-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_04.cpp
More file actions
31 lines (31 loc) · 896 Bytes
/
Copy pathproblem_04.cpp
File metadata and controls
31 lines (31 loc) · 896 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
/*Write the definition for a class called Rectangle that has data members length and width as float. The class
has the following member functions: -
float getPerimeter() to calculate and return the perimeter of the rectangle
float getArea() to calculate and return the area of the rectangle
Write a parameterized constructor to set data member length and width when object is being created.*/
#include<iostream>
using namespace std;
class Rectangle{
private:
float length,width;
public:
Rectangle(float l,float w){
length=l;
width=w;
}
float getPerimeter(){
return 2*(length+width);
}
float getArea(){
return length*width;
}
};
int main(){
float l,w;
cout<<"Enter length and width of rectangle:\n";
cin>>l>>w;
Rectangle obj(l,w);
cout<<"Perimeter of Rectangle:"<<obj.getPerimeter()<<endl;
cout<<"Area of Rectangle:"<<obj.getArea()<<endl;
return 0;
}