A squab is meant to represent a creature in a computer game


Consider the following code defining a composition relationship between two classes:

A Squab is meant to represent a creature in a computer game that is played on a rectangular grid. Positions on the grid are specified by two coordinates (x and y). Directions are represented by four letters: N, S, E and W. Movement in direction E causes an increase in the x coordinate, and W a decrease. Movement in direction N causes an increase in the y coordinate, and S a decrease

class Squab {

private:
int score;
Position pos;
public:
Squab(int x, int y);
int getScore() const;
void incScore();
Position getPos() const;
void move(char dn, int de);
bool lineOfSight(Squab s) const;
Squab * clone() const;
};
class Position {
private:
int x;

int y;
public:
Position(int x, int y);
void changePos(int x, int y);
int getX() const;
int getY() const;
};

A Squab is meant to represent a creature in a computer game that is played on a rectangular grid. Positions on the grid are specified by two coordinates (x and y). Directions are represented by four letters: N, S, E and W. Movement in direction E causes an increase in the x coordinate, and W a decrease. Movement in direction N causes an increase in the y coordinate, and S a decrease

Solution Preview :

Prepared by a verified Expert
Programming Languages: A squab is meant to represent a creature in a computer game
Reference No:- TGS01297250

Now Priced at $20 (50% Discount)

Recommended (98%)

Rated (4.3/5)