Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please include algorithm with code. I will give you a like.(in the question the highlighted part is previous assignment that could give you an idea

please include algorithm with code. I will give you a like.(in the question the highlighted part is previous assignment that could give you an idea on how to approach)

Overview

Use the principles of Object Oriented Design (OOD) and Object Oriented Programming (OOP) to re-build the horseRace assignment using object-oriented programming. Each horse will be an object, and the race will be another object that contains a list of horses and manages the race. Along the way, you will experiment with UML, create classes, review access modifiers, build member variables, add access methods, and create constructors.

The Project

Build a program that simulates a horse race. The race works just like the last assignment(Build a program that simulates a horse race. You will have a track of 15 units long, and five horses. On each turn, each horse will 'flip a coin' (Right, I don't know how horses flip coins either, but go with me on this.) Half the time, the horse will move forward one unit, and half the time it will stay in the same place. On each turn, you will see the track with the positions of the five horses, and dots for all the other positions. The race ends when one of the horses passes the finish line) and the user may not ever see the difference. But this time, the underlying design will use objects. You will have two objects in the game. There will be an array of five horse objects. The horse will 'know' how to advance according to a random flip, and to return its position. The other primary entity in this game is the race (or the track, if you prefer.) This object will contain a series of horses. It will also have the ability to start the race. When the race is running, the race class will 'tell' each horse to advance, and will print out a track diagram showing the relative positions of the horses.

In this case we may do automated testing against your program. In order to accommodate this you will prompt (ask for input) for a random seed and use it to seed your random number generator. This will allow you to test your program against several seeds. And we may test your program with a series of these random seeds.

Sample Run

Note that you will not need the automation feature nor a GUI. This just gives you an idea of the race concept.

Here is a sample run of the program:

Please enter a random seed: 700 .0............. .1............. .2............. 3.............. 4.............. ..0............ ..1............ ..2............ .3............. .4............. ...0........... ..1............ ...2........... .3............. .4............. ...0........... ..1............ ....2.......... .3............. .4............. ...0........... ..1............ ....2.......... ..3............ ..4............ ...0........... ...1........... ....2.......... ...3........... ...4........... ...0........... ...1........... ....2.......... ....3.......... ...4........... ...0........... ...1........... .....2......... .....3......... ...4........... ...0........... ...1........... .....2......... ......3........ ....4.......... ...0........... ...1........... ......2........ .......3....... ....4.......... ....0.......... ...1........... .......2....... ........3...... .....4......... ....0.......... ...1........... .......2....... ........3...... ......4........ .....0......... ...1........... .......2....... .........3..... ......4........ .....0......... ....1.......... .......2....... .........3..... ......4........ .....0......... ....1.......... ........2...... ..........3.... ......4........ .....0......... .....1......... ........2...... ...........3... .......4....... .....0......... ......1........ .........2..... ............3.. .......4....... .....0......... .......1....... .........2..... ............3.. .......4....... .....0......... ........1...... .........2..... ............3.. .......4....... .....0......... ........1...... ..........2.... .............3. .......4....... ......0........ .........1..... ...........2... .............3. .......4....... .......0....... .........1..... ...........2... ..............3 .......4....... ........0...... ..........1.... ............2.. ..............3 ........4...... .........0..... ..........1.... ............2.. ..............3 ........4...... .........0..... ..........1.... .............2. ............... ........4...... Horse 3 wins! 

Code Organization

While you have already written this program in a procedural fashion, this program is a perfect candidate for the object-oriented paradigm. Please use the UML diagram I created as a starting point:

Tips

You will need two classes: each will have a header and a cpp file.

You will also need a main.cpp file.

do not include namespace std

Your make file should have a target for each object as well as the main target to build the final executable.

Your make file should also include clean and run targets.

The horse class will need to utilize random number generation. I included an example of this with the last homework exercise, but you may still need to look up how to generate a random number in C++. Don't forget the srand() function to ensure you get a different random sequence on each run of the program.

Each class will need a simple constructor. (My version of Race actually has two constructors.) Remember that every class should have a null parameter constructor. Also, remember that the main point of a constructor is to initialize the member variables. You might additionally do some other initial work that happens only once in the constructor. (That was a hint.)

Each method should represent something the class can DO. Each member variable should be information that the data has.

This program uses an aggregate data structure. One of the classes includes an array of instances of the other class.

The Race class' start() method (at least in my version of the program) controls most of the race action. It not only starts the race, but it controls the entire race.

The Race::printLane() method is used to print out a visual depiction of the lane for a particular horse. This method is easy to visualize, but it can be tricky to implement, because the horse ID will probably be an integer, and the rest of the track will likely be characters. Think about how clever use of std::cout and the << operator might simplify this situation.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions