?? my_realisation.cpp
字號:
//---------------------------------------------------------------------------
#include "My_Realisation.h"
//---------------------------------------------------------------------------
int Offset=0;
//---------------------------------------------------------------------------
Rational::Rational () {
p=0;
q=1;
sign=1;
Abbr ();
};
//---------------------------------------------------------------------------
Rational::Rational (long int x, long int y) {
p=x;
q=y;
Abbr ();
};
//---------------------------------------------------------------------------
long int Rational::NOD (long int x, long int y) {
long int ost=x%y;
while (ost!=0) {
x=y;
y=ost;
ost=x%y;
}
return y;
};
//---------------------------------------------------------------------------
void Rational::Print(int i, int j) {
if (q != 1) SimMeth->SimShow->Cells[j+2][i+2]=IntToStr(p)+"/"+IntToStr(q);
else SimMeth->SimShow->Cells[j+2][i+2]=p;
if ( (sign == -1) && (q !=1) ) SimMeth->SimShow->Cells[j+2][i+2]="-"+IntToStr(p)+"/"+IntToStr(q);
else if (sign == -1) SimMeth->SimShow->Cells[j+2][i+2]="-"+IntToStr(p);
};
//---------------------------------------------------------------------------
void Rational::Show() {
if (q != 1) ShowMessage(IntToStr(p)+"/"+IntToStr(q));
else ShowMessage(p);
if ( (sign == -1) && (q !=1) ) ShowMessage("-"+IntToStr(p)+"/"+IntToStr(q));
else if (sign == -1) ShowMessage("-"+IntToStr(p));
};
//---------------------------------------------------------------------------
void Rational::Abbr () {
sign = 1;
if (p<0) { p = -p; sign = -sign; }
if (q<0) { q = -q; sign = -sign; }
long int gcd = NOD (p, q);
p /= gcd;
q /= gcd;
};
//---------------------------------------------------------------------------
Rational operator - (Rational a, Rational b) {
long int pp = a.sign*a.p*b.q - b.sign*b.p*a.q;
long int qq = a.q*b.q;
Rational x (pp, qq);
return x;
};
//---------------------------------------------------------------------------
Rational operator + (Rational a, Rational b) {
long int pp = a.sign*a.p*b.q + b.sign*b.p*a.q;
long int qq = a.q*b.q;
Rational x (pp, qq);
return x;
};
//---------------------------------------------------------------------------
Rational operator * (Rational a, Rational b) {
int K = a.sign*b.sign;
long int pp = K*(a.p*b.p);
long int qq = a.q*b.q;
Rational x (pp, qq);
return x;
};
//---------------------------------------------------------------------------
Rational Rational::inv () {
if (sign == -1) p=-p;
long int pp = q;
long int qq = p;
if (p=0) {pp=0; qq=1;}
Rational x (pp, qq);
return x;
};
//---------------------------------------------------------------------------
Rational operator / (Rational a, Rational b) {
return a*b.inv();
};
//---------------------------------------------------------------------------
bool Rational::operator < (Rational b) {
if (( sign * p * b.q) < (b.sign * b.p * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
bool Rational::operator > (Rational b) {
if (( sign * p * b.q) >(b.sign * b.p * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
bool Rational::operator == (Rational b) {
if (( sign * p * b.q) == (b.sign * b.p * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
bool Rational::operator == (long int b) {
if ( (sign * p) == (b * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
bool Rational::operator <= (long int b) {
if ( (sign * p) <= (b * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
bool Rational::operator != (Rational b) {
if (( sign * p * b.q) != (b.sign * b.p * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
bool Rational::operator != (long int b) {
if ( (sign * p) != (b * q) ) return true;
return false;
};
//---------------------------------------------------------------------------
Rational Rational::operator = (Rational R) {
sign = R.sign;
p = R.p;
q = R.q;
return (*this);
};
//---------------------------------------------------------------------------
SimReal::SimReal () {
SRx=0;
SRy=0;
};
//---------------------------------------------------------------------------
RazrElement::RazrElement () {
xPosition=0;
yPosition=0;
Element=Rational(0,1);
};
//---------------------------------------------------------------------------
void SimReal::GetValues (int x, int y) {
SRx=x;
SRy=y;
Field_1 = new Rational *[y+1];
for (int i=0; i<=y; i++) Field_1[i]=new Rational [x+1];
Field_2 = new Rational *[y+1];
for (int i=0; i<=y; i++) Field_2[i]=new Rational [x+1];
Z_Function = new Rational [x+1];
Sigma = new Rational [x+1];
Basis = new Rational [y+1];
for (int i=1; i<=y; i++) {
Rational x(-1,1);
Basis[i]=x;
}
for (int i=1; i<=y; i++)
for (int j=0; j<=x; j++) {
Rational x(StrToInt(SimMeth->SimShow->Cells[j+2][i+1]),1);
Field_1[i][j]=x;
}
for (int i=1; i<=x; i++) {
Rational x(StrToInt(SimMeth->SimShow->Cells[i+2][0]),1);
Z_Function[i]=x;
}
};
//---------------------------------------------------------------------------
void SimReal::FindBasis() {
int p;
for (int i=1; i<=SRx; i++) {
bool Ind_1 = false, Check = false;
for (int j=1; j<=SRy; j++) {
if ( !((Field_1[j][i] == 1) || (Field_1[j][i] == 0)) ) break;
if ( (Field_1[j][i] == 1) && (Ind_1) ) break;
if ( Field_1[j][i] == 1) { Ind_1 = true; p=j; }
if ( j == SRy) Check = true;
}
if (Check) {
Basis[p]=Z_Function[i];
Basis[p].Print(p-1+Offset,-2);
SimMeth->SimShow->Cells[1][p+1+Offset]="X"+IntToStr(i);
}
}
SimMeth->SimShow->RowCount+=1;
SimMeth->SimShow->Cells[0][SRy+2+Offset]="膩朦蜞:";
for (int i=1; i<=SRy; i++)
if (Basis[i] == -1) p=-1;
if (p==-1) ShowMessage ("拎玷
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -