Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ (please dont answer unless you completly understand) Lab 6 - Functions l Obiectives Make use of multiple Functions . Use menus to select different

C++ (please dont answer unless you completly understand) image text in transcribed
image text in transcribed
Lab 6 - Functions l Obiectives Make use of multiple Functions . Use menus to select different Functions 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. 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 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 randonn 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, add1 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 Qdd 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 fronm the menu-anything but 1-3 or-1). Make sure your code has "Coded by that message. (meaning you exited the program fully) "and prints You will need to turn in your source code, as well as your output as described above. Please submit both files to D2L See Lab 1's instruction sheet for details on how to document and submit your work if need be. ALGORITHM FOR MAIN CODE FOR LAB 6 1. prompt and read in a code (1-3,-1 to stop) 2. while (code !=-1) 2.1 switch (code) case 1 - prompt and read in n call prime(n) break case 2-prompt and read in a num (100, 500, 1000) call coinToss (num) break case 3-prompt and read in a value call evenOdd (value) break default - print "Bad Code" 2.2 prompt and read in a code (1-3,-1 to stop) 3. Stop

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 Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

On the same day, Kyoto Fund converted $500,000 into JPY at

Answered: 1 week ago