QuestionQuestion

In this assignment, you will design the class hierarchy for a drawing program. This program can draw the following shapes: point, line, circle, and rectangle. Each shape has a color. You first need to determine the classes you need for this program. For example, you need an abstract class Shape as the parent of concrete shapes like rectangle or circle and a class Color to represent colors.
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 PreviewSolution 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;
}...
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats