Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include<cmath>
- using namespace std;
- void menu_print();
- void root_num(double a, double b, double c);
- void calc_root(double a, double b, double c);
- void point_x(double a, double b, double c, double x);
- int main() {
- menu_print();
- return 0;
- }
- void menu_print(){
- double a, b, c, x;
- int opt=1;
- cout << "Enter the three parameters of a*x^2+b*x+c = 0\n";
- cout << "Enter a parameter: ";
- cin >> a;
- cout << "Enter b parameter: ";
- cin >> b;
- cout << "Enter c parameter: ";
- cin >> c;
- while(opt != 0) {
- cout << "0 - exit, 1 - roots, 2 - value at point x, 3- new equation\n";
- cin >> opt;
- if(opt == 0) {
- cout << "Exit! Bye\n";
- return;
- }
- if(opt == 1) { root_num(a, b, c); calc_root(a, b, c); }
- if(opt == 2) {
- cout << "Enter x value: ";
- cin >> x;
- point_x(a, b, c, x);
- }
- if(opt == 3) { menu_print(); }
- }
- }
- void root_num(double a, double b, double c){
- double delta = (b*b)-(4*a*c);
- if(delta<0)
- {
- cout<<"Equation doesn't have any roots."<<endl;
- return;
- }
- if(delta==0)
- {
- cout<<"The only root is: ";
- return;
- }
- if(delta>0)
- {
- cout<<"The two roots are: ";
- }
- }
- void calc_root(double a, double b, double c){
- double x1, x2, delta;
- delta = (b*b)-(4*a*c);
- if (delta == 0) {
- x1=-b/(2*a);
- cout << setiosflags(ios::fixed) << setprecision(1);
- cout << x1 << endl;
- }
- if (delta > 0){
- x1=(-b+sqrt(delta))/(2*a);
- x2=(-b-sqrt(delta))/(2*a);
- cout << x1 << " " << x2 << endl;
- }
- }
- void point_x(double a, double b, double c, double x){
- double sum;
- sum = (a*(pow(x,2)))+(b*x)+c;
- cout << "The result is " << sum << endl;
- }
Add Comment
Please, Sign In to add comment