Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: C++  |  size: 1.13 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Homework 7, question 3
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. void calculateQuadratic(double a, double b, double c, double &x1, double &x2)
  9. {
  10.      double value;
  11.      
  12.      value = b * b - 4. * a * c;
  13.      
  14.      if (value >= 0)
  15.      {
  16.                x1 = (b + value) / 2. * a;
  17.                x2 = (-b - value) / 2. * a;
  18.      }
  19.      else if (value < 0)
  20.      {
  21.                x1 = (b + value) / 2. * a;
  22.                x2 = (-b - value) / 2. * a;
  23.      } //for the imaginary part
  24. }
  25.  
  26. int main(int argc, char **argv)
  27. {
  28.     double a, b, c; //input
  29.     double x1, x2; // output
  30.     int i;
  31.    
  32.     if (argc == 1)
  33.     {
  34.              cout << "enter a: ";
  35.              cin >> a;
  36.              cout << endl;
  37.              cout << "enter b: ";
  38.              cin >> b;
  39.              cout << endl;
  40.              cout << "enter c: ";
  41.              cin >> c;
  42.     }
  43.    
  44.     if (argc == 4)
  45.     {
  46.              calculateQuadratic(atof(argv[1]), atof(argv[2]),
  47.                                 atof(argv[3]), x1, x2);
  48.     }
  49.    
  50.     if (argc == 5)
  51.     {
  52.     }
  53.    
  54.     system("pause");
  55.     return 0;
  56. }