Need help with a simple C++ assignment

Sep 9th, 2015
Price: $40 USD

Question description

The program below solves the Quadratic formula for real roots only, but it does not use C++ classes.  Please re-design and re-implement the program so that it uses C++ classes.

PLEASE ONLY GIVE ME THE SOURCE CODE, I DO NOT WANT A CPP FILE. Also I will run the program to make sure it works. Thank you so much!!

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;

int main () {
  double a, b, c, disc = 0;
  cout << "Please enter your three coefficients for your quadratic equation ";
  cin >> a >> b >> c;
  if (!cin.eof() && cin.good() && a != 0) {
  // system keyboard tests !cin.eof() and cin.good
  // test for eof from the keyboard and good input data in that order.  The !cin.eof()
  // test has to come first to check if the user wants to bail without completing his
  // data entry. If the test cin.good is put first, the control-z or control-b input
  // will be understood as an invalid input, which is an undesirable side-effect.
  // a != 0 is an application test which rejects a value which equals zero
  // application tests always follow system tests and never precede them.
  disc = b*b - 4*a*c;
  if (disc < 0)
  { cout << " No real roots"; }
  else if (disc == 0)
  { double root = -b/(2*a);
   if (root == 0) root = abs(root);
   cout << " One real root; x = " << root;
  { // show both roots
   double root1, root2;
   root1 = -b/(2*a) + sqrt (disc)/(2*a);
   root2 = -b/(2*a) - sqrt (disc)/(2*a);
   cout << " Two real roots; root1 = " << root1
    << " and root2 = " << root2;
  if (!cin.eof())
  cout << " One or more invalid inputs";
  cout << endl;
  return EXIT_SUCCESS;

Tutor Answer

(Top Tutor) Karim B
School: University of Maryland

Studypool has helped 1,244,100 students

Review from student
" Thanks, good work "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1821 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors