Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a base class Shape with virtual functions void draw(GraphicWindow& win) c

ID: 3552193 • Letter: D

Question

Design a base class Shape with virtual functions


void draw(GraphicWindow& win) const;
void move(double dx, double dy);


The Circle, Line, and Message classes of Chapter 2 are not derived from the Shape
class. Supply three adapter classes CircleShape, LineShape, and MessageShape. Supply
a test program that populates a vector<Shape*> with adapted objects, and demon-
states the draw and move functions.

#include "ccc_win.h"

int ccc_win_main()

{  

   Point p(1, 3);

   cwin << p << Circle(p, 2.5);

   return 0;

}

#include "ccc_shap.h"

#if defined(_MSC_VER)

   #define CCC_MSW

#endif

#if defined(_WINDOWS_) || defined (_Windows) || defined(WINVER) || defined(__WIN32__)

   #define CCC_MSW

#endif

#if defined(__GNUC__) && !defined(CCC_MSW)

   #define CCC_X11

#endif

#if defined(CCC_ASC)

#include "ccc_asc.h"

#elif defined(CCC_WXW)

#include "ccc_wxw.h"

#elif defined(CCC_X11)

#include "ccc_x11.h"

#elif defined(CCC_MSW)

#include "ccc_msw.h"

#else

#include "ccc_asc.h"

#endif

Explanation / Answer

class Shape { public: Shape(int newx, int newy); int getX(); int getY(); void setX(int newx); void setY(int newy); void moveTo(int newx, int newy); void rMoveTo(int deltax, int deltay); virtual void draw(); private: int x; int y; };#include "Shape.h" // constructor Shape::Shape(int newx, int newy) { moveTo(newx, newy); } // accessors for x & y int Shape::getX() { return x; } int Shape::getY() { return y; } void Shape::setX(int newx) { x = newx; } void Shape::setY(int newy) { y = newy; } // move the shape position void Shape::moveTo(int newx, int newy) { setX(newx); setY(newy); } void Shape::rMoveTo(int deltax, int deltay) { moveTo(getX() + deltax, getY() + deltay); } // abstract draw method void Shape::draw() { }class Rectangle: public Shape { public: Rectangle(int newx, int newy, int newwidth, int newheight); int getWidth(); int getHeight(); void setWidth(int newwidth); void setHeight(int newheight); void draw(); private: int width; int height; };#include "Shape.h" #include "Rectangle.h" #include // constructor Rectangle::Rectangle(int newx, int newy, int newwidth, int newheight): Shape(newx, newy) { setWidth(newwidth); setHeight(newheight); } // accessors for width and height int Rectangle::getWidth() { return width; } int Rectangle::getHeight() { return height; } void Rectangle::setWidth(int newwidth) { width = newwidth; } void Rectangle::setHeight(int newheight) { height = newheight; } // draw the rectangle void Rectangle::draw() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote