Program lib;
uses crt;
type Books=record
number:integer;
fio:string;
group:string;
home:string;
year:integer;
end;
var
book_file:fileof books;
f:fileof books;
data:array[1..20] of books;
rec:books;
file_name:string;
key,key1:integer;
exit:boolean;
x:string;
procedure name_of_file;
begin
write('Vvedite fail bazi dannih studentov:');
readln(file_name);
end;
procedure add_record;
begin
writeln('Record N',filepos(book_file)+1);
with rec dobegin
write('FIO:');
readln(fio);
write('Group:');
readln(group);
write('Vozrast:');
readln(year);
write('Address:');
readln(home);
write(book_file,rec);
end;
end;
procedure sort; //Не могу реализовать ввод из rec в массив Data а метод сортировки проверен работает
var i,n,j:integer;
begin
name_of_file;
assign(book_file,file_name);
{$I-}
reset(book_file);
{$I+}if IOresult <> 0then
writeln('File with name '+file_name+' is not')
elsebegin
writeln;
while (not eof(book_file)) do
read(book_file,rec);
data[i]:=rec;
for i:=1to n-1dofor j:=1to n-i doif data[j].fio>data[j+1].fio thenbegin
rec := data[j];
data[j] := data[j+1];
data[j+1] := rec;
end;
with rec dobegin
readln(fio);
readln(group);
readln(year);
readln(home);
end;
volvo
10.12.2007 3:11
Так пробовал?
{ Открываешь файл ... }
n := 0;
while (not eof(book_file)) dobegin
read(book_file,rec);
inc(n);
data[n]:=rec;
end;
{ А дальше - сортировка }
Pirate
12.12.2007 0:58
Volvo спасибо незнаю бы что делал елси бы не ты,подставил твой код но одна проблемка если есть несколько слов допустим на букву 'S' то сортируется например так:
Alex Sergei Bob Coooo Ses
procedure sort;
var i,n,j:integer;
begin
name_of_file;
assign(book_file,file_name);
{$I-}
reset(book_file);
{$I+}if IOresult <> 0then
writeln('File with name '+file_name+' is not')
elsebegin
n:=0;
while (not eof(book_file)) dobegin
read(book_file,rec);
inc(n);
data[n]:=rec;
end;
for i:=1to n-1dofor j:=1to n-i doif data[j].fio>data[j+1].fio thenbegin
rec := data[j];
data[j] := data[j+1];
data[j+1] := rec;
end;
for i:=1to filesize(Book_file) do
writeln(data[i].fio);
end;
end;
volvo
12.12.2007 1:10
В файле точно все в порядке? Потому что небольшая тестовая программа сортирует эти самые значения прекрасно:
type
Books= record
number:integer;
fio:string;
group:string;
home:string;
year:integer;
end;
const
n = 5;
data: array[1 .. 5] of books = (
(number:0; fio:'Alex'; group:''; home:''; year:0),
(number:0; fio:'Sergey'; group:''; home:''; year:0),
(number:0; fio:'Bob'; group:''; home:''; year:0),
(number:0; fio:'Coooo'; group:''; home:''; year:0),
(number:0; fio:'Ses'; group:''; home:''; year:0)
);
var
i, j: integer;
rec: books;
beginfor i:=1to n-1dofor j:=1to n-i doif data[j].fio>data[j+1].fio thenbegin
rec := data[j];
data[j] := data[j+1];
data[j+1] := rec;
end;
for i:=1to n do
writeln(data[i].fio);
end.
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.