//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