Добавил:
Silebox
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
program lab7_1;
uses sysutils;
const cols = 5;
type arr_str = array[1..cols] of string;
var
f: TextFile;
fname, cmd: shortstring;
headers: arr_str = ('инвентарный номер', 'порядковый номер', 'наименование оборудования', 'дата приобретения', 'стоимость');
i: integer;
procedure checkHeaders();
var x: string;
begin
reset(f); ReadLn(f,x);
if (length(x) = 0) then
begin
rewrite(f);
for i:=1 to cols do
begin
Write(f, headers[i]);
if (i <> cols) then Write(f, ' | ')
end;
WriteLn(f, '');
end;
end;
function getSpaces(x,s:string):string;
begin
getSpaces := StringOfChar(' ', (length(s) div 2) - (length(x) div 2));
end;
function getInfo():string;
var
x: string = '';
temp_x: string;
begin
Write('Введите инвентарный номер: '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[1]) +' | ';
Write('Введите порядковый номер: '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[2]) +' | ';
Write('Введите наименование оборудования: '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[3]) +' | ';
Write('Введите дату приобретения (формат: дд.мм.гггг): '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[4]) +' | ';
Write('Введите стоимость: '); ReadLn(temp_x); x := x + temp_x + ' рублей';
getInfo := x;
end;
procedure allRecordsOutput();
var temp_x: string;
begin
reset(f);
while (not eof(f)) do
begin
ReadLn(f,temp_x);
WriteLn(temp_x);
end;
WriteLn('');
append(f);
end;
begin
Write('Введите название файла: '); ReadLn(fname);
if (not FileExists(fname)) then FileCreate(fname);
assign(f,fname);
checkHeaders();
append(f);
while (true) do
begin
WriteLn('1 - добавить запись');
WriteLn('2 - показать записи');
WriteLn('Enter - выйти');
Write('>> '); ReadLn(cmd);
if (cmd = '1') then WriteLn(f,getInfo())
else if (cmd = '2') then allRecordsOutput()
else if (cmd = '') then break
else WriteLn('неправильная команда');
end;
close(f);
end.
uses sysutils;
const cols = 5;
type arr_str = array[1..cols] of string;
var
f: TextFile;
fname, cmd: shortstring;
headers: arr_str = ('инвентарный номер', 'порядковый номер', 'наименование оборудования', 'дата приобретения', 'стоимость');
i: integer;
procedure checkHeaders();
var x: string;
begin
reset(f); ReadLn(f,x);
if (length(x) = 0) then
begin
rewrite(f);
for i:=1 to cols do
begin
Write(f, headers[i]);
if (i <> cols) then Write(f, ' | ')
end;
WriteLn(f, '');
end;
end;
function getSpaces(x,s:string):string;
begin
getSpaces := StringOfChar(' ', (length(s) div 2) - (length(x) div 2));
end;
function getInfo():string;
var
x: string = '';
temp_x: string;
begin
Write('Введите инвентарный номер: '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[1]) +' | ';
Write('Введите порядковый номер: '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[2]) +' | ';
Write('Введите наименование оборудования: '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[3]) +' | ';
Write('Введите дату приобретения (формат: дд.мм.гггг): '); ReadLn(temp_x); x := x + temp_x + getSpaces(temp_x, headers[4]) +' | ';
Write('Введите стоимость: '); ReadLn(temp_x); x := x + temp_x + ' рублей';
getInfo := x;
end;
procedure allRecordsOutput();
var temp_x: string;
begin
reset(f);
while (not eof(f)) do
begin
ReadLn(f,temp_x);
WriteLn(temp_x);
end;
WriteLn('');
append(f);
end;
begin
Write('Введите название файла: '); ReadLn(fname);
if (not FileExists(fname)) then FileCreate(fname);
assign(f,fname);
checkHeaders();
append(f);
while (true) do
begin
WriteLn('1 - добавить запись');
WriteLn('2 - показать записи');
WriteLn('Enter - выйти');
Write('>> '); ReadLn(cmd);
if (cmd = '1') then WriteLn(f,getInfo())
else if (cmd = '2') then allRecordsOutput()
else if (cmd = '') then break
else WriteLn('неправильная команда');
end;
close(f);
end.