//C++面向物件的二次方程求根,能繪出函式圖
#include <iostream>
#include <cmath>
#include <windows.h>
using namespace std;
class equation
{
float a, b, c, x1, x2, delta;
void value();
public:
equation(float aa, float bb, float cc);
void show();
};
equation::equation(float aa, float bb, float cc)
{
while (fabs(aa) < 1e-6 && fabs(bb) < 1e-6) {
cout << "方程的系數 a b c有錯誤,\n";
cout << "請重新輸入a,b,c的值:";
cin >> aa >> bb >> cc;
}
a = aa; b = bb; c = cc;
}
void equation::value()
{
delta = b * b - 4 * a * c;
if (delta >= 0) {
x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
}
}
void equation::show()
{
if (a != 0) {
value();
if (delta > 0) {
cout << "有兩個不相等的實根,分別是:";
cout << "x1=" << x1 << ", ""x2=" << x2 << endl;
} else {
if (delta == 0)
cout << "有兩個相等的實根,x1=x2=" << x1 << endl;
else cout << "方程無實根。" << endl;
}
} else if (b != 0)
cout << "方程的根是"
<< "x=" << -c / b << endl;
}
int main()
{
equation A(1, 2, -15), B(1, 7, 0);
A.show();
B.draw();
getchar();
return 0;
}
出現了這個error
uj5u.com熱心網友回復:
B.show();轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/53501.html
標籤:基礎類
下一篇:求大神指點
