Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Objectives : Make use of multiple Functions Use menus to select different Functions Instructions: Main Program: Design your main program so that it has

C++

Objectives:

  • Make use of multiple Functions
  • Use menus to select different Functions

Instructions:

Main Program:

Design your main program so that it has a while loop that will run until the user chooses to exit.

Inside this loop, you will also need to prompt the user to ask the user which function he/she would like to run. Use a switch statement to call the functions. This will be very similar to the menu and code that was created in Lab 4 (calculator) or it is repeated at the end of this lab.

Prime Numbers:

For the prime number function, have the method print out all primes up to a value n, which will be input from the keyboard by the user. You should ask for n inside of the main function and then pass it into the prime number method/function. Ex: n = 12 would print 2, 3, 5, 7, 11

You will receive EXTRA CREDIT (+5) if the prime number method prints n number of prime numbers rather than prime numbers up to a value n.

Ex: n = 12 would print 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37

Weighted Coins:

For this function, you will be simulating a coin toss. However, you will not be doing just any coin toss. The coin you will be simulating will be weighted so that it will land on heads 60 percent of the time and will land on tails only 40 percent of the time. In main, you need to have the user input the number of coin tosses he/she wishes to perform. Inside the for loop of the weighted Coin function (which will run until number of coin tosses is satisfied), generate a random number from 1 to 100, test the random number to see if it is <= 60 and add 1 to heads counter. If the random number is over 60, add 1 to tails counter.

Make sure the function prints out:

1) The total number of times the coin landed on heads. 2) The total number of times the coin landed on tails. 3) The percentage of the time the coin landed on heads.

Even or Odd:

In this function, you have one parameter, an integer. You need to be able to determine if the number is even or odd. Print out the appropriate message.

Hint: What operator (+ - * / %) would be helpful here?

Run:

Select the prime generator function - put in a number between 10-20 as your n. Once it finishes, select the coin toss function. Do the coin toss three times: 100, 500, and 1000. Then run EvenOdd function two times once for a number that is even and once for a number that is odd. Show one error message for the switch using the default option (picking an invalid option from the menu anything but 1-3 or -1). Make sure your code has Coded by _________ and prints that message. (meaning you exited the program fully)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Show that: (a) (VH)T=TT1 (b) (TH)s=TCp

Answered: 1 week ago

Question

List the components of the strategic management process. page 77

Answered: 1 week ago