Assignment F
Chapter 4
Additional requirement:
In these problems, and all future problems, use functions. Provide a function prototype for each function before the main function. The function prototype should have descriptive names for the function and for each parameter. Put very little code in the main function. Each function should be preceded with a short comment giving:
- A long line of asterisks as an eye catcher
- The purpose of the function
- Parameters, other input, and initial conditions
- Return values, other results, and final conditions provided
Problem F1
The equation ax2 + bx + c = 0 may have two real numbers as solutions, for some values of a, b, and c. (Handout problem G1 discusses handling of the other cases, where other kinds of solutions are produced.) Write a program to input integer values for a, b and c, and produce output for the two real values of x that are solutions. Allow the user to enter the values of a, b, and c. Your program need only work for those cases where two real solutions are produced. Compute the solutions as floating point results with 2 decimal precision. The solutions are given by the following mathematical equations:
| _______ | _______ |
| x1 = ( -b + b2 -4ac ) / 2a and | x2 = ( -b - b2 -4ac ) / 2a |
Test it twice:
a = 2, b = 8, c = 8
a = 100, b = 100, c = -11
Do NOT use any other test data, because some test data will not work
(we will fix this later)
Check your results by hand, by substituting your results back into the equation and verifying that they are roots.
Problem F2
Write a program that has 4 functions. The main() function shall call the other three functions. The first function shall obtain the temperature from the user in degrees Fahrenheit. The second function shall convert the temperature in degrees Fahrenheit into degrees Rankine, degrees Celsius, and degrees Kelvin. The third function shall print the temperature for all four scales. Formulas for conversion are:
Fahrenheit to Celsius: C = ( F - 32 ) * 100 / 180
Fahrenheit to Rankine: R = ( F - 32 ) + 491.67
Celsius to Kelvin K = C
+ 273.16
where C, F, R, and K are corresponding temperatures for
the 4 scales.
Use a memory constant for every constant.
Print the result with a precision of one tenth of a degree.
Test it three times, with input:
-40F
32F
212F
Problem F3
Write a main function that calls five functions.
The five functions are: input, division, mean, power, print.
Write the input function to allow the user to input two integers.
Write the division function to provide both the quotient and the remainder, determined by dividing the first number by the second number.
Write a stub for the mean function; your mean function should accept two integer parameters, and return the integer 1; do not compute the mean.
Write a stub for the power function; your power function should accept two integer parameters, and return the integer 1; do not compute the power.
Write the print function to print the input values, the quotient, the remainder, the mean, and the power. Provide descriptive text identifying the six items in the printed output.
The idea of a stub is to allow you to write part of the program, and test it. You would go back later, and complete the code to make the stub functions into complete calculation functions. (Do not complete the mean and power functions in this assignment; just write them as stubs.)
Test it with the values:
17 5