For all of these questions, you are not allowed to create your own functions in your solution. No credit will be given if this rule is violated.
We wish to solve equations of the form ax2 + bx + c = 0 where a, b, c are integers and a is non-zero.
We know that there are three possibilities for the roots; there are two distinct real roots, only one real root, or two distinct complex roots. Determine the correct case and display the roots for the quadratic equation.
-2 7 15
This represents the quadratic equation -2x2 + 7x + 15 = 0 which you are to solve.
Suppose that the text file quad1.txt contains:
-2 7 15
Then the sample run is:
$ ./lab4q1 There are two real roots. The real roots of (-2)x^2 + (7)x + (15) are: -1.500 and 5.000
Suppose that the text file quad1.txt now contains:
1 -2 1
Then the sample run is:
$ ./lab4q1 There is one real root. The real root of (1)x^2 + (-2)x + (1) is: 1.000
Suppose finally that the text file quad1.txt now contains:
1 3 3
Then the sample run is:
$ ./lab4q1 There are two complex roots. The complex roots to (1)x^2 + (3)x + (3) are: (-1.500) + (0.866)i and (-1.500) + (-0.866)i
In Question 1, clearly it is very inconvenient to have to edit the text file quad1.txt each time you want to solve a different quadratic equation. Could we put all the quadratic equations we wish to solve into a single file and get our program to solve all of them?
This question is identical to Question 1, except that:
Suppose that the text file quad2.txt contains:
-2 7 15 1 -2 1 1 3 3
Then the sample run is:
$ ./lab4q2 There are two real roots. The real roots of (-2)x^2 + (7)x + (15) are: -1.500 and 5.000 There is one real root. The real root of (1)x^2 + (-2)x + (1) is: 1.000 There are two complex roots. The complex roots to (1)x^2 + (3)x + (3) are: (-1.500) + (0.866)i and (-1.500) + (-0.866)i $
Note that the text file can contain many more lines (not just three), so your program must work for all text files.
A total of 18 different hosts have accessed this document in the last 444 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 5 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.