Page 201 - DCAP404 _Object Oriented Programming
P. 201

Object-oriented Programming




                    Notes                               put_n  (  );
                                                        put_m  (  );
                                                        put_s  (  );    cout  <<“\n  total  score=  “<<total<<“\n”;
                                                 }
                                                 main  (  )
                                                 {
                                                 clrscr  (  );

                                                        result  S1;
                                                        S1.get_n  (345)
                                                        S1.get_m  (30,  35);
                                                        S1.get-S  (7);
                                                        S1.show  (  );



                                     Did u know?  How the problem of duplicate sub-objects is resolved?
                                     The problem of duplicate sub-objects is resolved with virtual inheritance. When a base
                                     class is inherited as virtual, only one sub-object will appear in the derived class—a process
                                     called virtual base-class inheritance.
                                   //Program to show hybrid inheritance using virtual base classes

                                                 #  include  <  iostream.h>
                                                 #  include<  conio.h>
                                                 Class  A
                                                 {
                                                 protected:
                                                        int  x;
                                                 public:
                                                        void  get  (int);

                                                        void  show  (void);
                                                 };
                                                 void  A  ::  get  (int  a)
                                                        { x = a; }
                                                 void  A  ::  show  (void)
                                                        {  cout  <<  X;}
                                                 Class  A1  :  Virtual  Public  A

                                                 {
                                                 protected:
                                                        int  y;
                                                 public:




          194                               LOVELY PROFESSIONAL UNIVERSITY
   196   197   198   199   200   201   202   203   204   205   206