Advertisement
Aniket_Goku

Q22

Oct 14th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. //Q 22 CREATE CLASS 'INVENTORY' THAE STORE ITEM NO,ITEM NAME,PRICE AND QUANTITY .
  2. // OVERLOAD OPRATIONS
  3. //UNARY + TO ADD ITEMS
  4. //UNARY - TO DELETE ITEMS
  5. // BINARY + TO INCREAMENT PRICE BY 10% FOR ITEMS HAVING PRICE LESS THEN PARTICULAR PRICE
  6. //DEFINE FUNCTION TO DISPLAY ALL ITEM WITH DETAILS
  7. #include<iostream>
  8. using namespace std;
  9. int t=-1;
  10. class inventory
  11. {
  12.     private:
  13.        
  14.         char i_name[30];
  15.         float price,qty;
  16.        
  17.     public:
  18.         int i_no;
  19.         void get_data()
  20.         {
  21.             cout<<"---------------------------------------------------------------";
  22.            
  23.             cout<<endl<<"Enter the item no: ";
  24.             cin>>i_no;
  25.             cout<<endl<<"Enter the item name: ";
  26.             cin>>i_name;
  27.             cout<<endl<<"Enter the item price: ";
  28.             cin>>price;
  29.             cout<<endl<<"Enter the item qty: ";
  30.             cin>>qty;
  31.             cout<<"---------------------------------------------------------------";
  32.         }
  33.         void put_data()
  34.         {
  35.             cout<<endl<<i_no<<"\t"<<i_name<<"\t"<<price<<"\t"<<qty<<"\t"<<price*qty;
  36.         }
  37.         void put_no()
  38.         {
  39.             cout<<i_no;
  40.         }
  41.         void operator +()
  42.         {
  43.            
  44.             cout<<"-------------------+op overload--------------------------------";
  45.             cout<<endl<<"Enter the item no: ";
  46.             cin>>i_no;
  47.             cout<<endl<<"Enter the item name: ";
  48.             cin>>i_name;
  49.             cout<<endl<<"Enter the item price: ";
  50.             cin>>price;
  51.             cout<<endl<<"Enter the item qty: ";
  52.             cin>>qty;
  53.             cout<<"---------------------------------------------------------------";
  54.            
  55.         }
  56.         void operator -()
  57.         {
  58.             t--;           
  59.         }
  60.        
  61.                    
  62. };
  63. int main()
  64. {
  65.     inventory i[10];
  66.     int ch;
  67.  
  68.     do
  69.     {
  70.    
  71.         cout<<endl<<"================menu===============";
  72.         cout<<endl<<"1.ADD";
  73.         cout<<endl<<"2.DELETE";
  74.         cout<<endl<<"3.increament all price by 10%";
  75.         cout<<endl<<"4.DISPLAY";
  76.         cout<<endl<<"5EXIT";
  77.         cout<<"\nENter your choice: ";
  78.         cin>>ch;
  79.         switch(ch)
  80.         {
  81.             case 1:
  82.                 if(t<9)        
  83.                 {
  84.                     t++;
  85.                     +i[t];
  86.                     for(int j=0;j<=t;j++)
  87.                     {
  88.                         i[j].put_data();
  89.                     }  
  90.                 }
  91.                 else
  92.                 {
  93.                     cout<<endl<<"only 10 items can inserted";
  94.                 }
  95.                 break;
  96.             case 2:
  97.                 if(t!=-1)          
  98.                 {
  99.                    
  100.                     cout<<endl<<"*** item NO = "<<i[t].i_no<<" was deleted";
  101.                     -i[t];
  102.                    
  103.                     for(int j=0;j<=t;j++)
  104.                     {
  105.                         i[j].put_data();
  106.                     }  
  107.                 }
  108.                 else
  109.                 {
  110.                     cout<<endl<<"Insert some Items";
  111.                 }
  112.                 break;
  113.             case 3:
  114.                 cout<<"\nEMPTY";
  115.                
  116.                 break;
  117.             case 4:
  118.                 for(int j=0;j<=t;j++)
  119.                 {
  120.                     i[j].put_data();
  121.                 }  
  122.                 break; 
  123.         }  
  124.     }while(ch>=1 && ch<=4);
  125.     return 0;
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement