Page 169 - DCAP404 _Object Oriented Programming
P. 169

Object-oriented Programming




                    Notes          in the stock. The following program uses classes and shows how to convert data of one type to
                                   another.

                                   #include<iostream.h>
                                   #inc1ude<conio.h>
                                   class  stock2;
                                   class  stockl
                                   {
                                   int  code,item;
                                   float  price;
                                   public:
                                   stockl(int  a,int  b,float  c)

                                   {
                                   code=a;
                                   item=b;
                                   price=c;
                                   }
                                   void  disp()
                                   {

                                   cout<<  “code”  <<code  <<“\n”;
                                   cout<<  “Items”  <<item  <<“\n”;
                                   cout<<  “Price  per  item  `”  <<price  <<“\n”;
                                   }
                                   int  getcode()
                                   {return  code;}
                                   int  getitem()
                                   {return  item;}
                                   int  getprice()

                                   {return  price;}
                                   operator  float()
                                   {
                                   retum(item*price);
                                   }
                                   };
                                   class  stock2

                                   {
                                   int  code;
                                   float  val;




          162                               LOVELY PROFESSIONAL UNIVERSITY
   164   165   166   167   168   169   170   171   172   173   174