BEST代写-线上留学生作业代写 & 论文代写专家

成立于2015年的老牌留学生代写品牌-BEST代写提供超过百门冷热门留学学科的作业和论文代写服务。全网BEST原创,高质,准时的留学生代写。

C++代写 | COMP 2404 – Assignment #3

C++代写 | COMP 2404 – Assignment #3

这个作业是用C++使用策略模式模拟龟兔赛跑

COMP 2404 – Assignment #3

For this assignment, you will write a C++ program to implement a simplified version of the Strategy design
pattern. Your program will simulate a race between a tortoise and hare, using behaviour classes to implement
different types of runner movements.

Draw a UML class diagram
We are going to implement the Strategy design pattern in a hierarchy of move behaviours, similar to
the hierarchy of dance behaviours from the in-class coding example of section 3.4, program #8. The
program will represent a collection of runners making their way from the left-hand side of the screen to
the right-hand side, and each runner’s move behaviour will change randomly at every step.
To do this, you will implement an abstract MoveBehaviour class, along with five concrete sub-classes:
the WalkBehaviour class will cause a runner to move forward by one position, the SleepBehaviour class
will cause a runner to stay in their current position, the JumpBehaviour class will cause a runner to move
forward by a random number of positions, the SlideBehaviour class will cause a runner to slip backwards
by a random number of positions, and the TeleportBehaviour class will cause a runner to move to a
random location on the screen.
The abstract MoveBehaviour class will require a pure virtual move() function, and the appropriate behaviour will be implemented in the concrete sub-classes.
Your program will implement a Race class that serves as the control object, and a View class that handles
all output to the screen. The Race class will store a collection of Runner objects corresponding to the
runners of the race, and each Runner object will store a MoveBehaviour object that computes the runner’s
next move.
You will begin by drawing a UML class diagram, drawn by you using a drawing package of your choice,
and your diagram will follow the conventions established in the course material covered in section 2.3.
Your diagram will represent all the classes in your program, including the control, view, and entity classes,
as well as the hierarchy of move behaviour classes. Your diagram will show all attributes, all operations
(including the parameters and their roles such as in, out, in-out), where applicable. As always, do not
show collection classes, as they are implied by multiplicity. Do not show other objects as attributes, as
these must be shown as associations. Do not show simple getters, setters, constructors, or destructors.
While you must begin drawing your UML diagram in this step, you will need to update it throughout
the instructions below. The diagram that you submit with your assignment must match your completed
program.

Implement the Position class
You will begin by implementing a new Position class that contains the following data members:
3.2.1. a row, as an integer
3.2.2. a column, as an integer
The Position class will contain the following member functions:
3.2.3. a constructor that initializes the data members to default values
3.2.4. getter member functions for both data members
3.2.5. setter member functions for both data members
3.3. Implement the MoveBehaviour classes
You will implement the hierarchy of MoveBehaviour classes, which you will model on the DanceBehaviour
classes that we worked on during the lectures. You can find these classes in the coding example posted
in cuLearn, in section 3.4, program #8.
You will implement the MoveBehaviour classes as follows:
3.3.1. You will create a new MoveBehaviour abstract class that serves as the base class for the other
behaviour classes. The MoveBehaviour class will contain a pure virtual member function, as follows:
(a) void move(Position& oldPos, Position& newPos, string& log) computes a new position
newPos for the runner, given its current position oldPos; the move() function will return a short,
text description of the move in the log parameter, which will be printed to the screen in a later
step
3.3.2. You will create five concrete move behaviour classes, which derive from the MoveBehaviour class,
as follows:
(a) the WalkBehaviour class will have a move() function that keeps the runner in the same row and
moves it one column to the right
(b) the SleepBehaviour class will have a move() function that keeps the runner in the same row
and column
(c) the JumpBehaviour class will have a move() function that keeps the runner in the same row and
moves it forward by a random number between 1 and 8 of columns to the right
(d) the SlideBehaviour class will have a move() function that keeps the runner in the same row
and moves it backward by a random number between 1 and 5 of columns to the left
(e) the TeleportBehaviour class will have a move() function that moves the runner to a valid position at a random row and a random column
NOTE: You may keep the move behaviour class definitions in a single header file, and the corresponding
member function implementations in a single source file.
3.4. Implement the Runner class
You will implement a new Runner class that contains the following data members:
3.4.1. the runner’s name, as a string object
3.4.2. the runner’s avatar, as a char
3.4.3. the runner’s bib number, as an integer; this is the number pinned to the runner’s shirt that uniquely
identifies them
3.4.4. the runner’s lane number, as an integer; this is the row on the screen where the runner will be at
the beginning of the race
3.4.5. the runner’s current position, as a Position object
3.4.6. a pointer to the runner’s current MoveBehaviour object
3.4.7. the current log, as a string object, describing the runner’s last move

bestdaixie

评论已关闭。