C++ | Catalog display

Introduction

This is a program to calculate no. of pages required to display no. of products if no. of products on one page is given. This is also called pagination.It can be used in php for pagination.

Program to calculate no. of pages in catalog.

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int a,b,c,d;
//Input and save them in 'a' and 'b'
cout<<"Enter the no. of products to be displyed on one page"<<endl;
cin>>a;
cout<<"Enter the no. of products"<<endl;
cin>>b;
//calculate mod and save them in 'c'
c=b%a;
//if-else conditional statement
if(c==0)
d=b/a;
else
{
d=b/a;
d=d+1;
}
//show the output d
cout<<"No. of pages required "<<d;
//get character
getch();
}

Output

Enter the no. of products to be displyed on one page
10
Enter the no. of products
56
No. of pages required 6

or

Enter the no. of products to be displyed on one page
10
Enter the no. of products
50
No. of pages required 5

How does it work

  1. You enter the no. of products on one page
  2. You enter the no. of products.
  3. The mod is calculated.
  4. The conditional statement calculates the no of pages required.
  5. No. of pages required is printed on screen.

Extending it

The program cannot be extended. however it has many applications in web world. you can use this one in php to create pagination of pages. Alert! while using this one in php you have to calculate everything in integers. but after division the no of pages (d variable) is in float. so you need to convert it.

Explanation.

  1. Include ‘iostream.h’ and ‘conio.h’ files.
  2. Add void main.
  3. Start program by first clearing the screen.
  4. Declare the variables as int. (name them as you want.)
  5. Add cout and cin of variable of input of necessary inputs.(as shown in program)
  6. Calculate the mod.
  7. Decide the no of pages by using if-else conditional statement.
  8. Print the number of pages required.

At the end

You learnt creating the c++ program of Calculating the no of pages required for products in catalog. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s