Page 205 - C++
P. 205

ii)    ONEENDTWOEND
                      iii)   ONETWOSIX
                      iv)    ONETWOSIXEND



                   f)  Find the output of the following program :-                                       (3)
                   Note : Assume all the required header files are already included in the program.
                      class item
                      {
                          int ino;
                          char iname[20];
                          float price;
                         public :
                          item( ) {ino = 100, strcpy(iname, “none”); price = 100;}
                          void assign(int I, char name[ ], float p)
                            {
                              ino += I; strcpy(iname, name); price = p;
                            }
                          void raisep(float p)
                            {
                              price += p;
                                }
                          void reducep(float p)
                            {
                               price −= p;
                             }
                          void disp( )
                            {
                               cout << ++price << “:” << iname << “:” << price++ << endl;
                             }
                         };
                      void main( )
                        {
                          item one, two;
                          one.disp( );
                          one.assign(1, “pen”, 95);
                          two.assign(2, “pencil”, 55);
                          one.raisep(10);
                          two.reducep(5);
                          two.disp( );
                          one.disp( );
                         }

                   Q2)
                   a)  How encapsulation and abstraction are implemented in C++ language? Explain
                       with an example.                                                                 (2)
                   b)  Answer the questions (i) and (ii) after going through the following class:
                          class student
                          {
                             int rno ; char name[20]; float fees;
                                 public:
                             student( );                      // Function 1
                             student (int r, char n[ ],float f) ;   // Function 2
                             void display(float f);           // Function 3
                             ~student( );                     // Function 4
                          };
                   i)   Fill in the blank lines as Statement 1 and Statement 2 to execute function 2 and 3
                   respectively in the following code:                                                   (1)
                         void main( )
                          {
                            student s ;
   200   201   202   203   204   205   206   207   208   209   210