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

  Write a prolog relation subsequence

Write a Prolog relation remove(E,L,R) that is true if R is the list which results from removing one instance of E from list L. The relation is false if E isn't a member of L.

  Creating loop to find number of items bought based on price

Make a block using a loop that will find the number of items that can be bought based on the price of the item and the total amount available to spend.

  Question 1please define sexual harrassment in addition what

question 1please define sexual harrassment. in addition what was discussed in the discussion section of this class

  Website for a labview program

A Labview program that measures a lot of different things such as voltage, current , temperature , watt, etc - you need to have a website that displays these data for an easier access.

  Advantages of using invisible html table to create web page

What advantages do you see in using an invisible HTML table to structure an entire Web page? What disadvantages does the table structure pose?

  Explain simple javascript event

Modify the body tag of your page to include the onLoad event handler. Within the event handler call the MyLoadFunction().

  Design program which models worms behavior

Design a program that models the worms behavior in the following scenario: A worm is moving toward an apple. Each time it moves, the worm cuts the distance between itself and the apple.

  Provide example of array and how it could be used

Provide the example of the Array and how it could be used. Then look over sections on ArrayLists. Would an ArrayList be better suited for your use?

  Create a very abstract programming environment

Find these header files in the Visual Studio system and determine the smallest (i.e., most negative) and largest (i.e., most positive) values that can be represented as int, unsigned int, long, unsigned long, float and double.

  Write down a program which explores the seating patterns

write a program that explores the seating patterns related to course performance by using an array of student scores.

  Php script to obtain url and its description from user

Write a PHP script to obtain URL and its description from user and stores information into database by using MySQL.

  Create a new class called soda

Create a new class called Soda that is also a caffeinated beverage by default it will have no option for condiments. Have it called in main. Main also calls the old addLemon function on Tea so that the customer gets two lemons. Use an adapter to s..

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