Zdravim mám podobný problém s úkolemv delphi, který zní:
Vytvořte aplikaci, která ze zadané matice A typu MxN vytvoří matici B tak, že se prvky na hlavní diagonále změní na nuly. Matice A se načte ze souboru nebo se vytvoří v aplikaci. Výsledná matice B se zobrazí v aplikaci a bude možné ji pak uložit do souboru. Matice mohou být libovolně velké.
Přesněji mám problém s indexováním, nemůžu se dostat k poslednímu řádku jakekoliv matice, zde je část programu, kterou jsem použil jako předlohu. Ještě mám problém s výstupem, ale ten vyřeším pomoci řetězce jak už tu bylo zmíněno.
procedure TForm1.Button2Click(Sender: TObject);
type MATICE = array of array of integer; {deklarace typu dynamicka matice}
var I,J,M,N,MN:integer; {promenne pro indexovani a velikosti matice}
A : MATICE; {dynamicke pole pro matici}
S : string;
B : array of integer; {dynamicke pole pro radkove soucty}
soubor : TextFile;
begin
AssignFile(soubor,'matice1.txt'); {budeme zjistovat velikost vstupni matice}
Reset(soubor);
MN:=-1; N:=-1; {inicializujeme pocitaci promenne}
while not(eof(soubor)) do {dokud jsme neprecetli posledni udaj budeme cist znovu}
begin
read(soubor,I); MN:=MN+1;{zapamatujeme si precteni}
if eoln(soubor)and(N=-1) then N:=MN+1; {testujeme zdali jsme nakonci 1. radku}
end;
M:=MN div N; {vypocitame pocet radku, div je celociselne deleni}
CloseFile(soubor);
SetLength(A,M,N); {alokace pameti pro dynamicka pole}
{Zbytek řeším, ale nedaří se :-D}
AssignFile(soubor,'maticipracuji.txt');
Reset(soubor);
for I:=1 to M do
for j:=1 to N do
read(soubor,A[I-1,J-1]);
A[0,0]:=0;A[1,1]:=0;
CloseFile(soubor);
AssignFile(soubor,'maticipracuji.txt'); Rewrite(soubor);
for I:=1 to M do for J:=1 to N do
begin
writeln(soubor,A[I-1,J-1]); {zapisujeme jednotlive prvky pole B do souboru}
end;
CloseFile(soubor);
POLE2.Lines.LoadFromFile('maticipracuji.txt');
Label3.Caption:='Počet řádků'+' '+inttostr(M+1);
Label4.Caption:='Počet sloupců'+' '+inttostr(N);
Label5.Caption:=pole2.text;
end;
Fórum › Delphi
úkol, v delphi poraďte prosím s úpravou matice

Tak jsem si prošel ten kód a problém je podle mě následující:
M:=MN div N;
Když jsem si to odkrokoval pro matici 3x3, dostal jsem na konci N = 3, MN = 8 a M = 8 div 3 = 2, což taky vysvětluje, proč zlobí poslední řádek

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 4 hosté
Podobná vlákna
Delphi matice úkol — založil Václav
Integral v Delphi - poraďte prosím :) — založil Pomeranc
Delphi - úkol — založil Kris
Prosím poraďte... — založil V. S.
Poradte mi prosím... — založil Majox