Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Someone please help me fill this in. I'm completely clueless on what to put in. DO_2 to DO_10. // Purpose: This program reads pairs of

Someone please help me fill this in. I'm completely clueless on what to put in. DO_2 to DO_10.

// Purpose: This program reads pairs of numbers and performs different // operation based on the relationships between the numbers in // the pair. These relationships and actions include: // // 1. The first number is greater than the second: // Compute and then display the sum of the squares of the // numbers between the second and the first numbers // (inclusive). // // 2. The two numbers are equal: // Compute and then display the square of the first number. // // 3. The second number is greater than the first: // Compute and then display the square of the sum of the // numbers between the first and second numbers (inclusive). // // 4. Either number is negative: // Halt the program and display the value of constant // NEGATIVE_RESULT as the result. // // Input: Pairs of integers. Will halt when a negative number is input. // // Output: For each pair of numbers the output will follow the // specifications defined by the four conditions described // in the Purpose. // //-----------------------------------------------------------------------

// Libraries #include #include using namespace std;

// DO_2: Define the constants NEGATIVE_RESULT and WIDTH

// Funtion Prototypes int SumOfSquares(int num1, int num2);

// DO_3: Complete the prototype for SquareOfSum function. // See function definition below.

void DisplayResults(int result, int num1, int num2);

int main() { int number1, number2, result;

// Priming Read of While Loop cout << "Enter two numbers: ";

// DO_4: Provide the priming read for the Sentinel Control Loop // Look at the while statement below for details on what is // necessary.

cout << endl; // Loop until either of the numbers is negative // DO_5: Complete the halting condition for this sentinel control // loop.

while ()

{ // Decide which computation is needed

if (number1 > number2) // Condition #1 { result = SumOfSquares(number2, number1); }

else if (number1 == number2) // Condition #2 { result = number1 * number2; }

else // Condition #3 { // DO_6: Make a call to SquareOfSum passing in the number1 // and number2 and storing the return from the call in // result. Look at the function prototype for // requirements of the call.

}

// Display the results of the computations

DisplayResults(result, number1, number2);

// Get the next pair of numbers;

cout << "Enter two numbers: "; cin >> number1 >> number2; cout << endl; } // END OF WHILE LOOP

// DO_7: Make a call to the function that will display the output for // case 4 (see comments at the top of the file). Look at the // function prototype for requirements of which constant and // variables will need to be passed into the function.

return 0; } // END OF main FUNCTION

//--------------------------------------------------------------------- // Function calculates and returns the sum of squares of the numbers // from num1 to num2 (inclusive). // params: (in, in) //--------------------------------------------------------------------- // DO_8: Complete the function definition for SumOfSquares. // Check the function prototype for details on this function.

{ int sumOfSquares = 0; while (num1 <= num2) { sumOfSquares += num1 * num1; num1++; } return sumOfSquares; } // END OF SumOfSquares FUNCTION

//--------------------------------------------------------------------- // Function calculates and returns the square of the sum of the numbers // from num1 to num2 (inclusive). // params: (in, in) //--------------------------------------------------------------------- int SquareOfSum(int num1, int num2) {

// DO_9: Complete the body of the SquareOfSum function. This function // sums the numbers between num1 and num2 (inclusive) and then // returns the square of the sum.

} // END OF SquareOfSumFUNCTION

//--------------------------------------------------------------------- // Function to display the inputs and the results // params: (in, in, in) //--------------------------------------------------------------------- void DisplayResults(int result, int num1, int num2) { // DO_10: Display the two numbers and the result. // Set the width for each output according to the // sample run in Lab6.tx6

return; } // END OF DisplayResults FUNCTION

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

2. Outline the functions of nonverbal communication

Answered: 1 week ago