Программы для работы с большим объемом информации, записанной в файлах
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
°йл создан);
end;;
// открытие файла
procedure OpenFile (var f: TFile; var FileName: string);
begin InputFileName (Введите имя существующего файла, FileName,true) then
begin
AssignFile (f, FileName);(Файл открыт);
end;;
// загрузка из файла
procedure LoadFromText (var f: TFile; var FileName: string);
var name: string; tf: TextFile; el: TCatalog; ok: Boolean;
begin InputFileName (Введите имя текстового файла, name,true) and(Введите имя типизированного файла, FileName, false)
then name=FileName then ShowMessage (Имена должны быть разными! )
else
AssignFile (tf,name);(tf);(f, FileName);(f);: =True;
while not Eof (tf) and ok do
if LoadCatalog (tf,el) then write (f,el) else ok: =False;(f);(tf);
if ok then ShowMessage (Данные загружены)
else ShowMessage (Ошибка при загрузке);
end;;
// печать файла
procedure PrintFile (var f: TFile);
var el: TCatalog; i: Integer;
begin
Reset (f);
if Eof (f) then ShowMessage (Файл пуст)
else
i: =0;
while not Eof (f) do
begin
read (f,el);(i);(Файл №, i);(el);
end;;
CloseFile (f);
end;
// сохранение в текстовый файл
procedure SaveToText (var f: TFile; FileName: string);
var name: string; tf: TextFile; el: TCatalog;
begin InputFileName (Введите имя текстового файла, name,false)
then name=FileName then ShowMessage (Имена должны быть разные! )
else
Reset (f);(tf, name);(tf);
while not Eof (f) do
begin
read (f,el);(tf,el);
end;
CloseFile (f);(tf);
ShowMessage (Текстовый файл создан);
end;
end;
// добавление элемента AddElems (var f: TFile);
var n: Integer;
begin
Reset (f);: =FileSize (f);(f,n);(f);(f);(Данные добавлены);
end;
// Выбор элемента
function SelectNum (var f: TFile; n: Integer; var num: Integer; var el: TCatalog): Boolean;
begin n=1 then num: =0
else
Writeln (Введите номер элемента);(num);
while (numn) do
begin
Writeln (Ошибка! Повторите ввод);
Readln (num);
end;
dec (num);
end;
Seek (f,num);(f,el);(el);: = InputQuery (Этот элемент? );
end;
// измненение элемента
procedure EditElems (var f: TFile);
var n,num: Integer; el: TCatalog;
begin
Reset (f);
if Eof (f) then ShowMessage (Файл пуст)
else SelectNum (f, FileSize (f), num,el)
then
EditCatalog (el);(f,num);(f,el);(Данные изменены);
end;
CloseFile (f);
end;
// удаление элемента
procedure DeleteElems (var f: TFile);
var num,n: Integer; el: TCatalog;
begin
Reset (f);: =FileSize (f);
if n=0 then ShowMessage (Файл пуст)
else SelectNum (f,n,num,el)
then n=1
then
CloseFile (f);(f);
end num=n-1
then
Seek (f, num);(f);
end
Seek (f,n-1);(f,el);(f,num);(f,el);(f,n-1);(f);
end;
ShowMessage (Данные удалены);
end;
CloseFile (f);
end;
// вывод файлов с заданной спецификацией
procedure Task (var f: TFile);
var el: TCatalog; name: string; ok: Boolean; fout: TFile; s: string [3];
begin
Reset (f);
if Eof (f) then ShowMessage (Файл пуст)
else InputFileName (Введите имя нового файла-отчета, name,False)
then
Writeln (Введите искомую спецификацию);
Readln (s);(fout, name);(fout);
while not Eof (f) do
begin
read (f,el);
if el. special=s
then
write (fout,el);: =True;
end;;
CloseFile (fout);
if ok
then
ShowMessage (Отчет сформирован);
if InputQuery (Напечатать отчет? ) then PrintFile (fout);
end
ShowMessage (Не найден ни один файл с заданной спецификацией);
endShowMessage (Прервано пользователем);(f);
end;. // UFile
Приложение 4. Главная программа
Program MainProgram; // главная программа
uses
SysUtils, windows,in HelpUtils. pas,in UElem. pas,in UFile. pas;
Var
f: TFile; item: Integer; FileName: string;
// выбор действия
function SelectItem: Integer;
var MaxItem: Integer;
begin
writeln (1 - Создать файл);
writeln (2 - Открыть файл );(3 - Загрузить данные из текстового файла);
MaxItem: =3;
if FileName<> then
begin
writeln (4 - Печать файла);(5 - Сохранить в текстовый файл);(6 - Добавить запись);(7 - Редактировать запись);(8 - Удалить запись);(9 - Занести в файл-отчёт записи о файлах с заданной спецификацией);
MaxItem: =9;
end;
writeln (0 - Выход);
repeat
write (Ваш выбор: );(Result);
until Result in [0. MaxItem];
end;
SetConsoleCP (1251);(1251);: =;
repeat
item: =SelectItem;
case item of // вызов соответствующих подпрограмм
1: NewFile (f,FileName);
: OpenFile (f,FileName);
: LoadFromText (f,FileName);
: PrintFile (f);
: SaveToText (f,FileName);
: AddElems (f);
: EditElems (f);
: DeleteElems (f);
: Task (f);
end; item=0;
end. // MainProgram