Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in C++, thanks For this program, you will design a class MazeRacer to keep track of where a mouse or human is on a grid.
in C++, thanks
For this program, you will design a class MazeRacer to keep track of where a mouse or human is on a grid. You will use this class to write an application program that first asks the user to provide names for two MazeRacer objects and starting coordinates for the second of them. The program then
requests target coordinates and a move sequence for each MazeRacer. Finally, it reports whether each racer ended up at the target. A sketch of the application is provided in your starter file. When you are finished, your program should be able to produce output as follows:(in picture)
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, and so the information about Algernon should be processed by one MazeRacer object and the information about Charlie should be processed by another. Your class must have member variables that keep track of the name, location, and number of moves that have been taken by a racer. It should have member fields that allow the location to change with incremental moves (e.g., moveLeft()). These move functions should be the only way to modify the location. Add accessor methods wherever your program needs it. You should have at least two constructors, and you should make thoughtful decisions abut what should be public and what should be private.
Some useful code:
#include
#include
using namespace std;
class MazeRacer {
};
void moveRacer(MazeRacer& racer);
void checkDestination(MazeRacer racer, int tx, int ty);
int main() {
cout
MazeRacer racer1; // first get name then construct racer1 accordingly
cout
cout
cout
MazeRacer racer2; // get name and coordinates; construct racer2 accordingly
cout
int tx, ty; // populate target coordinates
// implement moveRacer to get move sequence from user
moveRacer(racer1);
moveRacer(racer2);
// implement checkDestination to see whether targets are reached
checkDestination(racer1, tx, ty);
checkDestination(racer2, tx, ty);
return 0;
}
// get move sequence from user and move racer accordingly
void moveRacer(MazeRacer& racer) {
cout
string seq;
cin >> seq;
for (int i=0; i
// move racer depending on the direction specified by seq.at(i)
}
}
// report whether racer is at (tx,ty)
void checkDestination(MazeRacer racer, int tx, int ty) {
if (true) { // replace this condition with an appropriate one
cout
Enter a name for the first maze competitor: Algernon Algernon 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 (LRUD) for Algernon: RRURUUU Enter a sequence of moves (LRUD) for Charlie: RRU Algernon was at the target after 7 moves Charlie was not at the target after 3 moves } else {
cout
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started