I am new to OOPs, so I was trying to create a program implementing inheritance.Here I am accepting the values for width and height in the derived class.Is there any way to reflect the same value in the super class ie Rectangle also.?ie if iam inputting 3 and 4 as breadth and height in Input() of RectangleArea then it should display the same value in Display() in Rectangle class.
#include <iostream>
using namespace std;
class Rectangle
{
public:
int width;
int height;
public:
void Display()
{
cout<<"Height"<<height<<",Width"<<width<<endl;
}
};
class RectangleArea : public Rectangle
{
public:
void Input()
{
cin>>width;
cout<<" ";
cin>>height;
}
void Display(int area)
{
cout<<"Area"<<area;
}
};
int main()
{
Rectangle rect;
RectangleArea rect1;
rect1.Input();
rect.Display();
return 0;
}