Lab 12

For all problems involving random number generation, add code to ensure that each time the program runs, the random number sequence is distinct.

  1. Write a complete C++ program that does the following:
  2. Sample run of program:
    Enter a number greater than or equal to 10: 7 Invalid input! Try again: 11 Random number between 1 and 11 is 9
  3. Write a complete C++ program that does the following:
  4. Sample run of program:
    Enter two positive integers with a difference of at least 10: -1 15 Invalid input! Try again: 5 9 Invalid input! Try again: 15 39 Random number between 15 and 39 is 23
  5. Write a complete C++ program that simulates rolls of a die.
  6. Sample run of program:
    Enter a number of die rolls: 5 Roll 1: 2 Roll 2: 3 Roll 3: 6 Roll 4: 1 Roll 5: 2 Total number of ones rolled: 1

  7. Write a C++ program to play a guessing game:
  8. Sample run of program:
    Guess the number I'm thinking of between 1 and 100: 50 Too big 40 Too small 45 Too big 43 Too small 44 Congratulations! You took 5 guesses.

  9. Write a C++ program to simulate repeated coin tosses with a penny for 10, 100, 1000, and 5000 repeats.
  10. Sample run of program:
    Probability of heads given 10 tosses = 0.6 Probability of tails given 10 tosses = 0.4 Probability of heads given 100 tosses = 0.53 Probability of tails given 100 tosses = 0.47 Probability of heads given 1000 tosses = 0.484 Probability of tails given 1000 tosses = 0.516 Probability of heads given 5000 tosses = 0.4974 Probability of tails given 5000 tosses = 0.5026