ВОПРОС · Q&A

Работа с файлами в паскале

25 ответов 12,1 тыс.
sax_ol
прав, конечно =)

Добавлено: вместо for i:=1 to 17 do begin
что-то типа такого:
while not EOF(ft) do begin
ну, это было написано после 12 ночи =) посыпаю голову пеплом)
 
1 часть Марлезонского балета:

Код:
program lab14;
uses crt;
type Stud = record
Name,Group: String[100];
Data: Byte;
Gender: Char;
Teormeh1,Mathematica1,Phisics,Geometry:Byte;
Teormeh2,Mathematica2,Sopromat:Byte;
end;
var i: Integer;
Student:Stud;
ft: file of Stud;
begin
clrscr;
writeln;
assign(ft,'stud.txt');
rewrite(ft);
for i:=1 to 2 do
begin
textcolor(14);
write(i);
textcolor(white);
write(' ФИО студента:	');
readln(Student.Name);
write(' Группа:			 ');
readln(Student.Group);
write(' Дата рождения: ');
readln(Student.Data);
write(' Пол студента:	');
readln(Student.Gender);
writeln(' Оценки за первую сессию:');
write('	 Физика:							 ');
readln(Student.Phisics);
write('	 Математика:					  ');
readln(Student.Mathematica1);
write('	 Теоретическая механика:  ');
readln(Student.Teormeh1);
write('	 Начертательная геометрия: ');
readln(Student.Geometry);
writeln(' Оценки за вторую сессию:');
write('	 Математика:						');
readln(Student.Mathematica2); 
write('	 Теоретическая механика:	');
readln(Student.Teormeh2);
write('	 Сопротивление материалов: ');
readln(Student.Sopromat);
writeln;
write(ft,Student);
end;
close(ft);
end.

2 часть Марлезонского балета:

Код:
program lab14;
uses crt;
type Stud = record
Name,Group: String[100];
Data: Byte;
Gender: Char;
Teormeh1,Mathematica1,Phisics,Geometry:Byte;
Teormeh2,Mathematica2,Sopromat:Byte;
end;
var Student:Stud;
ft: file of Stud;
i,mat0,mat,phys0,phys,meh0,meh,geom0,geom,porivn1,porivn2,predmet:byte;
begin
clrscr;
writeln;
assign(ft,'stud.txt');
mat0:=0;
phys0:=0;
meh0:=0;
geom:=0;
for i:=1 to 2 do begin
read(ft,Student);
phys:=Student.Phisics;
phys0:=phys0+phys;
mat:=Student.Mathematica1;
mat0:=mat0+mat;
meh:=Student.Teormeh1;
meh0:=meh0+meh;
geom:=Student.Geometry;
geom0:=geom0+geom;
end;
if (mat0>phys0) then porivn1:=mat0
else porivn1:=phys0;
if (meh0>geom0) then porivn2:=meh0
else porivn2:=geom0;
if (porivn1>porivn2) then predmet:=porivn1
else predmet:=porivn2;
if (predmet=phys0) then writeln ('Физика');
if (predmet=mat0) then writeln ('Математика');
if (predmet=meh0) then writeln ('Механика');
if (predmet=geom0) then writeln ('Графика');
readkey;
close(ft);
end.
 
nicht arbeitet.

Error 103. File not open
 
my brain go sleep :flood:

Код:
reset(ft)
 
так вроде должно быть)))
assign(ft,'stud.txt');
Reset(ft);

Добавлено: и дальше
while not EOF(ft) do begin // for - не надо
...
end;
 
спс всем