Check this code and execute the rectangle class with some modifications: - change to other shapes - add color #include using namespace std; class Rectangle { private: double width; double height; public: Rectangle(double w=1, double h=1); double getWidth(); void setWidth(double W); double getHeight(); void setHeight(double h); double getArea(); double getPerimeter(); }; Rectangle::Rectangle(double w, double h):width(w),height(h) {} double Rectangle::getWidth() { return width; } void Rectangle::setWidth(double w) {width = w; } double Rectangle::getHeight() { return height; } void Rectangle::setHeight(double h) { height = h; } double Rectangle::getArea() { return width*height; } double Rectangle::getPerimeter() { return 2*(width+height); } int main() { Rectangle r1(4,40); cout<
Check this code and execute the rectangle class with some modifications:
- change to other shapes
- add color
#include <iostream>
using namespace std;
class Rectangle {
private:
double width;
double height;
public:
Rectangle(double w=1, double h=1);
double getWidth();
void setWidth(double W);
double getHeight();
void setHeight(double h);
double getArea();
double getPerimeter();
};
Rectangle::Rectangle(double w, double h):width(w),height(h) {}
double Rectangle::getWidth() { return width; }
void Rectangle::setWidth(double w) {width = w; }
double Rectangle::getHeight() { return height; }
void Rectangle::setHeight(double h) { height = h; }
double Rectangle::getArea() { return width*height; }
double Rectangle::getPerimeter() { return 2*(width+height); }
int main()
{
Rectangle r1(4,40);
cout<<r1.getArea()<<"\n"<<r1.getPerimeter()<<endl;
return 0;
}
Step by step
Solved in 3 steps with 1 images