Question: (Part B) : Pass by value versus pass by reference 40 points Write a C++ program which prompts user to choose from the two alternative

(Part B) : Pass by value versus pass by reference 40 points

Write a C++ program which prompts user to choose from the two alternative funtions specified below, each of which returns a random message. The random number generator function should be called from within the functions.

The two functions are:

  1. Function messageByValue is a value returning function that returns the message by value and
  2. Function messageByReference is a void function that returns the message by reference.

Each function returns one of four random messages:

  1. Sorry. Youre not close enough! returned 25% of the time
  2. Oh, youre almost there? returned 15% of the time
  3. Aw cmon, you can do better than that! returned 20% of the time
  4. Youre up big. Getting closer to breaking your old record returned 40% of the time

NOTE: Use a while loop to continually run program until a -1 is entered to Terminate program.

  1. The problem requires that you determine the parameters needed for each function.
  2. The message should be displayed in main().
  3. No Global non-constant variables should be used.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!