-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_07.cpp
More file actions
34 lines (34 loc) · 859 Bytes
/
Copy pathproblem_07.cpp
File metadata and controls
34 lines (34 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*Consider you have a class Shape which has two public methods setWidth(float w) and setHeight(float h) and
two protected variables width and height as float data type; and another class Rectangle which has a public
method float getArea(). Write code to calculate the area perimeter of a rectangle for given width and height
using the members of Shape class.*/
#include<iostream>
using namespace std;
class Shape{
public:
void setWidth(float w){
width=w;
}
void setHeight(float h){
height=h;
}
protected:
float height,width;
};
class Rectangle:public Shape{
public:
float getArea(){
cout<<"Perimeter:"<<2*(height+width)<<endl;
return height*width;
}
};
int main(){
Rectangle obj;
float h,w;
cout<<"Enter height and width:\n";
cin>>h>>w;
obj.setHeight(h);
obj.setWidth(w);
cout<<"Area:"<<obj.getArea();
return 0;
}