Need help with a simple C++ assignment

Sep 9th, 2015
FratBro23
Category:
Computer Science
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;
  }
  else
  { // 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;
  }
  }
  else
  if (!cin.eof())
  cout << " One or more invalid inputs";
  cout << endl;
  return EXIT_SUCCESS;
}

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Cornell University
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
ddg82
Dec 7th, 2016
" Thanks, good work "
tinytim47
Nov 24th, 2016
" Wow this is really good.... didn't expect it. Sweet!!!! "
kenmwao2
Nov 24th, 2016
" Solid work, thanks. "
jestin7
Nov 15th, 2016
" This tutor is great! "
lilmoe415
Nov 1st, 2016
" Thank you, Thank you, for top quality work, this is your guy!! "
dontuwannaknow
Oct 10th, 2016
" Excellent work as always thanks so much "
thargrow
Oct 1st, 2016
" Very Satisfied. "
SjSurvivor143
Sep 26th, 2016
" Thanks for the help. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1823 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