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

C++ PROGRAMMING Hi! My assignment prompt is below. What I\'m having the most tro

ID: 3793201 • Letter: C

Question

C++ PROGRAMMING

Hi! My assignment prompt is below. What I'm having the most trouble understanding is where the shapes are being stored. I'm assuming an array, but I'm not sure how sizing would work. Any help is appreciated, thanks! I have also attached the .h file we must use.

Prompt: The goal of HW2 is to implement classes representing shapes. A given program will use this class to create shapes at arbitrary locations in the x-y plane and move them. The program uses a function to move shapes and to detect if shapes overlap. The board is assumed to be the entire x- y plane.

Shape.h:

//

// Shape.h

//

#ifndef SHAPE_H

#define SHAPE_H

class Shape

{

public:

virtual ~Shape(void);

virtual char name(void) const = 0;

virtual int size(void) const = 0;

void print(void) const;

void move (int dx, int dy);

bool overlap(const Shape &t) const;

static Shape *makeShape(char ch,int posx,int posy);

protected:

int *x, *y;

};

class O: public Shape

{

public:

O(int posx, int posy);

virtual char name(void) const;

virtual int size(void) const;

};

class I: public Shape

{

public:

I(int posx, int posy);

virtual char name(void) const;

virtual int size(void) const;

};

class L: public Shape

{

public:

L(int posx, int posy);

virtual char name(void) const;

virtual int size(void) const;

};

class S: public Shape

{

public:

S(int posx, int posy);

virtual char name(void) const;

virtual int size(void) const;

};

class X: public Shape

{

public:

X(int posx, int posy);

virtual char name(void) const;

virtual int size(void) const;

};

class U: public Shape

{

public:

U(int posx, int posy);

virtual char name(void) const;

virtual int size(void) const;

};

#endif

Figure I: 0 1 2 3 1 2 3 4 0 1 2 Figure 1 The cells (or squares forming a shape are indexed by a number starting from 0, as shown in Fig 1. A shape can be placed on a board by specifying the position of its "zeroth cell" in the x-y plane. In Figure 2 below, shapes have been placed on a board as follows:

Explanation / Answer

Virtual functions makes sense only in xclasses meant to act as interface to objects of derived class which are typically allocated on heap and accessed through pointers or references.

The shaping rework is performed in those area.

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