Question: THIS IS FOR C++ ONLY A quadratic equation is a polynomial equation of degree 2, commonly written in the form p(x) = ax 2 +
THIS IS FOR C++ ONLY A quadratic equation is a polynomial equation of degree 2, commonly written in the form p(x) = ax 2 + bx + c. Contents of coeffs.txt = a b c Contents of roots.txt = the equation ax^2+bx+c=0 has roots, root and root2 Contents of coeff.txt = 2.5 6.7 -3 And here is the pseudocode, function main () int define ifstream object named fin fin.open("coeffs.txt") a read_coef(fin) b read_coef(fin) c read_coef(fin) fin.close() root1 calc_root1(a, b, c) root2 calc_root2(a, b, c) output(a, b, c, root1, root2) return 0 end function main function read_coef (ifstream& fin) double define double variable coef read from fin into coef return coef end function read_coef function discriminant (double a, double b, double c) double return b 2 4ac end function discriminant function calc_root1 (double a, double b, double c) double return (b + discriminant(a, b, c)) (2a) end function calc_root1 function calc_root2 (double a, double b, double c) double return (b - discriminant(a, b, c)) (2a) end function calc_root2 function output (double a, double b, double c, double root1, double root2) void define ofstream object named fout fout.open("roots.txt") configure fout so real numbers are displayed in fixed notation with five digits after the decimal point send to fout "The equation ", a, "x^2 + ", b, "x + ", c, " = 0 has roots ", root1, " and ", root2 followed by newline fout.close() end function output ACTUAL PROGRAMMING CODE #include ??? // For sqrt() #include ??? // For ifstream and ofstream classes #include ??? // For setprecision() #include ??? // For cin, cout, fixed, and endl using namespace std; //------------------------------------------------------------------------------ // Implement read_coeff(). Make sure to specify that the parameter fin is // defined as ifstream& (we will discuss what the & means later in the course). //------------------------------------------------------------------------------ ??? //------------------------------------------------------------------------------ // Implement discriminant(). //------------------------------------------------------------------------------ ??? //------------------------------------------------------------------------------ // Implement calc_root1(). //------------------------------------------------------------------------------ ??? //------------------------------------------------------------------------------ // Implement calc_root2(). //------------------------------------------------------------------------------ ??? //------------------------------------------------------------------------------ // Implement output(). //------------------------------------------------------------------------------ ??? //------------------------------------------------------------------------------ // Implement main(). //----------------------------------------------------------------------------- ???
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
