To write a program in C++ to prepare product information using arrays.

ALGORITHM:
1. Stop
2. Create a class product.
3. Read the product name and cost.
4. Calculate the sum
5. Display the product information.
6. Stop the program.




Program Code:
#include <iostream>
using namespace std;
class product
{
int pno[10],pcost[10],count=0,i,j=0;
public:
int input(int &j);
int tcost(int g);
int display(int g); 
};
int product::input(int &j)
{
j++;
while(j<=5)
{
cout<<"Product No. ";
cin>>pno[j];
cout<<endl<<"Product Cost. ";
cin>>pcost[j];
break;
}
return j;
}
int product::tcost(int g)
{
for(i=0;i<g+1;i++)
count+=pcost[i];
cout<<"Total Cost = "<<count<<endl;

return 0;
}
int product::display(int g)
{
for(i=0;i<g+1;i++)
{
cout<<"Product No.  "<<pno[i]<<endl;
cout<<"Product Cost.  "<<pcost[i]<<endl<<endl;
}
return 0;
}
int main() 
{
int x=0,j=-1,g;
while(x!=4)
{
cout<<endl<<endl<<"1. Add a product"<<endl;
cout<<"2. Display Product Total Cost"<<endl;
cout<<"3. Display All Product"<<endl;
cout<<"4. Quit"<<endl;
cout<<"Enter Your Choice: ";
cin>>x;
product obj;
if(x==1)
{
g=obj.input(j);
 }
else if(x==2)
{
obj.tcost(g);
}
else if(x==3)
{
obj.display(g);
}
else if(x==4)
break;
}
cout<<endl<<"Thank You.";    

}





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: