Saturday, 16 May 2015

U4P8

Create a class ITEM with item_code, item_rate and quantity as a data members. Create an array of pointers to objects of class ITEM. Write a member function which will calculate the amount of item. Print item_code and amount of item.

Code :
 #include<iostream.h>  
 #include<conio.h>  
 class item  
 {  
      public:  
      float item_code, item_rate, quantity,amount;  
      void get()  
      {  
           cout<<"\nItem code: ";  
           cin>>item_code;  
           cout<<"Item Rate: ";  
           cin>>item_rate;  
           cout<<"Quantity : ";  
           cin>>quantity;  
      }  
      void calculate()  
      {  
           cout<<"\nCode : "<<item_code<<" :: Amount : "<<item_rate*quantity;  
      }  
 };  
 void main()  
 {  
      clrscr();  
      item o;  
      item *po[3];  
      po[3] = &o;  
      for(int i=0;i<3;i++)  
      {  
           po[i]->get();  
      }  
      for(i=0;i<3;i++)  
      {  
           po[i]->calculate();  
      }  
      getch();  
 }  


Output : 

No comments:

Post a Comment