Question
Then, define those classes with the following hints:
• A general shape should have getters/setters for its color.
• A point has two coordinates x and y. You need getters/setters for them and a constructor to initialize a point by its two coordinates. Note that, in computer screen, x goes from left to right, while y goes from top to bottom.
• A line has two end points. You need two constructors to initialize a line by four coordinates (i.e. x1, y1, x2, y2).
• A rectangle has two points for its top-left and bottom-right corners. You need a constructor to initialize a rectangle by four coordinates for those two points (i.e. x1, y1, x2, y2).
• A circle has a point for its center and a value for its radius. You need a constructor to initialize a circle by its center and radius.
• A color has three components red, green, and blue (as unsigned char values). You need getters/setters for them and a constructor to initialize a color by its three components.
You need to define a method 'draw' for each of the shapes. First, determine if those methods are virtual functions. Then, implement those methods, assuming that you can call the following built-in functions:
• drawline(x1, y1, x2, y2): Draw a line from (x1, y1) to (x2, y2)
• drawcircle(x, y, r): Draw a circle centered at (x, y) with radius r
• setcolor(r, g, b): Set the drawing color by three components r (red), g (green), b (blue).
Finally, you need to define method 'contains(x, y)' to check if a point (x,y) is inside a shape. Implement this method as a virtual function for class.
Shape (it should be a pure virtual function) and the concrete classes.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
#include <cstdlib>#include <iostream>
#include <cmath>
using namespace std;
class Color {
public:
Color();
Color(double r, double g, double b);
Color(const Color& orig);
virtual ~Color();
Color operator=(const Color & color);
void setRed(double r);
void setGreen(double g);
void setBlue(double b);
private:
double red;
double green;
double blue;
};
Color::Color() {
this->red = 0;
this->green = 0;
this->blue = 0;
}...