#include "NumType.h"
#include <string>
using namespace std;
class equas
{
public:
static int iEquas;
void set(int iPnt,nums nA);
nums get(int iPnt);
void display();
friend equas operator + (equas nA,equas nB);
friend equas operator + (equas nA,nums nB);
friend equas operator - (equas nA,equas nB);
friend equas operator - (equas nA,nums nB);
friend equas operator * (equas nA,equas nB);
friend equas operator * (equas nA,nums nB);
friend equas operator / (equas nA,equas nB);
friend equas operator / (equas nA,nums nB);
private:
nums aArr[equas::iEquas+1];
};
int equas::iEquas=1;
void equas::set(int iPnt,nums nA)
{
aArr[iPnt]=nA;
}
nums equas::get(int iPnt)
{
return aArr[iPnt];
}
void equas::display()
{
int iI;
for (iI=0;iI<=equas::iEquas;iI++)
{
cout<<iI<<":";
aArr[iI].display();
cout<<"___";
}
}
equas operator + (equas nA,equas nB)
{
equas nC;
int iI;
for(iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]+nB.aArr[iI];
}
return nC;
}
equas operator + (equas nA,nums nB)
{
equas nC;
int iI;
for(iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]+nB;
}
return nC;
}
equas operator - (equas nA,equas nB)
{
equas nC;
int iI;
for(iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]-nB.aArr[iI];
}
return nC;
}
equas operator - (equas nA,nums nB)
{
equas nC;
int iI;
for(iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]-nB;
}
return nC;
}
equas operator * (equas nA,equas nB)
{
equas nC;
int iI,iJ=0;
for (iI=1;iI<=equas::iEquas;iI++)
{
if (nA.aArr[iI].return_Up()!=0)
{
iJ=1;
}
}
if (iJ==1)
{
for (iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]*nB.aArr[0];
}
return nC;
}
else
{
for (iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[0]*nB.aArr[iI];
}
return nC;
}
}
equas operator * (equas nA,nums nB)
{
equas nC;
int iI;
for (iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]*nB;
}
return nC;
}
equas operator / (equas nA,nums nB)
{
equas nC;
int iI;
for (iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]/nB;
}
return nC;
}
equas operator / (equas nA,equas nB)
{
equas nC;
int iI;
for (iI=0;iI<=equas::iEquas;iI++)
{
nC.aArr[iI]=nA.aArr[iI]/nB.aArr[0];
}
return nC;
}
表达式计算之四:方程的数据结构
最新推荐文章于 2022-08-10 21:16:06 发布