#include <iostream>
using namespace std;
char x;
int n;
class CEquation
{
private:
double a;
double b;
char unknow;
public:
CEquation(double aa = 0, double bb = 0);
friend istream & operator >> (istream &in, CEquation &e);
friend ostream & operator << (ostream &out, CEquation &e);
double Solve();
char getUnknown();
};
int main()
{
CEquation e;
cout << "请输入一元一次方程(输入格式: 3x-8=0): ";
cin >> e;
cout << "方程为: " << e;
cout << "方程的解为: " << e.getUnknown() << "=" << e.Solve() << endl;
system("pause");
return 0;
}
CEquation::CEquation(double aa, double bb)
{
a = aa;
b = bb;
}
istream & operator >> (istream &in, CEquation &e)
{
in >> e.a >> e.unknow >> e.b >> x >> n;
return in;
}
ostream & operator << (ostream &out, CEquation &e)
{
if(e.b > 0)
{
out << e.a << e.unknow << "+" << e.b << x << n;
out << endl;
}
else
{
out << e.a << e.unknow << e.b << x << n;
out << endl;
}
return out;
}
double CEquation::Solve()
{
double Solve;
Solve = - b / a;
return Solve;
}
char CEquation::getUnknown()
{
return unknow;
}