by Dinesh Thakur Category: Array Pointer and Union

 

#include <iostream.h>

#include<conio.h>
class MyClass
{
       private:
       int Price;
       int Count;
       long Total;
       public:
                void Input(int P,int C)
           {
                Price=P;
                Count=C;
           }
                void MyClass::Compute()
           {
                Total=(long) Price*Count;
            }
                void MyClass::Print()
            {
                cout<<"Price="<<Price<<" Count="<<Count<<" Total="<< Total<<"\n";
             }
 };
     void main()
{
      clrscr();
      MyClass *ob;
      ob=new MyClass[6];
      ob[0].Input(5,0);
      ob[1].Input(3,5);
      ob[2].Input(1,0);
      ob[3].Input(5,20);
       ob[4].Input(4,0);
       ob[5].Input(8,5);
       for(int i=0;i<6;i++)
       ob[i].Compute();
       for(i=0;i<6;i++)
       ob[i].Print();
       delete ob;
        getch();
}

Using Class Pointer And Class Array Together



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles