Wednesday, 22 March 2017

Hacker Rank Solution Program In C++ For " Multi Level Inheritance "

Problem :- Suppose we have a class A which is the base class and we have a class B which is derived from class A and we have a class C which is derived from class B, we can access the functions of both class A and class B by creating an object for class C. This is called Multi-Level inheritance. (B inherits A and C inherits B.)


Submit Your Solution Here :- Click Here

Solution :-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

class Triangle{
   public:
      void triangle(){
         cout<<"I am a triangle\n";
      }
};

class Isosceles : public Triangle{
     public:
        void isosceles(){
          cout<<"I am an isosceles triangle\n";
        }
};
   
class Equilateral:public Isosceles{
   public:
        void equilateral(){
            cout<<"I am an equilateral triangle\n";
        }
};
int main(){
  
    Equilateral eqr;
    eqr.equilateral();
    eqr.isosceles();
    eqr.triangle();
    return 0;
}


Output :-

Hacker Rank Solution Program In C++ For " Multi Level Inheritance "

No comments:
Write comments

Recommended Posts × +