CPP

CPP

Class Hierarchies and Abstract Classes has 10 Questions

How many types of inheritance are there in c++?

2
3
4
5
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class poly
  4.     {
  5.         protected:
  6.         int width, height;
  7.         public:
  8.         void set_values(int a, int b)
  9.         {
  10.             width = a; height = b;
  11.         }
  12.     };
  13.     class Coutput
  14.     {
  15.         public:
  16.         void output(int i);
  17.     };
  18.     void Coutput::output(int i)
  19.     {
  20.         cout << i;
  21.     }
  22.     class rect:public poly, public Coutput
  23.     {
  24.         public:
  25.         int area()
  26.         {
  27.             return(width * height);
  28.         }
  29.     };
  30.     class tri:public poly, public Coutput
  31.     {
  32.         public:
  33.         int area()
  34.         {
  35.             return(width * height / 2);
  36.         }
  37.     };
  38.     int main()
  39.     {
  40.         rect rect;
  41.         tri trgl;
  42.         rect.set_values(3, 4);
  43.         trgl.set_values(4, 5);
  44.         rect.output(rect.area());
  45.         trgl.output(trgl.area());
  46.         return 0;
  47.     }

1212
1210
1010
none of the mentioned
How many constructors can present in a class?

1
2
3
multiple
What should be the name of constructor?

same as object
same as member
same as class
none of the mentioned
What does derived class does not inherit from the base class?

constructor and destructor
friends
operator = () members
all of the mentioned
How many types of constructor are there in C++?

1
2
3
4
What is meant by containership?

class contains objects of other class types as its members
class contains objects of other class types as its objects
both a & b
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class stu
  4.     {
  5.         protected:
  6.         int rno;
  7.         public:
  8.         void get_no(int a)
  9.         {
  10.             rno = a;
  11.         }
  12.         void put_no(void)
  13.         {
  14.         }
  15.     };
  16.     class test:public stu
  17.     {
  18.         protected:
  19.         float part1,part2;
  20.         public:
  21.         void get_mark(float x, float y)
  22.         {
  23.             part1 = x;
  24.             part2 = y;
  25.         }
  26.         void put_marks()
  27.         {
  28.         }
  29.     };
  30.     class sports
  31.     {
  32.         protected:
  33.         float score;
  34.         public:
  35.         void getscore(float s)
  36.         {
  37.             score = s;
  38.         }
  39.         void putscore(void)
  40.         {
  41.         }
  42.     };
  43.     class result: public test, public sports
  44.     {
  45.         float total;
  46.         public:
  47.         void display(void);
  48.     };
  49.     void result::display(void)
  50.     {
  51.         total = part1 + part2 + score;
  52.         put_no();
  53.         put_marks();
  54.         putscore();
  55.         cout << "Total Score=" << total << "\n";
  56.     }
  57.     int main()
  58.     {
  59.         result stu;
  60.         stu.get_no(123);
  61.         stu.get_mark(27.5, 33.0);
  62.         stu.getscore(6.0);
  63.         stu.display();
  64.         return 0;
  65.     }

66.5
64.5
62.5
60.5
How many kinds of classes are there in c++?

1
2
3
4
What is meant by polymorphism?

class having many forms
class having only single form
class having two forms
none of the mentioned