#include<iostream>
#include<cmath>
#include<cstring>
#include<strstream>
#include<stdio.h>
#include<ctype.h>
using namespace std;
class xiang;
ostream &operator<<(ostream &os,xiang &t);
xiang operator+(const xiang &a,const xiang &b);
xiang operator-(const xiang &n,const xiang &m);
class xiang {
public:
float coef; //系数
int expn; //指数
friend ostream &operator<<(ostream &os,xiang &t);
friend xiang operator+(const xiang &a,const xiang &b);
friend xiang operator-(const xiang &n,const xiang &m);
};
ostream &operator<<(ostream &os,xiang &t) 重载输出
{
if(t.coef>0)
os<<t.coef<<"x^"<<t.expn;
else if(t.coef<0)
os<<t.coef<<"x^"<<t.expn;
else
os<<'0';
return os;
}
xiang operator+(const xiang &a,const xiang &b) //重载加法运算
{
xiang t;
if(a.expn==b.expn)
{
t.coef=a.coef+b.coef;
t.expn=a.expn;
}
return t;
}
xiang operator-(const xiang &n,const xiang &m) //重载减法运算
{
xiang t;
if(n.expn==m.expn)
{
t.coef=n.coef-m.coef;
t.expn=n.expn;
}
return t;
}
void f1()
{
cout<<"=============欢迎进行多项式运算============="<<endl;
cout<<"********************************************"<<endl;
cout<<"想进行加法运算,请输入'1'"<<endl;
cout<<"想进行减法运算,请输入'2'"<<endl;
cout<<"加法的带入求值,请输入'3'"<<endl;
#include<cmath>
#include<cstring>
#include<strstream>
#include<stdio.h>
#include<ctype.h>
using namespace std;
class xiang;
ostream &operator<<(ostream &os,xiang &t);
xiang operator+(const xiang &a,const xiang &b);
xiang operator-(const xiang &n,const xiang &m);
class xiang {
public:
float coef; //系数
int expn; //指数
friend ostream &operator<<(ostream &os,xiang &t);
friend xiang operator+(const xiang &a,const xiang &b);
friend xiang operator-(const xiang &n,const xiang &m);
};
ostream &operator<<(ostream &os,xiang &t) 重载输出
{
if(t.coef>0)
os<<t.coef<<"x^"<<t.expn;
else if(t.coef<0)
os<<t.coef<<"x^"<<t.expn;
else
os<<'0';
return os;
}
xiang operator+(const xiang &a,const xiang &b) //重载加法运算
{
xiang t;
if(a.expn==b.expn)
{
t.coef=a.coef+b.coef;
t.expn=a.expn;
}
return t;
}
xiang operator-(const xiang &n,const xiang &m) //重载减法运算
{
xiang t;
if(n.expn==m.expn)
{
t.coef=n.coef-m.coef;
t.expn=n.expn;
}
return t;
}
void f1()
{
cout<<"=============欢迎进行多项式运算============="<<endl;
cout<<"********************************************"<<endl;
cout<<"想进行加法运算,请输入'1'"<<endl;
cout<<"想进行减法运算,请输入'2'"<<endl;
cout<<"加法的带入求值,请输入'3'"<<endl;