In: Computer Science
using c++
E2b: Design a class named Rectangle to represent a rectangle. The class contains:
(1) Two double data members named width and height which specifies the width and height of the rectangle .
(2) A no-arg constructor that creates a rectangle with width 1 and height 1.
(3) A constructor that creates a rectangle with the specified width and height .
(4) A function named getArea() that returns the area of this rectangle .
(5) A function named getPerimeter() that returns the perimeter of this rectangle .
Your solution:
Output:
#include
using namespace std;
class rectangle{
// Access specifier
public:
int height;
int width;
rectangle(){
height=1;
width=1;
}
rectangle(int a, int b){
width=a;
height=b;
}
int getArea()
{
return height*width;
}
int getPerimeter(){
return 2*(height+width);
}
};
//testing
int main(){
rectangle a;
cout<<"height is :-"<
cout<<"height is :-"<