|
|
Здесь выложен исходный код калькулятора для мобильника(JAVA) и простенькой программы на Delphi.
Также приведены ссылки на файлы проектов.
Исходный код калькулятора для мобильника:
MatrixCalc.java
Matrix.java
0)
if ( s.charAt(s.length()-1)!= '\n') s+= '\n';
int c = 0;
int k = s.indexOf('\n');
while( k!=-1 ) {
c++;
k = s.indexOf('\n',k+1);
}
this.rows = c;
c = 1;
k = s.indexOf('\n');
int x = s.indexOf(' ');
while( x!=-1 && x j
Fraction t;
for(int k=0;k j
Fraction t;
for(int k=0;k
Fraction.java
0 && b>0) ) return a+b; // b=0 is error value ?
int t;
while ( b>0 ) {
t = a % b;
a = b;
b = t;
}
return a;
}
Fraction() {
this.n = 0;
this.d = 1;
}
Fraction(int n) {
this.n = n;
this.d = 1;
}
Fraction(int n,int d) {
if(d==0) {
this.d = 1;
this.n = 999999999;
// return null; //Error!
}
if(n==0)
d=1;
if(d<0) {
n = -n;
d = -d;
}
int g = gcd(n,d);
this.n = n/g;
this.d = d/g;
}
Fraction(Fraction f) {
this.n = f.n;
this.d = f.d;
}
Fraction(String s) {// "321/12"
int i = s.indexOf('/');
int nn, dd;
if(i!=-1){
nn = Integer.parseInt(s.substring(0,i));
dd = Integer.parseInt(s.substring(i+1));
}else{
nn = Integer.parseInt(s);
dd = 1;
}
n= nn;
d= dd;
if(d==0) {
this.d = 1;
this.n = 999999999;
// return null; //Error!
}
if(n==0)
d=1;
if(d<0) {
n = -n;
d = -d;
}
int g = gcd(n,d);
this.n = n/g;
this.d = d/g;
}
public String toString() {
return ""+this.n + (this.d!=1?"/"+this.d:"");
}
int cmp(Fraction f) {
return (this.n*f.d - this.d*f.n);
}
int cmp(int n) {
return (this.n - this.d*n);
}
Fraction times(int n) {
return new Fraction( this.n*n, this.d );
}
Fraction times(Fraction f) {
return new Fraction( this.n*f.n, this.d*f.d );
}
Fraction divide(int n) {
return new Fraction( this.n, this.d*n );
}
Fraction divide(Fraction f) {
return new Fraction( this.n*f.d, this.d*f.n );
}
Fraction plus(int n) {
return new Fraction( this.n+n*this.d, this.d );
}
Fraction plus(Fraction f) {
return new Fraction( this.n*f.d + this.d*f.n, this.d*f.d );
}
Fraction minus(int n) {
return new Fraction( this.n-n*this.d, this.d );
}
Fraction minus(Fraction f) {
return new Fraction( this.n*f.d - this.d*f.n, this.d*f.d );
}
Fraction minus() {
return new Fraction( -this.n, this.d);
}
Fraction abs() {
return new Fraction( (this.n>0?this.n:-this.n) , this.d );
}
Fraction getcopy() {
return new Fraction(this);
}
}
// tests
// f=new Fraction(1,-2);
// alert(f);
// g=new Fraction(1,3);
// alert(g.plus(f));
]]>
Исходный код на Delphi
Файл unit1.pas
i) then ii:= i1-1
else ii:= i1;
if (j1>j) then jj:= j1-1
else jj:= j1;
m1.a[ii,jj] := m.a[i1,j1];
end;
result:= Opred(m1);
end;
function AlgebrDopoln(var m: mMatrix; i,j: integer): integer;
begin
result:= round(power(-1,i+j)) * MinorIJ(m,i,j);
end;
function Opred(m: mMatrix): integer; // m = n
var
i,j: integer;
begin
if m.m = 1 then
begin
result:= m.a[1,1];
exit;
end;
result:= 0;
for i:= 1 to m.m do
inc(result, m.a[i,1] * AlgebrDopoln(m,i,1));
end;
procedure AmB(var m1,m2,z: mMatrix); // m1.n = m2.m
var i,j,k: integer;
begin
z.m := m1.m;
z.n := m2.n;
for i:= 1 to m1.m do
for j:= 1 to m2.n do
begin
z.a[i,j]:= 0;
for k:= 1 to m1.n do
inc(z.a[i,j],m1.a[i,k]*m2.a[k,j]);
end;
end;
function Obr(var m1,z: mMatrix): integer; // m1.n = m2.m
var i,j,k: integer;
begin
z.m := m1.m;
z.n := m1.n;
for i:= 1 to m1.m do
for j:= 1 to m1.n do
z.a[i,j]:= AlgebrDopoln(m1,j,i);
result:= Opred(m1);
end;
///////////////////
procedure TForm1.LoadMatrix(var m: mMatrix);
var
i,j: integer;
begin
m.n:= -1;
while StringGrid1.Cells[m.n+1,0] <> '' do
inc(m.n);
inc(m.n);
m.m:= -1;
while StringGrid1.Cells[0,m.m+1] <> '' do
inc(m.m);
inc(m.m);
for i:= 1 to m.m do
for j:= 1 to m.n do
m.a[i,j]:= StrToInt(StringGrid1.Cells[j-1,i-1]);
end;
procedure TForm1.LoadMatrix2(var m: mMatrix);
var
i,j: integer;
begin
m.n:= -1;
while StringGrid2.Cells[m.n+1,0] <> '' do
inc(m.n);
inc(m.n);
m.m:= -1;
while StringGrid2.Cells[0,m.m+1] <> '' do
inc(m.m);
inc(m.m);
for i:= 1 to m.m do
for j:= 1 to m.n do
m.a[i,j]:= StrToInt(StringGrid2.Cells[j-1,i-1]);
end;
procedure TForm1.ShowResultMatrix(var m: mMatrix);
var
i,j: integer;
begin
for i:= 0 to ResultGrid.RowCount-1 do
for j:= 0 to ResultGrid.ColCount-1 do
ResultGrid.Cells[i,j]:= '';
for i:= 1 to m.m do
for j:= 1 to m.n do
ResultGrid.Cells[j-1,i-1]:= IntToStr(m.a[i,j]);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
m: mMatrix;
begin
LoadMatrix(m);
Label4.Caption:= IntToStr( Opred(m) );
ShowResultMatrix(m);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
z,m,m2: mMatrix;
begin
LoadMatrix(m);
LoadMatrix2(m2);
AmB(m,m2,z);
ShowResultMatrix(z);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
z,m: mMatrix;
begin
LoadMatrix(m);
Label4.Caption:= IntToStr( Obr(m,z) );
ShowResultMatrix(z);
end;
end.
]]>
MatrixCalc.zip - программа для JAVA ME полностью
Matrix.zip - программа на Delphi полностью
|