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<

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

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;
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT