Guest User

Untitled

a guest
Apr 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6.  
  7. void menu_print();
  8. void root_num(double a, double b, double c);
  9. void calc_root(double a, double b, double c);
  10. void point_x(double a, double b, double c, double x);
  11.  
  12.  
  13.  
  14. int main() {
  15.     menu_print();
  16. return 0;
  17. }
  18.  
  19.  
  20. void menu_print(){
  21.     double a, b, c, x;
  22.     int opt=1;
  23.  
  24.     cout << "Enter the three parameters of a*x^2+b*x+c = 0\n";
  25.     cout << "Enter a parameter: ";
  26.     cin >> a;
  27.     cout << "Enter b parameter: ";
  28.     cin >> b;
  29.     cout << "Enter c parameter: ";
  30.     cin >> c;
  31.  
  32.     while(opt != 0) {
  33.         cout << "0 - exit, 1 - roots, 2 - value at point x, 3- new equation\n";
  34.         cin >> opt;
  35.         if(opt == 0) {
  36.             cout << "Exit! Bye\n";
  37.             return;
  38.         }
  39.         if(opt == 1) { root_num(a, b, c); calc_root(a, b, c); }
  40.         if(opt == 2) {
  41.             cout << "Enter x value: ";
  42.             cin >> x;
  43.             point_x(a, b, c, x);
  44.         }
  45.         if(opt == 3) { menu_print(); }
  46.     }
  47. }
  48.  
  49.  
  50.  
  51. void root_num(double a, double b, double c){
  52.     double delta = (b*b)-(4*a*c);
  53.         if(delta<0)
  54.         {
  55.             cout<<"Equation doesn't have any roots."<<endl;
  56.             return;
  57.         }
  58.  
  59.         if(delta==0)
  60.         {
  61.             cout<<"The only root is: ";
  62.             return;
  63.         }
  64.  
  65.         if(delta>0)
  66.         {
  67.             cout<<"The two roots are: ";
  68.         }
  69. }
  70.  
  71. void calc_root(double a, double b, double c){
  72.     double x1, x2, delta;
  73.     delta = (b*b)-(4*a*c);
  74.     if (delta == 0) {
  75.         x1=-b/(2*a);
  76.         cout << setiosflags(ios::fixed) << setprecision(1);
  77.         cout << x1 << endl;
  78.     }
  79.     if (delta > 0){
  80.         x1=(-b+sqrt(delta))/(2*a);
  81.         x2=(-b-sqrt(delta))/(2*a);
  82.         cout << x1 << " " << x2 << endl;
  83.     }
  84. }
  85.  
  86. void point_x(double a, double b, double c, double x){
  87.     double sum;
  88.     sum = (a*(pow(x,2)))+(b*x)+c;
  89.     cout << "The result is " << sum << endl;
  90. }
Add Comment
Please, Sign In to add comment