Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 2. For your second program, you will design a class MazeRacer to keep track of where a mouse or human is on a grid,

image text in transcribed

Program 2. For your second program, you will design a class MazeRacer to keep track of where a mouse or human is on a grid, and you will use this class to write an application program that simulates a race between two MazeRacer objects. The application program will create a default racer called Algernon, who starts at (0,0), and it will ask the user to provide the name and starting coordinates names for a second racer. The program then requests target coordinates and a move sequence for each racer (L denotes left, R denotes right, U denotes up, and D denotes down). After moving each racer according to the appropriate move sequence, the program reports where each racer ended up, whether it was at the target, and how many moves were taken. If exactly one racer reached the target, that is the winner; if both reach the target but one took fewer moves, that is the winner; otherwise, you should output Tie!. When you are finished, your program should be able to produce output as below. (User input is highlighted for clarity.) The first maze competitor is Algernon, who will start at (0,0). Enter a name for the second maze competitor: Charlie Enter starting coordinates for Charlie: 1 2 Enter the target coordinates: 3 4 Enter a sequence of moves for Algernon: RRURUUU Enter a sequence of moves for Charlie: RRUL Algernon was at target (3,4) after 7 moves. Charlie was at (2,3) after 4 moves. Algernon wins! OOD requirements: Although you could probably get a program that produces output as above without using classes, the purpose of this problem is to practice class design. Your program should use a separate MazeRacer object to keep track of and process information about each individual racer. Your class must have member variables that keep track of the name, location, and number of moves that have been taken by a racer. The racers don't need to know the target. Your class should have a 1-argument member function moveOne that allows it to move one spot based on the character passed in, and this should be the only way to modify location. Add accessor methods wherever your program needs it. Define at least two constructors; it would be wise for the O-argument constructor to initialize Algernon's name and starting coordinates (0,0). Make good OOD decisions about what should be public and what should be private. Style notes: Because class design is the goal of this program and the application itself has relatively linear control flow, don't worry if your main function is a bit long and perhaps not optimally decomposed into the different phases of the program. Still do use comments to make the structure easy to identify, and follow all the other usual style guidance

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

How could assessment be used in an employee development program?

Answered: 1 week ago