upsidedown

oops3

Feb 3rd, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. class item
  4. {
  5.     int code;
  6.     float price;
  7. public:
  8. void getdata()
  9.     {
  10.         cout<<"enter the item code and price\n";
  11.         cin>>code>>price;
  12.     }
  13. void del(int d)
  14.     {
  15.         if(code==d)
  16.         {
  17.             price=0;
  18.         }
  19.     }
  20. void display()
  21.     {
  22.         cout<<"code=\t"<<code<<"\tprice=\t"<<price<<"\n";
  23.     }
  24. float show()
  25.     {
  26.         return price;
  27.     }
  28. };
  29. void main()
  30. {
  31.     item t[100];
  32.     char ch;
  33.     int n,x,d,c,i;
  34.     float s=0;
  35.     do
  36.     {
  37.     cout<<"enter 1 for adding an item\n"<<"enter 2 for deleting an item\n"<<"enter 3 for displaying\n";
  38.     cout<<"make a choice\n";
  39.     cin>>x;
  40.      switch(x)
  41.      {
  42.      case 1:
  43.      cout<<"enter the no of items";
  44.      cin>>n;
  45.      for(i=0;i<n;i++)
  46.      {
  47.         t[i].getdata();
  48.      }
  49.      break;
  50.      case 2:
  51.         cout<<"enter the item to be deleted\n";
  52.         cin>>d;
  53.         for(i=0;i<n;i++)
  54.         {
  55.           t[i].del(d);
  56.         }
  57.         break;
  58.       case 3:
  59.         cout<<"press 1 for displaying total item\n"<<"press 2 for displaying total price";
  60.         cin>>c;
  61.         switch(c)
  62.         {
  63.  
  64.           case 1:
  65.             for(i=0;i<n;i++)
  66.             {
  67.              t[i].display();
  68.             }
  69.             break;
  70.            case 2:
  71.              for(i=0;i<n;i++)
  72.              {
  73.                s=s+t[i].show();
  74.              }
  75.              cout<<"total price=\t"<<s;
  76.             break;
  77.         }
  78.         break;
  79.         default:
  80.             cout<<"wrong choice.............\n";
  81.             break;
  82.     }
  83.      cout<<"do u want to continue y/n\n";
  84.      ch=getch();
  85.     }
  86.  
  87.      while(ch!='n');
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment