Create a simulation class in c++

Assignment Help Programming Languages
Reference no: EM13936359

Create a simulation race between the tortoise and the hare. For this project, use random-number generation to move the creatures. To make things more interesting, the animals have to race up the side of a slippery mountain, which could cause them to lose ground. In this race either animal could win or there could be a tie with no clear winner.

The animals begin at "Square 1" of 70 squares. Each of the squares represents a position the animal can hold along the racetrack. The finish line is at Square 70. When an animal wins, a winning message of your choice should be posted. For example:

• Yay! The rabbit won! He hops the fastest!

• Woo-hooo! Slow and steady wins the race! Congratulations, turtle!

• Tie score--no winner! Want to race again?

To start the race, print a message similar to:

• Bang! Off they go!

There is a clock that ticks once per second. With each tick of the clock, your program should adjust the position of the animals according to the following rules:

Animal Move Type Percentage of the

Tortoise Fast Plod 50% 3 squares to the right

Tortoise Slip 20% 6 squares to the left

Tortoise Slow Plod 30% 1 squares to the right

Hare Sleep 20% No move at all

Hare Big Hop 20% 9 squares to the right

Hare Big Slip 10% 12 squares to the left

Hare Small Hop 30% 1 square to the right

Hare Small Slip 20% 2 squares to the left

Time

Keep track of the positions of the animals by using variables. If an animal slips, the lowest it can go is back to position 1. The highest it can go is to position 70 when it wins the race.

You will work with the percentages in the table above by generating a random integer current in the range 1 <current ≤ 10.

For the tortoise, a "fast plod" is when 1 ≤ current ≤ 5, a "slip" when 6 ≤ current ≤ 7, or a "slow plod" 8 ≤ current ≤ 10. A similar approach would be used to set up the moves for the hare.

For each tick of the clock (each repetition of the loop), print a 70-position line showing the letter T in the tortoise's position and the letter H in the hare's position. If the two animals land on the same square, which may happen, the animals will bump. If this happens, print BUMP! at the current position. (There is no Bump penalty for either animal.)

After you print each line, check to see if either animal has landed on Square 70. If this happens, print a winning-type message.

It will make the simulation more interesting if you have the user press any key after each iteration of the loop, so that they can see the movement of the animals.

Reference no: EM13936359

Questions Cloud

Write the function definition as a recursive search : Write the function definition as a recursive search, assuming an array-based implementation.
Software package that requires user to enter thei password : Write a C++ program that asks for a password and then verifies that it meets the stated criteria. If it does not, the program should display a message telling the user why.
Which activities are behind schedule : Calculate the progress of the project by completing the table - Which activities are behind schedule?
Ethical decision model to analyse the situation : Description: Part 2 is a new piece of work that should not include material from Part 1. As before, it is a written analysis (4500 words) of a complex ethical problem similar to that which you might encounter in the IT industry.
Create a simulation class in c++ : Create a simulation race between the tortoise and the hare. For this project, use random-number generation to move the creatures. To make things more interesting, the animals have to race up the side of a slippery mountain, which could cause them ..
Is the work making a statement about womens lives : Is the work making a statement about women's lives? Men's lives? How might the work be different if told from the point of view of the opposite gender? Does the work perpetuate or challenge gender stereotypes
Create a template that changes the value of 2 variables : Use the template in a program where you change the value of 2 variables of type int and 2 variables of type long.
How does piece or just small part of it relate to your life : When you are doing reader -response, you might read a work and ask yourself these kinds of questions to start coming up with a 'response': How does a piece- or just a small part of it- relate to your own life? What is it about a work that resonates ..
Derive the cube class from the base square class. : In your derived class have the default values for side be 1. For the cube class include a public function calcVal that evaluates the volume of the cube. (Hint: The volume of the cube is side * square :: calcVal.)

Reviews

Write a Review

Programming Languages Questions & Answers

  Create a database with a table called "tblprofiles"

Use a RegularExpressionValidator control on the start page that displays an error message if the user does not enter a properly formatted social security number.

  Tic-tac-toe game

You have gathered your information on the AI for the Tic-Tac-Toe game and began to develop your own ways to improve it using C++. Now, it's time to present your findings in a final paper. Remember that your final analysis and recommendations m..

  Write program to asks user to enter temperatures

Write down the C++ program which asks the user to enter 12 temperatures for each month in year and store them in one-dimensional array called "temps".

  Write code for largest value of parking tickets

Without using any additional variables, and without changing the values of ndays or the elements of the parkingTickets array, write some code that results in mostTickets containing the largest value found in parkingTickets .

  Create project to compute checking account balance

Create a project to compute your checking account balance. Form: Include radio buttons to indicate the type of transaction: deposit, check, or service charge.

  London underground fire at the kings cross underground

london underground fire at the kings cross underground station on 18 november 1987 a wooden escalator caught fire

  Write program to prints question do you want to continue

Write a program which prints question"do you want to continue?"and reads user input. if user input is"y", "yes", "ok", "sure", or "why not?" , print out "ok".

  Html and php for creating dynamic web pages

Html and PHP for creating dynamic web pages

  Write down an application with three labeled text elds one

write an application with three labeled text ?elds one each for the initial amount of a savings account the annual

  Explain modular concepts incorporated in program logic

The title of the report is Kyles Transportation Company and could you also please do the code for the report so that the program will run in Qbasic or Microsoft QuickBASIC

  Display policy data after revisions have made

The day is not correct for the month (that is, between 1 and 31 for January, 1 and 29 for February, and so on), then set the month, day, and year to 0. Display the policy data after any revisions have been made.

  Create a function that carries out the desired action

Create your own assignment to get more practice with arrays. Listed below are twenty seven functions you can write that deal with arrays. Listed next to each function is a number of points each is worth in parenthesis. Create a function that carri..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd