Question
2. Write the definition of a function that calculates the sum and average of the numbers in an interval. a. The preconditions are that the
2. Write the definition of a function that calculates the sum and average of the numbers in an interval. a. The preconditions are that the input to the function is two integer values and that the first number is less than the second number. i. Make sure to provide code inside the function that ensures the preconditions are met. For example, if the end points of the interval are passed in the wrong order, your code would need to adjust them. b. The postcondition is that the sum of the numbers in the interval and the average of the numbers in the interval is returned. Since a function can only return a single result, your function would be declared as a void function and the results would be returned through reference parameters that are declared in the caller. i. Notice that the postcondition does not say anything about displaying these values. The caller of the function decides what to do with the values after the function calculates them. c. In your program, provide the prototype for this function and comments documenting the preconditions and postconditions (either before or after the prototype). d. Place the function definition after the main function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started