SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 313 Weeks Ago, 5 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 30 Nov 2017 My Price 10.00

execute a program that simulates a coin toss and a dice roll.

This should be written in C++ any questions please ask the instructions are attached and thanks in advance!

 

Student Lab Activity

 

 
devry-u-rgb_logo-small

 

CIS170C Week 4 Lab Instructions

 

Lab 4 of 7:  Functions

 

Lab Overview—Scenario/Summary

 

You will code, build, and execute a program that simulates a coin toss and a dice roll.

 

Learning outcomes:

 

1.       Write functions using parameters.

2.       Be able to debug a program with syntax and logic errors.

3.       Be able to use the debug step-into feature to step through the logic of the program and to see how the variables change values.

 

Deliverables

 

Section

Deliverable

Points

Lab 4

Step 5: Program Listing and Output

40

All Steps

Total

40

 

Lab Steps

 

Preparation:

 

If you are using the Citrix remote lab, follow the login instructions located in the lab area in Course Home.

 

Locate the Visual Studioicon, and launch the application.

 

Step 1: Requirements:Coin Toss and Dice Rolling program

Write a program that simulates flipping a coin and rolling a dice.

 

A user will input their choice of flipping a coin (C), rolling a dice (D), or exiting (E).

 

If the user chooses a coin toss, the program will ask how many times the coin should be tossed, and then will simulate tossing the coin that many times and print the result to the user.

 

If the user chooses rolling a die, the program will ask how many sides the die has and how many times it should be rolled.  The program will then simulate rolling a die (with the number of sides specified) that many times.

 

The program will continue until the user presses E.

 

 

This should be a lot of fun!

Here are some great things to think about as you begin your program!

 

You will need two functions.A string flipCoin()and aint rollDice(int)function. These functions will generate a random number. For the coin flip, the random number should be in the range of 1 to 2. If the number is 1, the function should returnheads. If the random number is 2, the function should returntails.For the roll dice function, the random number should be in the range of 1 to the number of sides. The function should return the result of the die roll.

Important notes: You will want to seed your random number generator. To do this at the beginning of your program #include <ctime>.

Use the following commands to seed the random number generator.

            //Get the system time to use it to seed the random number generator

            unsigned seed = time(0);

           

            //seed the random number generator

            srand(seed);

 

To get a random number between 1 and 2, use the following code: int toss = 1 + rand() % 2;.

 

Sample Output from the Program

 

Welcome to the random value generator!

Would you like to flip a coin (C), roll a die (D), or exit (E)? C

How many times do you want to flip the coin? 5

Flip 1 : tails

Flip 2 : heads

Flip 3 : heads

Flip 4 : heads

Flip 5 : tails

Would you like to flip a coin (C), roll a die (D), Exit (E)? D

How many sides does your die have? 6

How many times do you want to roll the die? 5

Roll 1 : 5

Roll 2 : 3

Roll 3 : 2

Roll 4 : 2

Roll 5 : 2

Would you like to flip a coin (C), roll a die (D), or exit (E)? D

How many sides does your die have? 20

How many times do you want to roll the die? 3

Roll 1 : 19

Roll 2 : 16

Roll 3 : 15

Would you like to flip a coin (C), roll a die (D), or exit (E)? E

Thanks for playing!

Press any key to continue.

 

Step 2: Processing Logic

Using the pseudocode below, write the code that will meet the requirements.

Main Function
    Declare the number of tosses, number of sides, and user choice.

    Seed the random number generator.

 

    while user choice !=E
        Ask the user if they want to flip a coin, roll a die, or exit.

        If the choice is C

             Ask the user how many times to flip the coin.

    For i=1 to number of flips Step 1

                        Call flipCoin()

                         Print result

        If the choice is D

Ask the user how many sides the die has.

            Ask the user how many times to roll the die.

    For i=1 to number of rolls Step 1

                        Call rollDice()

                         Print result
          Else

    Display the closing message.

 

 

flipCoin Function

Generate an integer random number between 1 and 2.

    If a 1 is generated return heads, else return tails.

rollDice Function

      Generate a random number between 1 and the number of sides.

      Return the result of the roll.

Step 3: Create a New Project

Create a new project and name it LAB4.

 

Write your code using the processing logic in Step 2 (above). Make sure that you save your program.

Step 4: Compile and Execute

a)      Compile your program. Eliminate all the syntax errors.

 

b)      Build your program, and verify the results of the program. Make corrections to the program logic, if necessary, until the results of the program execution are what you expect.

 

Step 5: Print Screenshots and Program

 

1.      Capture a screen print of your output (do a print screen and paste into an MS Word document).

2.      Copy your code and paste it into the same MS Word document that contains the screen print of your output.

3.      Save the Word document as Lab04_LastName_FirstInitial.

 

 

END OF LAB

 

Attachments:

Answers

(5)
Status NEW Posted 30 Nov 2017 01:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)