Question: Assignment Functions (Pass by Value, Pass by Reference) The code should be well structured and has correct logic. It should follow programming best practices. The

Assignment Functions (Pass by Value, Pass by Reference)

The code should be well structured and has correct logic. It should follow programming best practices. The code should be well indented and commented.

PART 1: Write a program that will read two floating point numbers (the first read into a variable called first and the second read into a variable called second) and then calls the function swap with the actual parameters first and second. The swap function having formal parameters number1 and number2 should swap the value of the two variables.

NOTE: Do not name your function 'swap'. Compilers have their own function swap and will use their own function, not yours. So it will appear that your function works while it may not. Name it 'swapp', 'exchange', or something similar.

Sample Run:

Enter the first number

Then hit enter

80

Enter the second number

Then hit enter

70

You input the numbers as 80 and 70.

After swapping, the first number has the value of 70 which was the value of the

second number

The second number has the value of 80 which was the value of the first number

Part 2: Write a program that will input miles traveled and hours spent in

travel. The program will determine miles per hour. This calculation must

be done in a function other than main; however, main will print the

calculation. The function will thus have 3 parameters: miles, hours, and

milesPerHour. Which parameter(s) are pass by value and which are

passed by reference? Output is fixed with 2 decimal point precision.

Sample Run:

Please input the miles traveled

475

Please input the hours traveled

8

Your speed is 59.38 miles per hour

Part 3: Write a program that will read in grades, the number of which is

also input by the user. The program will find the sum of those grades and

pass it, along with the number of grades, to a function which has a pass

by reference parameter that will contain the numeric average of those

grades as processed by the function. The main function will then determine

the letter grade of that average based on a 10-point scale.

90100 A

8089 B

7079 C

6069 D

059 F

Sample Run:

Enter the number of grades

3

Enter a numeric grade between 0-100

90

Enter a numeric grade between 0-100

80

Enter a numeric grade between 0-100

50

The grade is C

Note: Every time you use functions, you MUST write prototypes and implement the functions after the main function.

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!