class Triangle
The class Triangle has a function called triangle(). Now we create a class derived from the base class Triangle called Isosceles.
Now we can create a derived class object and use it to access the functions of the base class.
I am an isosceles triangle
I am a triangle
Now write a function in the Isosceles class so that the output is given below.
Sample Output
I am an isosceles triangle
In an isosceles triangle, two sides are equal
I am a triangle
Submit your solution here: Click Here
{
public:
void triangle()
{
cout << "I am a triangle\n";
}
};
The class Triangle has a function called triangle(). Now we create a class derived from the base class Triangle called Isosceles.
class Isosceles: public Triangle
{
public: void isosceles()
{
cout << "I am an isosceles triangle\n";
}
};
Now we can create a derived class object and use it to access the functions of the base class.
int main()
{
Isosceles isc;
isc.isosceles();
isc.triangle();
return 0;
}
This code will print:
I am a triangle
Now write a function in the Isosceles class so that the output is given below.
Sample Output
I am an isosceles triangle
In an isosceles triangle, two sides are equal
I am a triangle
Submit your solution here: Click Here
Inheritance Introduction Hackerrank Solution in C++
#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.
void description()
{
cout << "In an isosceles triangle two sides are equal\n";
}
};
int main()
{
Isosceles isc;
isc.isosceles();
isc.description();
isc.triangle();
return 0;
}
The Output of Inheritance Introduction Hackerrank Solution
Similar to Inheritance Introduction
- StringStream Hackerrank Solution in C++
- Attribute Parser Hackerrank Solution in C++
- Basic Data Types HackerRank Solution in C++
- For Loop Hackerrank Solution in C++
- Functions in C++ Hackerrank Solution
- Pointer Hackerrank Solution in C++
- Arrays Introduction Hackerrank Solution in C++
- Strings Hackerrank Solution in C++
- Plus Minus Hackerrank Solution C++
- Hello World in C Hackerrank Solution
- Divisible Sum Pairs Hackerrank Solution in C++
- Apple And Orange Hackerrank Solution
- Simple Array Sum Hackerrank Solution C++
- Compare The Triplets Hackerrank Solution C++
0 Comments: