Dzień dobry. Bardzo proszę o pomoc, gdyż kompletnie nie wiem o co chodzi. Za zadanie miałam zrobić program, który tworzy ciąg arytmetyczny, geometryczny oraz dowolny. W pierwszym załączniku wszystko działa. W drugim załączniku miałam zrobić dziedziczenie. Miał być główny ciąg i od niego powinien dziedziczyć ciąg arytmetyczny i geometryczny. Spróbowałam zrobić to dla przycisku 1, żeby generował dany ciąg, ale wychodzą mi kosmiczne wyniki. Zupełnie inne niż w 1 załączniku. Drugi przycisk generuje sumę, trzeci sumę ważoną, czwarty sumę ważoną ciągu a ostatnio ustala jaką pozycje ma dana wartość ciągu.
TCiag = class
public
function Napis:string;
function Pozycja(p:integer):integer;
function Suma:integer;
function SumaW(w1,w2,w3,w4:integer):integer;
function SumaWazC(c:TCiag):integer;
end;
TArytm = class(TCiag)
protected
Fa1,Fa2,Fa3,Fa4:integer;
public
constructor Create; overload;
function Napis:string; overload;
function Pozycja(p:integer):integer; overload;
function Suma:integer; overload;
function SumaW(w1,w2,w3,w4:integer):integer; overload;
function SumaWazC(c:TArytm):integer; overload;
end;
TGeom = class(TCiag)
protected
Fa1,Fa2,Fa3,Fa4:integer;
public
constructor Create; overload;
function Napis:string; overload;
function Pozycja(p:integer):integer; overload;
function Suma:integer; overload;
function SumaW(w1,w2,w3,w4:integer):integer; overload;
function SumaWazC(c:TGeom):integer; overload;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TCiag.Napis:string;
begin
end;
function TCiag.Pozycja(p:integer):integer;
begin
result:=0;
end;
function TCiag.Suma;
begin
result:=0;
end;
function TCiag.SumaW(w1,w2,w3,w4:integer):integer;
begin
result:=0;
end;
function TCiag.SumaWazC(c:TCiag):integer;
begin
result:=0;
end;
constructor TArytm.Create;
begin
Fa1:=0;
Fa2:=0;
Fa3:=0;
Fa4:=0;
end;
function TArytm.Napis:string;
var
a1,r:integer;
begin
Fa1:=a1;
Fa2:=a1+r;
Fa3:=a1+(2*r);
Fa4:=a1+(3*r);
result:=inttostr(Fa1)+','+inttostr(Fa2)+','+inttostr(Fa3)+','+inttostr(Fa4);
end;
function TArytm.Pozycja(p:integer):integer;
begin
if (p=Fa1) then result:=1
else
if (p=Fa2) then result:=2 else
if (p=Fa3) then result:=3 else
if (p=Fa4) then result:=4 else
result:=-1;
end;
function TArytm.Suma:integer;
begin
result:=Fa1+Fa2+Fa3+Fa4;
end;
function TArytm.SumaW(w1,w2,w3,w4:integer):integer;
begin
result:=Fa1*w1+Fa2*w2+Fa3*w3+Fa4*w4;
end;
function TArytm.SumaWazC(c:TArytm):integer;
begin
result:=Fa1*c.Fa1+Fa2*c.Fa2+Fa3*c.Fa3+Fa4*c.Fa4;
end;
constructor TGeom.Create;
begin
Fa1:=0;
Fa2:=0;
Fa3:=0;
Fa4:=0;
end;
function TGeom.Napis:string;
var
a1,g:integer;
begin
Fa1:=a1;
Fa2:=a1*g;
Fa3:=a1*g*g;
Fa4:=a1*g*g*g;
result:=inttostr(Fa1)+','+inttostr(Fa2)+','+inttostr(Fa3)+','+inttostr(Fa4);
end;
function TGeom.Pozycja(p:integer):integer;
begin
if (p=Fa1) then result:=1
else
if (p=Fa2) then result:=2 else
if (p=Fa3) then result:=3 else
if (p=Fa4) then result:=4 else
result:=-1;
end;
function TGeom.Suma:integer;
begin
result:=Fa1+Fa2+Fa3+Fa4;
end;
function TGeom.SumaW(w1,w2,w3,w4:integer):integer;
begin
result:=Fa1*w1+Fa2*w2+Fa3*w3+Fa4*w4;
end;
function TGeom.SumaWazC(c:TGeom):integer;
begin
result:=Fa1*c.Fa1+Fa2*c.Fa2+Fa3*c.Fa3+Fa4*c.Fa4;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a1,a2,a3,a4,r,g:integer;
a:TArytm;
gr:TGeom;
begin
memo1.Clear;
if (Radiogroup1.ItemIndex=0) then begin
try
a1:=strtoint(edit1.text);
except
raise exception.create('Nieprawidłowy pierwszy wyraz ciagu');
end;
try
r:=strtoint(edit2.text);
except
raise exception.create('Nieprawidłowa różnica ciągu');
end;
a:=TArytm.Create;
memo1.Text:=a.Napis;
a.free;
end;
if (Radiogroup1.ItemIndex=1) then begin
try
a1:=strtoint(edit1.Text);
except
raise exception.create('Nieprawidlowy pierwszy wyraz ciagu');
end;
try
g:=strtoint(edit2.Text);
except
raise exception.create('Nieprawidlowy iloraz');
end;
gr:=TGeom.Create;
memo1.Text:=gr.Napis;
gr.free;
end;
if (Radiogroup1.ItemIndex=2) then begin
end;
end;
dodanie znacznika <code class="delphi">
- @furious programming