We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<iostream>usingnamespacestd;/* * Create classes Rectangle and RectangleArea */classRectangle{protected:intwidth;intheight;public:Rectangle(){width=0;height=0;}Rectangle(int_w,int_h){width=_w;height=_h;}voiddisplay(){std::cout<<width<<" "<<height<<std::endl;}};classRectangleArea:publicRectangle{public:voidread_input(){std::cin>>width;std::cin>>height;}voiddisplay(){std::cout<<width*height<<std::endl;}};intmain(){/* * Declare a RectangleArea object */RectangleArear_area;/* * Read the width and height */r_area.read_input();/* * Print the width and height */r_area.Rectangle::display();/* * Print the area */r_area.display();return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Rectangle Area
You are viewing a single comment's thread. Return to all comments →
My C++ solution