Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

HW08: MegaCalc 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 equals7 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 0 Here are the results: 5 plus 0 equals 5 5 minus 0 equals 5 5 multiplied by 0 equals0 Division by zero is undefined If you need to read more about reference parameters, they're discussed in your textbook beginning on p.259. Just save your code in a file called megacalc.cpp in the HW08 subdirectory

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

Students also viewed these Databases questions

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago