Question: // why is this not working? #include #include #include #include #include #include using namespace std; double a, b, c; void printline(ofstream &outf, char ch, int
// why is this not working?
#include
#include
#include
#include
#include
#include
using namespace std;
double a, b, c;
void printline(ofstream &outf, char ch, int num)
{
int i;
for (i = 1; i
}
double getd()
{
double d = pow(b, 2) - (4 * a*c);
return d;
}
double findoneroot()
{
double r = 0.0;
r = -b / (2 * a);
return r;
}
void findtworoots()
{
double r1 = 0.0, r2 = 0.0;
r1 = (-b + sqrt(pow(b, 2) - (4 * a*c))) / (2 * a);
r2 = (-b - sqrt(pow(b, 2) - (4 * a*c))) / (2 * a);
outf
}
void printtitles(ofstream &outf)
{
outf
outf
printline(outf, '=', linelen);
outf
}
void main()
{
string name;
ifstream inf;
ofstream outf;
inf.open("1.dat");
outf.open("2.ot");
printtitles(outf);
{
istringstream inputline(input);
inputline >> a >> b >> c;
if (getd() == 0)
{
r = findoneroot();
outf
}
else if (getd() > 0)
findtworoots();
else
outf
}
printline(outf, '=', linelen);
outf
}
Computer Science I Program #3 Due October 4, 2018 This program will find the roots of a series of quadratic equations using functions provided by C++ and some written by us. The functions will include the use of both void functions and return value functions. Read in three coefficients A, B, and C (all type double) which are the coecients of x2, x and the constant from a quadratic equation. Call a return-value function called getd, which will return the value of the determinant for this equation. Based on the value of the determinant the program will call one of the following functions: findoneroot - a returm value function which will find the single real root (with multiplicity of two) findtworoots-Since there are two return values, you must use a void function and pass the results through the parameter list!! The program will then output either the two real roots or it will print a message that there are no real roots. Note that in findone and findtwo, use the pow function supplied by C++ to find the square roots necessary Note that you should use a while loop to read the data from the data file. Note - use a void furnction called printtitles, where you will print the overall and column Note- Print out A, B, and C with a precision of two and the roots should have a precision of The output should look something like this: The Roots of Quadratic Equations D Root 1 1.00-4.00 4.00 0.00 2.0000 2.0000 1.00-2.00 -3.00 16.00 3.0000 1.0000 1.00 0.00 1.00 4.00 There are No Real Roots* Sample Data: -5 45 18 57 4.5 5 21 0.5 3.5 2.25 1.0 2.76 1.333 -5.11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
