Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Since we just learned about reference parameters for functions, now's your chance to use them! You are to write a short program that prompts the

image text in transcribed
Since we just learned about reference parameters for functions, now's your chance to use them! You are to write a short program that prompts the user for two integer values. Then these values are passed to the MegaCalc function, which will derive the sum, difference, product, and quotient with remainder all in one function call! But how can a function return more than one value? By using formal parameters that are reference variables. So the main function needs to declare plenty of local variables, so that it can pass the following arguments to the MegaCalc function: . the value of the first operand (pass by value) the value of the second operand (pass by value) a variable to store the sum (pass by reference) a variable to store the difference (pass by reference) . a variable to store the product (pass by reference) a variable to store the quotient (pass by reference) a variable to store the remainder (pass by reference) The MegaCalc function returns no value to the caller. After the call to the MegaCalc function returns, main must display the results to stdout. But that's not all -- what will you do if the user enters a value of zero for the second operand? If you don't handle the situation, your program will crash because the CPU will not allow division by zero. That means MegaCalc must not allow division by zero to occur, and that the main function must write an appropriate message when displaying the final results of the calculations. For example, if the user enters values of 5 and 2 we should see the following appear on the screen: Please enter two integer values separated by whitespace: 5 2 Here are the results: 5 plus 2 equals 7 5 minus 2 equals 3 5 multiplied by 2 equals 10 5 divided by 2 equals 2 with a remainder of 1 But with the second operand having a value of zero, we should see the following: Please enter two integer values separated by whitespace: 5 Here are the results 5 plus o equals 5 5 minus equals 5 S multiplied by o equals o Division by zero is undefined

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

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago