Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- class dat
- {
- public:
- int code;
- char nm[20];
- int cost;
- };
- int main()
- {
- int t=0,sum=0,a,i=0,count=0,c,flag=0,j,x;
- dat b[50];
- do{
- cout<<"You can do the following, enter appropriate number:\n";
- cout<<"1.Add an item\n";
- cout<<"2.Display total value\n";
- cout<<"3.Delete an item\n";
- cout<<"4.Display all items\n";
- cout<<"5.Quit\n";
- cout<<"What is your choice\n";
- cin>>a;
- cout<<"\n";
- switch(a)
- {
- case 1:
- count++;
- cout<<"Enter the item name\n";
- cin>>b[i].nm;
- cout<<"Enter the item code\n";
- cin>>b[i].code;
- cout<<"Enter the item cost\n";
- cin>>b[i].cost;
- cout<<"\n";
- i++;
- break;
- case 2:
- sum=0;
- cout<<"code\tcost\n";
- for(j=0;j<count;j++)
- {
- cout<<b[j].code<<"\t"<<b[j].cost<<"\n";
- sum=sum+b[j].cost;
- }
- cout<<"\nTotal cost="<<sum<<endl<<"\n";
- break;
- case 3:
- cout<<"Enter the item code to delete the item\n";
- cin>>c;
- for(j=0;j<count;j++)
- {
- if(b[j].code==c)
- {
- flag=1;
- i--;
- cout<<"Item has been deleted\n";
- for(x=j;x<count-1;x++)
- b[x]=b[x+1];
- cout<<"\n";
- count--;
- break;
- }
- else
- flag=0;
- }
- if(flag==0)
- cout<<"code not found\n\n";
- break;
- case 4:
- cout<<"the items in the list are:\n";
- cout<<"code\tname\n";
- for(j=0;j<count;j++)
- cout<<b[j].code<<"\t"<<b[j].nm<<endl;
- cout<<endl;
- break;
- case 5:
- t=1;
- break;
- default:
- cout<<"invalid operator\n\n";
- break;
- }
- }while(t!=1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment