Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- class item
- {
- int code;
- float price;
- public:
- void getdata()
- {
- cout<<"enter the item code and price\n";
- cin>>code>>price;
- }
- void del(int d)
- {
- if(code==d)
- {
- price=0;
- }
- }
- void display()
- {
- cout<<"code=\t"<<code<<"\tprice=\t"<<price<<"\n";
- }
- float show()
- {
- return price;
- }
- };
- void main()
- {
- item t[100];
- char ch;
- int n,x,d,c,i;
- float s=0;
- do
- {
- cout<<"enter 1 for adding an item\n"<<"enter 2 for deleting an item\n"<<"enter 3 for displaying\n";
- cout<<"make a choice\n";
- cin>>x;
- switch(x)
- {
- case 1:
- cout<<"enter the no of items";
- cin>>n;
- for(i=0;i<n;i++)
- {
- t[i].getdata();
- }
- break;
- case 2:
- cout<<"enter the item to be deleted\n";
- cin>>d;
- for(i=0;i<n;i++)
- {
- t[i].del(d);
- }
- break;
- case 3:
- cout<<"press 1 for displaying total item\n"<<"press 2 for displaying total price";
- cin>>c;
- switch(c)
- {
- case 1:
- for(i=0;i<n;i++)
- {
- t[i].display();
- }
- break;
- case 2:
- for(i=0;i<n;i++)
- {
- s=s+t[i].show();
- }
- cout<<"total price=\t"<<s;
- break;
- }
- break;
- default:
- cout<<"wrong choice.............\n";
- break;
- }
- cout<<"do u want to continue y/n\n";
- ch=getch();
- }
- while(ch!='n');
- }
Advertisement
Add Comment
Please, Sign In to add comment