$30
Quadratic Roots Program Requirements (C review)
Introduction
Some mathematical computations are extremely complex and time-consuming for a computer
to perform. Often, we resort to a look-up table instead, where outputs are pre-calculated and
stored in a file. Mathematical functions that fall into this category include trigonometric
functions (sine, cosine, tangent, etc.), roots, and logarithms.
Task
You are to create a program that computes the roots of the equation ax2 + bx + c = 0
using the Quadratic Formula:
𝑥 =
−𝑏 ± √𝑏
2 − 4𝑎𝑐
2𝑎
The program shall read lines containing 3 integers representing a, b, and c from an input text file
and writes the set and its corresponding floating-point roots to either an output text file or the
screen.
Requirements
1. The program will be done using Cygwin and gcc.
2. The input file will contain three integers per line, representing values for a, b, and c respectively.
Each line of the output file or screen shall contain the set of three integers followed by the two
floating-point roots, with all values separated by tabs. All floating-point values shall be printed
with 4 digits after the decimal point. If an input set generates complex roots, the output should
state “complex” rather than computing the roots.
3. All integers in the input file will be between -99 and 99. There is no limit to the size of the input
file.
4. The output file / screen must print the number sets in the same order as they appear in the
input file.
5. The program will expect either 1 or 2 command-line arguments to specify the names of the
input and output files. Example command-line input:
$ .\qr.exe input.txt output.txt
$ .\qr.exe input.txt
The output file argument is optional. If it does not appear, output shall be sent to the screen.
6. Malformed command-line syntax and/or failure to open input or output files shall result in an
error message and immediate program termination.
7. A makefile will be used and submitted.
8. Remember function headers and pseudocode!
Example Files
If the input file appeared like this:
1 20 3
2 -11 5
1 -5 6
3 6 3
4 5 6
1 4 4
The associated output file (or screen) should look like this:
1 20 3 -0.1511 -19.8489
2 -11 5 5.0000 0.5000
1 -5 6 3.0000 2.0000
3 6 3 -1.0000 -1.0000
4 5 6 complex
1 4 4 -2.0000 -2.0000
Think about different input scenarios and craft appropriate files to test those scenarios.