Your name goes here add a description of this program her


// Your name goes here
//
// add a description of this program here.

#include <iostream>
#include <cmath>

using namespace std;

int main() {

double a,b,c; // coefficeints of equation
double disc; // the discriminant
double r1,r2; // the two roots

cout << \" this program will compute and print the roots of a quadratic equation \ \";
cout << \" ax^2 + bx + c = 0 \ \";
cout << \" the user will be prompted for the 3 coefficients \ \ \ \";


//computer input
cout << \" The value of a is: \";
cin >> a;
cout << \" The Value of b is: \";
cin >> b;
cout << \" The Value of c is: \";
cin >> c;


// computations

disc = b*b - 4*a*c; // the discriminant

if (disc > 0) { // real root case
r1 = (-b + sqrt(disc)) / (2 * a); // root #1
r2 = (-b - sqrt(disc)) / (2 * a);
}
else if (disc == 0) {
r1 = -b / (2 * a);
cout << \" The double root is: \" << r1 << endl;
}
// to do: add a nested if-else section here to handle the two cases:
// 1) one double root
// 2) two real roots
// you should be able to re-use the code below

r1 = (-b + sqrt( disc ) )/ (2*a); // root #1
r2 = (-b - sqrt( disc ) )/ (2*a); // root #2

cout << \" the roots of the equation are: \ \";
cout << \" r1 \" << r1 << endl;
cout << \" r2 \" << r2 << endl;

}
else {
if (disc <= 0)
r1 = (-b + sqrt(disc)) / (2 * a);
// to do: add code to correctly compute and print the two imaginary roots
cout << \" there are no real roots for this equation \ \" << r1 << endl;
}

return 0;
}
// Your name goes here
//
// add a description of this program here.

#include <iostream>
#include <cmath>

using namespace std;

int main() {

double a,b,c; // coefficeints of equation
double disc; // the discriminant
double r1,r2; // the two roots

cout << \" this program will compute and print the roots of a quadratic equation \ \";
cout << \" ax^2 + bx + c = 0 \ \";
cout << \" the user will be prompted for the 3 coefficients \ \ \ \";


//computer input
cout << \" The value of a is: \";
cin >> a;
cout << \" The Value of b is: \";
cin >> b;
cout << \" The Value of c is: \";
cin >> c;


// computations

disc = b*b - 4*a*c; // the discriminant

if (disc > 0) { // real root case
r1 = (-b + sqrt(disc)) / (2 * a); // root #1
r2 = (-b - sqrt(disc)) / (2 * a);
}
else if (disc == 0) {
r1 = -b / (2 * a);
cout << \" The double root is: \" << r1 << endl;
}
// to do: add a nested if-else section here to handle the two cases:
// 1) one double root
// 2) two real roots
// you should be able to re-use the code below

r1 = (-b + sqrt( disc ) )/ (2*a); // root #1
r2 = (-b - sqrt( disc ) )/ (2*a); // root #2

cout << \" the roots of the equation are: \ \";
cout << \" r1 \" << r1 << endl;
cout << \" r2 \" << r2 << endl;

}
else {
if (disc <= 0)
r1 = (-b + sqrt(disc)) / (2 * a);
// to do: add code to correctly compute and print the two imaginary roots
cout << \" there are no real roots for this equation \ \" << r1 << endl;
}

return 0;
}

A. of hard-coding them the coefficients of hard-coding them) (instead B. Correctly handle the two cases below. owi Case 1: two imaginary roots Case 2: one double root When your program is working correctly, run the program with 4 data sets and submit your code and output using the provided dropbox. Details: 1. Start Visual Studio and create a new project named Homework3. Select the Win32 option from the Visual C++ template, Win32 Console Application 2. Add a new file tPrejeet menu name the file quadratie.epp 3. In the application wizard screen, click the \"applications settings\" and select the \"Empty Project\" checkbox from the Additional options section. Click Finish. 4. From the project menu, select add new item. Choose the C++ file (.cpp), enter hw3.cpp as the name, then click Add. 5. Copy/Paste the code from the provided source file. 6. Run the program using the \"Start Without Debugging\" option from the DEBUG menu, using Data Set A and also Data Set B (below). You will need to edit the source file to set the coefficients to have these values. 7. Modify the program to allow the user to enter the coefficients from the keyboard. Include prompts so the user knows which values (a, b, or c) to enter. 8. Modify the program to handle the two cases: two imaginary roots. Hint: compute sart( -disc). Your output should look something like: r 1 -4 t 2.34 i 2.34 i \'pretty\' formatting is not a priority One double root. Hint: add an if else statement completely inside the first if statement which tests if the discriminant is 0. For this case, the output should something like: Updated 2/17

Solution

#include <iostream>
#include <cmath>

using namespace std;

int main() {

   double a,b,c; // coefficeints of equation
   double disc; // the discriminant
   double r1,r2; // the two roots
float realPart, imagPart;
   cout << \" this program will compute and print the roots of a quadratic equation \ \";
   cout << \" ax^2 + bx + c = 0 \ \";
   cout << \" the user will be prompted for the 3 coefficients \ \ \ \";


   //computer input
   cout << \" The value of a is: \";
   cin >> a;
   cout << \" The Value of b is: \";
   cin >> b;
   cout << \" The Value of c is: \";
   cin >> c;


// computations

   disc = b*b - 4*a*c; // the discriminant

   if (disc > 0) { // real root case
       r1 = (-b + sqrt(disc)) / (2 * a); // root #1
       r2 = (-b - sqrt(disc)) / (2 * a);
  
   cout << \"Roots are real and unique: \"<<r1 <<\" and \" <<r2 <<endl;
   }
   else if (disc == 0) {
       r1 = -b / (2 * a);
       cout << \" The double root is: \" << r1 << endl;
   }
          
   else
   {
   cout << \" there are no real roots for this equation \"<<endl;
   realPart = -b/(2*a);
imagPart =sqrt(-disc)/(2*a);
cout << \"r1 = \" << realPart << \" + \" << imagPart << \" i\" << endl;
cout << \"r2 = \" << realPart << \" - \" << imagPart << \" i\" << endl;
      
   }

   return 0;
}

 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double
 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double
 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double
 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site