class product contains product id name, price and quantity. write a menu driven program which has following options: list all product. b) list the product detail which has qty < 10. c)search entered product from list and show all details. d) list products whose price is within range
using namespace std; //class product class product{ public: int id; string name; float price; int quantity; }; //main function int main() { //products array product products[100];
//Set data products[0].id=1; products[0].name="product1"; products[0].price=5; products[0].quantity=50;
int choice=-1;//choice do{ //Show menu cout<<"1 - List all product "; cout<<"2 - List the product detail which has qty >10 "; cout<<"3 - Search entered product from list "; cout<<"4 - Show all details "; cout<<"5 - List products whose price is within range "; cout<<"0 - Exit "; cout<<"Select one item: "; cin>>choice;//read one item float result=0;//result variable //Show result if(choice==1){ //List all product for(int i=0;i<4;i++){ cout<<products[i].id<<" "; cout<<products[i].name<<" "; cout<<products[i].price<<" "; cout<<products[i].quantity<<" "; } } if(choice==2){
//List the product detail which has qty >10 for(int i=0;i<4;i++){ if(products[i].quantity>=10){ cout<<products[i].id<<" "; cout<<products[i].name<<" "; cout<<products[i].price<<" "; cout<<products[i].quantity<<" "; } } } if(choice==3){ //Search entered product from list int id;//variable id cout<<"Enter id product: "; cin>>id;//read id
for(int i=0;i<4;i++){ if(products[i].id==id){ cout<<products[i].id<<" "; cout<<products[i].name<<" "; cout<<products[i].price<<" "; cout<<products[i].quantity<<" "; } } } if(choice==4){ // Show all details for(int i=0;i<4;i++){ cout<<products[i].id<<" "; cout<<products[i].name<<" "; cout<<products[i].price<<" "; cout<<products[i].quantity<<" "; } } if(choice==5){ //List products whose price is within range float picerangelow=0; float picerangehigh=0; cout<<"Enter pice range low: "; cin>>picerangelow; cout<<"Enter pice range high: "; cin>>picerangehigh; for(int i=0;i<4;i++){ //Show result if(products[i].price>=picerangelow && products[i].price<=picerangelow ){ cout<<products[i].id<<" "; cout<<products[i].name<<" "; cout<<products[i].price<<" "; cout<<products[i].quantity<<" "; } } }
Comments
Dear sanjay, please use panel for submitting new questions
give me code in c++ for class name product with data members product id,product name to calculate total sum of 5 product and display it
Dear Himani Sharma, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!
Thanx
Leave a comment