upsidedown

oop ext2_b

Feb 3rd, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include<iostream.h>
  2.  
  3. class dat
  4. {
  5. public:
  6.     int code;
  7.     char nm[20];
  8.     int cost;
  9. };
  10.  
  11. int main()
  12. {
  13.     int t=0,sum=0,a,i=0,count=0,c,flag=0,j,x;
  14.     dat b[50];
  15.     do{
  16.     cout<<"You can do the following, enter appropriate number:\n";
  17.     cout<<"1.Add an item\n";
  18.     cout<<"2.Display total value\n";
  19.     cout<<"3.Delete an item\n";
  20.     cout<<"4.Display all items\n";
  21.     cout<<"5.Quit\n";
  22.     cout<<"What is your choice\n";
  23.     cin>>a;
  24.     cout<<"\n";
  25.     switch(a)
  26.     {
  27.     case 1:
  28.         count++;
  29.         cout<<"Enter the item name\n";
  30.         cin>>b[i].nm;
  31.         cout<<"Enter the item code\n";
  32.         cin>>b[i].code;
  33.         cout<<"Enter the item cost\n";
  34.         cin>>b[i].cost;
  35.         cout<<"\n";
  36.         i++;
  37.         break;
  38.  
  39.     case 2:
  40.         sum=0;
  41.         cout<<"code\tcost\n";
  42.         for(j=0;j<count;j++)
  43.         {
  44.             cout<<b[j].code<<"\t"<<b[j].cost<<"\n";
  45.             sum=sum+b[j].cost;
  46.         }
  47.         cout<<"\nTotal cost="<<sum<<endl<<"\n";
  48.         break;
  49.  
  50.     case 3:
  51.         cout<<"Enter the item code to delete the item\n";
  52.         cin>>c;
  53.         for(j=0;j<count;j++)
  54.         {
  55.             if(b[j].code==c)
  56.             {
  57.                 flag=1;
  58.                 i--;
  59.                 cout<<"Item has been deleted\n";
  60.                 for(x=j;x<count-1;x++)
  61.                     b[x]=b[x+1];
  62.                 cout<<"\n";
  63.                 count--;
  64.                 break;
  65.             }
  66.             else
  67.                 flag=0;
  68.         }
  69.         if(flag==0)
  70.             cout<<"code not found\n\n";
  71.         break;
  72.  
  73.     case 4:
  74.         cout<<"the items in the list are:\n";
  75.         cout<<"code\tname\n";
  76.         for(j=0;j<count;j++)
  77.             cout<<b[j].code<<"\t"<<b[j].nm<<endl;
  78.         cout<<endl;
  79.         break;
  80.  
  81.     case 5:
  82.         t=1;
  83.         break;
  84.  
  85.     default:
  86.         cout<<"invalid operator\n\n";
  87.         break;
  88.     }
  89.     }while(t!=1);
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment