-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_three_term_polynomial.cpp
More file actions
60 lines (56 loc) · 1.63 KB
/
20_three_term_polynomial.cpp
File metadata and controls
60 lines (56 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*Fix the errors and get an error free compilation and execution.*/
#include<iostream>
#include<string>
#include<sstream>
#include <cmath>
int main()
{
int coeff1, coeff2, constant;
int exp1, exp2;
int y;
int x;
//Calculate the value of y for a user defined three term polynomial
//Get the coefficients, exponents, and the constants
std::cout<<"What is the first coefficient?";
std::cin>>coeff1;
std::cout<<coeff1<<"\n";
std::cout<<"What is the exponent of the first term?";
std::cin>>exp1;
std::cout<<exp1<<"\n";
std::cout<<"What is the second coefficient?";
std::cin>>coeff2;
std::cout<<coeff2<<"\n";
std::cout<<"What is the exponent of the second term?";
std::cin>>exp2;
std::cout<<exp2<<"\n";
std::cout<<"What is the constant?";
std::cin>>constant;
std::cout<<constant<<"\n";
//Print the complete equation
std::cout<<"The polynomial we are solving is:\n";
std::cout<<"\t"<<coeff1<<"*x^"<<exp1<<" + "<<coeff2<<"*x^"<<exp2<<"+ "<<constant;
std::cout<<"\nWhat is the value of x?";
std::cin>>x;
std::cout<<x<<"\n";
//Solve the equation with the given x
y = coeff1*pow(x,exp1) + coeff2*pow(x,exp2) + constant;
std::cout<<"y = "<<coeff1<<"*"<<x<<"^"<<exp1<<" + "<<coeff2<<"*"<<x<<"^"<<exp2<<"+ "<<constant<<" = "<<y;
return 0;
}
/*Answer
What is the first coefficient?1
1
What is the exponent of the first term?3
3
What is the second coefficient?2
2
What is the exponent of the second term?3
3
What is the constant?5
5
The polynomial we are solving is:
1*x^3 + 2*x^3+ 5
What is the value of x?45
45
y = 1*45^3 + 2*45^3+ 5 = 273379
*/