Assignment G

Chapter 5


Problem G1

The equation ax² +bx + c in problem F1 has 6 cases, that can occur with various values for a, b, and c. The 6 cases are:

1) When a, b, and c are all zero, any x is a solution. Print that message.

2) When a and b are zero and c is not, no solution exists. Print that message.

3) When a is zero and b is not zero, the only solution is x = -c/b.

If it is not one of the first three cases, then it is one of the remaining cases.

The remaining three cases are determined by the value of the determinant expression b2-4ac.

4) When b2-4ac is zero, the only solution is x = -b/2a.

5) When b2-4ac is positive, two solutions are given by the equations in problem F1.

6) When b2-4ac is negative, the solutions have a real and an imaginary component, as shown in the following mathematical equations:

The real component is

xR = -b/2a

The imaginary component is

      _____________
xI = - ( b2 -4ac ) / 2a

After computing the real and imaginary components, print the values of xR and xI in the following format.

Print the text shown here, but with the numeric values substituted for xR and xI

The two solutions are

X1 = xR + i xI and X2 = xR - i xI

where i is the square root of -1.


For example, if your results were 98.765 for xR and 0.123 for xI, your program should print:

The two solutions are

X1 = 98.765 + i 0.123 and X2 = 98.765 - i 0.123
where i is the square root of -1.



Try to use the most efficient method of selecting among the six cases.


Test it 7 times:

a = 0 b = 0 c = 0

a = 0 b = 0 c = 3

a = 0 b = 4 c = -5

a = 4 b = 4 c = 1

a = 2 b = 8 c = 8

a = 100 b=100 c= -11

a = 1 b = 1 c = 1

Check your results by hand, by substituting your results back into the equation and verify that they are roots


Problem G2

Write a program that determines a student's letter grade. Allow the user to enter three test scores. The maximum score on each test is 100 points. Determine the letter grade from the average of the test scores, using the following chart:

90% or more A

80% or more, but less than 90% B

70% or more, but less than 80% C

60% or more, but less than 70% D or F, to be determined from additional information

less than 60% F

Only if the grade needs to be determined between D and F, allow the user to enter the number of homework assignments the student turned in, and the total number of homework assignments. If more than 90% of the homework assignments were turned in, the letter grade is D, otherwise F.

Test it 4 times:

95 84 90

44 35 29

80 69 60 with 12 homework out of 13 turned in

85 69 55 with 8 homework out of 9 turned in

Compute the results by hand and check your results