Multi Level Inheritance in C++ – Hacker Rank Solution | HackerRank Programming Solutions | HackerRank C++ Solutions

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language C++ . At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight you profile to the recruiters.

In this post, you will find the solution for Multi Level Inheritance in C++-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Introduction To C++

C++ is a general-purpose programming language that was developed as an enhancement of the C language to include object-oriented paradigm. It is an imperative and a compiled language. 

C++ is a middle-level language rendering it the advantage of programming low-level (drivers, kernels) and even higher-level applications (games, GUI, desktop apps etc.). The basic syntax and code structure of both C and C++ are the same. 

C++ programming language was developed in 1980 by Bjarne Stroustrup at bell laboratories of AT&T (American Telephone & Telegraph), located in U.S.A. Bjarne Stroustrup is known as the founder of C++ language.

Multi Level Inheritance in C++- Hackerrank Solution

Problem

Solve the problem Inheritance-Introduction before solving this problem.

In the previous problem we learned about Inheritance and how can a derived class object use the member functions of the base class.

In this we will see what multi-level inheritance is. 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.)

Now create a class called Equilateral which inherits from Isosceles and should have a function such that the output is as given below.


Input Output :

I am an equilateral triangle
I am an isosceles triangle
I am a triangle
Multi Level Inheritance in C++ – Hacker Rank 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";
  		}
};
//Write your code here.
/* Multi Level Inheritance in C++ - Hacker Rank Solution START */
class Equilateral : public Isosceles
{
    public:
        void equilateral()
        {
            cout<<"I am an equilateral triangle\n";
        }
};

/* Multi Level Inheritance in C++ - Hacker Rank Solution END */

int main()
{
  
    Equilateral eqr;
    eqr.equilateral();
    eqr.isosceles();
    eqr.triangle();
    return 0;
}

Leave a Comment

Ads Blocker Image Powered by Code Help Pro
Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Refresh