标签:form 复试 mes for ++ 大学 高项 次方 math
1、建立一个角类,在这个类中重载减号运算符,并实现求出角度的正弦值的函数。
#include <iostream> #include <cmath> using namespace std; class angel { public: double x1, x2; double getangel() { return (x1 - x2) / 180 * 3.1415926927;//转为角度 } double getsin(void) { cout << sin(getangel()) << endl; } }; int main() { angel a; while(cin >> a.x1 >> a.x2) { a.getangel(); a.getsin(); } return 0; }
#include <iostream> #include <cmath> using namespace std; class anser { private: double a, b, c; public: anser (int x, int y, int z) { a = x; b = y; c = z; }; void show() { double x1, x2; if(a == 0) { x1 = -c / b; x2 = -c / b; cout << "x1 = x2 = " << x1 << endl; } else if((b * b - 4 * a * c) < 0) { cout << "No solution" << endl; } else { x1 = (-b + sqrt(b * b - 4 * a * c)) / 2 * a; x2 = (-b - sqrt(b * b - 4 * a * c)) / 2 * a; if(x1 == -0 || x2 == -0) { x1 = 0; x2 = 0; } cout << "x1 = " << x1 << " x2 = " << x2 << endl; } } }; int main() { double a, b, c; while(cin >> a >> b >> c) { anser ans(a, b, c); ans.show(); } return 0; }
#include <iostream> #include <cmath> #include <vector> using namespace std; class formula { public: vector<double> v; int n; double x; double fun(int n, int N, double x, vector<double> v) { if(n == 0) { return v[N]; } else { return fun(n - 1, N, x, v) * x + v[N-n]; } } void show(){ cout << fun(n, n, x, v) << endl; } }; int main() { int n; while (cin >> n) { vector<double> v(n + 1); double x; for(int i = 0; i <= n; i++) cin >> v[i]; cin >> x; formula f; f.n = n; f.v = v; f.x = x; f.show(); } return 0; }
PS: 这个类我是真的搞不懂,裂开~ 只能是照葫芦画瓢写一写,也不知道准不准确,希望复试不要遇到这种题。 T_T
标签:form 复试 mes for ++ 大学 高项 次方 math
原文地址:https://www.cnblogs.com/ache/p/12534927.html