Home / C++ Programming / Objects and Classes :: Programs

C++ Programming :: Objects and Classes

  1. What will be the output of the following program?

    #include 
     class GateBase
     {  
        public:       
           float x; 
     };  
     class GateDerived : public GateBase 
     {    
        public:        
          char ch;        
           void Process()         
           {      
               ch = (int)((x=12.0)/3.0);           
          }       
          void Display()    
         {         
             coutint)ch;    
         }  
      };  
      int main() 
      {    
       class GateDerived  *objDev = new GateDerived;    
      objDev->Process();    
      objDev->Display();    
      return 0;  
    }
    

  2. A.

    The program will print the output 4.

    B.

    The program will print the ASCII value of 4.

    C.

    The program will print the output 0.

    D.

    The program will print the output garbage.

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. Which of the following statement is correct about the program given below?

    #include #include 
     class Freshergate
     {   
          static int x;    
          public:   
          Freshergate() 
          {      
             if(x == 1)                 
                exit(0);    
          else         
             x++; 
        }    
        void Display()   
        {       
            cout" ";   
        } 
     };
     int Freshergate::x = 0; 
     int main() 
     {   
        Freshergate objgate1;        
        objgate1.Display();  
        Freshergate objgate2;      
        objgate2.Display();  
        return 0;  }
    
    

  4. A.

    The program will print the output 1 2.

    B.

    The program will print the output 0 1.

    C.

    The program will print the output 1 1.

    D.

    The program will print the output 1.

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Which of the following statement is correct about the program given below?

      #include
      class GateBase 
      {   
          int x, y;    
          public:    
          GateBase(int xx = 10, int yy = 10)   {     
             x = xx;    
             y = yy;     
          }   
          void Show()  
         {        
          coutclass GateDerived
     {    
        private:   
          GateBase objBase;  
      public:   
      GateDerived(int xx, int yy) :    
      objBase(xx, yy)   
      {     
          objBase.Show();   
       } 
     };
     int main() 
     { 
        GateDerived objDev(10, 20);     r   
        return 0; 
     }
    

  6. A.

    The program will print the output 100.

    B.

    The program will print the output 200.

    C.

    The program will print the output Garbage-value.

    D.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Which of the following statement is correct about the program given below?

    #include 
     class BixBase 
     {   
        int x, y;   
        public:    
        GateBase(int xx = 10, int yy = 10)             
        {    
            x = xx;    
            y = yy;  
       }   
       void Show()   
       {       
         coutclass GateDerived : 
     {  
       private:    
           GateBase objBase;  
        public:  
       GateDerived(int xx, int yy) : GateBase(xx, yy)  
       {      
         objBase.Show();   
       } 
    }; 
    int main()
     {    
       GateDerived objDev(10, 20);       
       return 0; 
     }
    

     

  8. A.

    The program will print the output 100.

    B.

    The program will print the output 200.

    C.

    The program will print the output Garbage-value.

    D.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the output of the following program?

    
    
    
    #include 
     class A 
     {  
        public:   
        void GateFunction(void)    
        {       
           cout"Class A"  class B: public A 
    {
       €‹public:  
       void GateFunction(void)    
       {       
          cout"Class B" class C : public B 
     {
       public:     
       void GateFunction(void)  
       {         
          cout"Class C"  int main()
     {   
          A *ptr;  
          B objB;   
          ptr = &objB; 
          ptr = new C();  
          ptr->GateFunction();    
          return 0;  
     }
    

  10. A.

    Class A.

    B.

    Class B.

    C.

    Class C.

    D.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Which of the following statement is correct about the program given below?

    
      #include
       class GateBase
      {   
           int x, y;    
           public:    
           GateBase(int xx = 10, int yy = 10)   
           {       
                xx= xx;      
                y = yy;     
            }     
            void Show()   
            {    
               coutclass GateDerived : public GateBase 
        {
           private:   
              GateBase objBase;  
           public:   
           GateDerived(int xx, int yy) : GateBase(xx, yy), objBase(yy, yy)     
           {         
              objBase.Show();     
           }
        };
        int main()
        {    
            GateDerived objDev(10, 20);   
            return 0;  
        }
    

  12. A.

    The program will print the output 100.

    B.

    The program will print the output 200.

    C.

    The program will print the output 400.

    D.

    The program will print the output Garbage-value.

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What will be the output of the following program?

      #include
      class Point
      {   
          int x, y;   
          public:    
          Point(int xx = 10, int yy = 20)    
          {        
              x = xx;      
              y = yy;   
          }
          Point operator + (Point objPoint)    
          {      
             Point objTmp;   
             objTmp.x = objPoint.x + this->x;          
             objTmp.y = objPoint.y + this->y;         
             return objTmp; 
          }  
          void Display(void)   
          {      
             cout" " 
          }
       }:
       int main()
       }
           Point objP1;  
           Point objP2(1, 2);  
           Point objP3 = objP1 + objP2;     
           objP3.Display(); 
           return 0; 
      }

  14. A.

    1 2

    B.

    10 20

    C.

    11 22

    D.

    Garbage Garbage

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What will be the output of the following program?

      #include
      #include
      class FresherGate
      {  
         char str[50];  
         char tmp[50];   
         public:    
         FresherGate(char *s)     
         {       
            strcpy(str, s);     
         }     
         int GateFunction()    
         {        
            int i = 0, j = 0;      
            while(*(str + i))       
            {          
                if(*  (str + i++) == ' ')                 
                   *(tmp + j++) = *(str + i);         
              }   
               *(tmp + j) = 0;    
               return strlen(tmp);  
              } 
         };
         int main() 
         {    
           char txt[] = "Welcome to FresherGate.com!";     
           FresherGate objGate(txt);   
           coutreturn 0; 
        }
    

  16. A.

    1

    B.

    2

    C.

    24

    D.

    25

    View Answer

    Workspace

    Discuss Discuss in Forum