Rectangle Area 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 Rectangle Area 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.

Rectangle Area in C++ - Hackerrank Solution

Create two classes:

The Rectangle class should have two data fields-width and height of int types. The class should have display() method, to print the width and height of the rectangle separated by space.

The RectangleArea class is derived from Rectangle class, i.e., it is the sub-class of Rectangle class. The class should have read_input() method, to read the values of width and height of the rectangle. The RectangleArea class should also overload the display() method to print the area (width * height) of the rectangle.

Input Format :

The first and only line of input contains two space separated integers denoting the width and height of the rectangle.

Constraints :


Output Format :

The output should consist of exactly two lines:
In the first line, print the width and height of the rectangle separated by space.
In the second line, print the area of the rectangle.

Sample Input :

10 5

Sample Output :

10 5

Explanation :

as width = 10 and height = 5 , so area = width * height = 50

Rectangle Area in C++ – Hacker Rank Solution

using namespace std;
 * Create classes Rectangle and RectangleArea
/* Rectangle Area in C++ - Hacker Rank Solution START */

class Rectangle 
    int width, height;
    void display() 
        cout > width;
        cin >> height;
    void display() 

Leave a Comment

Scroll to Top