66 935
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #27575 in C++ for zawnga

Question #27575
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
Expert's answer
#include <conio.h>
#include <iostream>
#include <string>

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;

products[1].id=2;
products[1].name="product2";
products[1].price=2;
products[1].quantity=100;

products[2].id=3;
products[2].name="product3";
products[2].price=20;
products[2].quantity=20;

products[3].id=4;
products[3].name="product4";
products[3].price=100;
products[3].quantity=2;

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<<"
";
}
}
}

}while(choice!=0);//exit if user enter 0

return 0;//return from function
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
19.01.17, 16:30

Dear sanjay,
please use panel for submitting new questions

sanjay
19.01.17, 11:44

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

Assignment Expert
04.11.14, 13:59

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!

Himani Sharma
04.11.14, 06:53

Thanx

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions