Consider the following code defining a composition relationship between two classes:class Squab {int y; A Squab is meant to represent a creature in a computer game that is played on a rectangular...


Consider the following code defining a composition relationship between two classes:class Squab {int y;


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 adecrease. Movement in direction N causes an increase in the y coordinate, and S a decrease


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;


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




May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here