Question
//follow the code bellowwww ( main code ) #include #include #include #include #include shape.hpp #include circle.hpp #include rect.hpp using namespace std; // ? Notes: Choose
//follow the code bellowwww ( main code )
#include
#include "shape.hpp" #include "circle.hpp" #include "rect.hpp"
using namespace std;
// ? Notes: Choose the debug mode "Multi-File Graphic Project" to run this program.
// You may change the max size of the list #define COUNT 5
int main() { int width = getmaxwidth(); int height = getmaxheight(); initwindow(width, height, "Exercise 5");
/* initialize random seed: */ srand(time(NULL));
char ch = 0;
while (ch != 27) // 27 is ESC key { if (kbhit()) { ch = getch(); switch (toupper(ch)) { case '+': break;
case '-': break;
case KEY_LEFT: break;
case KEY_RIGHT: break;
case KEY_UP: break;
case KEY_DOWN: break; } }
if (ismouseclick(WM_LBUTTONDOWN)) { } } return 0; }
//circle.cpp #include
#include "circle.hpp"
Circle::Circle(int _x, int _y, int _radius): radius(_radius) {}
//circle.hpp
#ifndef CIRCLE_H #define CIRCLE_H
class Circle { protected: int radius;
public: Circle(int _x = 0, int _y = 0, int _radius = 0); };
//rect.cpp #include
#include "shape.hpp" #include "rect.hpp"
Rect::Rect(int _x, int _y, int _width, int _height) : width(_width), height(_height) {}
//rect.hpp #ifndef RECT_H #define RECT_H
class Rect { protected: int width, height;
public: Rect(int _x = 0, int _y = 0, int _width = 0, int _height=0); };
#endif
//shape.cpp #include
Shape::Shape(int _x, int _y) : x(_x), y(_y), selected(false) {}
void Shape::setLocation(int _x, int _y) { x = _x; y = _y; }
void Shape::setSelected(bool _selected) {selected = _selected;}
//shape.hpp #ifndef SHAPE_H #define SHAPE_H
class Shape { protected: int x, y; // for location bool selected; // to indicate whether the shape is selected or not public: Shape(int _x = 0, int _y = 0); void setLocation(int _x, int _y); void setSelected(bool _selected); };
#endif #endif
please solve it by the code c++. please no misuse.
Question In this exercise you will be writing a C++ program that implements the concept of polymorphism. The program will do some manipulations on two types of shapes, circles, and rectangles, including resizing and moving the shape. The program will show a list of shapes on the screen randomly. However, the user can only manipulate one shape at a time. In this case, he or she first needs to choose a shape from the list using a mouse click. Table 1 shows the list the operations and their commands. Expected result of the program is given in several videos that come with this exercise. User Interaction Mouse click Keyboard press + or - Arrow keys Table 1: The commands for the user Operation To choose a shape that the user will be manipulating or working on To enlarge or shrink the selected shape. To move the object accordingly, i.e, to the left, right, up or down. You are expected to write the program by separating class specification and implementation into their dedicated files, i.e. hpp and cpp respectively. In fact, the separation has been done for you in the codebase that comes with this exercise. Besides, the code for some parts of the program has been provided including the basic structure of each class, and the main loop in the main function. Modify the codebase to achieve the goal of the program. Note that you must implement the concept of polymorphism to write the program Formulas Below are the formulas that you may need to use in your code: Determining whether a mouse click is inside a circle. Assuming a mouse click at location (mx.my), the mouse is considered inside the circle if its distance from the circle's center (cx,cy),d is smaller than or equal to the circle's radius, r. ie, dr The distance can be determined by Pythagorean theorem: d = V(mx - cx)2 + (my - cy)2 - Determining whether a mouse click is inside a rectangle. Assuming a mouse click at location (mx,my), the mouse is considered inside the rectangle if the following conditions are met. x15 mx 5x2 and yis my Sy2 Where (x1, y) and (x2, y2) are the top-left and bottom-right comers of the rectangle as shown in the following figure (x1, (x2,y2)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started