2927 - EE2310_Lec12 Scoreboard

Time

2023/12/14 08:15:00 2023/12/14 10:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14179 EE2310_Lec12

14179 - EE2310_Lec12   

Description

#include <iostream>
#include <string>
using namespace std;


class GeometricObject {
public:
   GeometricObject();
   GeometricObject(const string& color, bool filled);
   string getColor() const;
   void setColor(const string& color);
   bool isFilled() const;
   void setFilled(bool);
   string toString() const;

private:
   string color;
   bool filled;
};


GeometricObject::GeometricObject() {
   color = "white";
   filled = false;
}


/*

 * Implement GeometricObject's member functions.

 */

//-------------------------------------
// Use 3.14159 for the constant Pi

class Circle: public GeometricObject {
public:
/*

 * Define Circle's member functions.

 */


private:
   double radius;

};

/*

 * Implement Circle's member functions.

 */

//-------------------------------------

class Rectangle: public GeometricObject {
public:
/*

 * Define Rectangle's member functions.

 */

private:
   double width;
   double height;
};

/*

 * Implement Rectangle's member functions.

 */


int main() {
   GeometricObject shape;
   shape.setColor("Red");
   shape.setFilled(true);
   cout << shape.toString() << endl << " color: " << shape.getColor() << endl
        << " filled: " << (shape.isFilled() ? "true" : "false") << endl;
   Circle circle(5);
   circle.setColor("black");
   circle.setFilled(false);
   cout << circle.toString() << endl << " color: " << circle.getColor() << endl
        << " filled: " << (circle.isFilled()? "true" : "false") << endl
        << " area: " << circle.getArea() << endl << " perimeter: " << circle.getPerimeter() << endl;

   Rectangle rectangle(2, 3);
   rectangle.setColor("orange");
   rectangle.setFilled(true);
   cout << rectangle.toString() << endl << " color: " << rectangle.getColor() << endl << " filled: "
        << (rectangle.isFilled() ? "true" : "false") << endl << " width: " << rectangle.getWidth()
        << ", height: " << rectangle.getHeight() << endl << " area: " << rectangle.getArea() << endl
        << " perimeter: " << rectangle.getPerimeter() << endl;
}

 

Input

Output

Geometric object
 color: Red
 filled: true
Circle object
 color: black
 filled: false
 area: 78.5397
 perimeter: 31.4159
Rectangle object
 color: orange
 filled: true
 width: 2, height: 3
 area: 6
 perimeter: 10

Sample Input  Download

Sample Output  Download

Tags




Discuss