Охота чтобы базу даных непополнять каждый раз.
program baggage;
{ При подготовке был использован Приказ
Министерства транспорта Российской Федерации №82 от 28 июня 2007
"Об утверждении Федеральных авиационных правил "Общие правила
воздушных перевозок пассажиров, багажа, грузов и требования
к обслуживанию пассажиров, грузоотправителей, грузополучателей" }
Uses
Crt;
const
kinds=5;
{ 6 типов багажа
0 - общий;
1 - с объявленной ценностью;
2 - с объявленным сроком годности;
3,4,5 - зарезервированы под дальнейшее использование
}
Type
TKind = 0..kinds;
TDays = integer;
TPrice = integer;
passag = Record
vechi:Byte;
ves:Real;
case kind: TKind of
1: (price: TPrice);
2: (days: Tdays);
end;
Var
nomer:Array[1..10] of passag;
i,vechi:Byte;
begin
clrscr;
vechi:= 0;
Writeln('Список пассажиров:');
randomize;
for i:=1 to 10 do
begin
nomer[i].vechi := Random(5);
if nomer[i].vechi = 0 then
nomer[i].ves:= 0
else
begin
nomer[i].ves:= 60 * Random;
nomer[i].kind := Random(kinds);
case nomer[i].kind of
1: nomer[i].price := random(10000);
2: nomer[i].days := random(366);
end;
end;
Write('Пасажир №',i,nomer[i].vechi:4,nomer[i].ves:7:2);
write(nomer[i].kind:2);
case nomer[i].kind of
1: write(' price=', nomer[i].price, '$');
2: write(' days=', nomer[i].days);
end;
writeln;
end;
Writeln;
for i:=1 to 10 do
begin
if (nomer[i].vechi = 1) and (nomer[i].ves<30) then
begin
Inc (vechi);
Writeln('Пасажир № ',i,nomer[i].vechi:4,nomer[i].ves:7:2);
end;
end;
if (vechi= 0) then
Writeln('такого пасажира нет');
readln;
end.
type игрушка=record название:string;
цена:integer;
цвет:string;
возраст1:1..16;
возраст2:1..16;
end;
и определить:
o название игрушек, цена которых не превышает данную и которые подходят детям данного возраста;
o найти самую дешевую игрушку данного названия;
o найти самый распространенный цвет игрушек.
program p178129;
{
type игрушка=record название:string;
цена:integer;
цвет:string;
возраст1:1..16;
возраст2:1..16;
end;
и определить:
o название игрушек, цена которых не превышает данную и которые подходят
детям данного возраста;
o найти самую дешевую игрушку данного названия;
o найти самый распространенный цвет игрушек.
}
uses
crt;
const
MinAge = 1;
MaxAge = 16;
MaxColors = 100;
type
TFileName = string[30];
TName = string;
TPrice = integer;
TColor = string;
TAge = MinAge..MaxAge;
TToy = record
name : TName;
price : TPrice;
color : TColor;
age1 : TAge;
age2 : TAge;
end;
TColorRec = record
color: TColor;
freq : integer;
end;
TColorList = record
colors: array[1..MaxColors] of TColorRec;
count: integer;
end;
TToysFile = file of TToy;
var
f: TToysFile;
choice: integer;
procedure FileInsert(var f: TToysFile);
var
toy: TToy;
begin
clrscr;
with toy do begin
write('Название ');
readln(name);
write('Цена ');
readln(price);
write('Цвет ');
readln(color);
write('Возраст от ');
readln(age1);
write('Возраст до ');
readln(age2);
end; { with }
reset(f);
seek(f, FileSize(f));
write(f, toy);
close(f);
readln;
end; { FileInsert }
procedure req1(var f: TToysFile);
{ название игрушек, цена которых не превышает данную и которые подходят
детям данного возраста }
var
toy : TToy;
price : TPrice;
age : TAge;
begin
write('Цена ');
readln(price);
write('Возраст ');
readln(age);
reset(f);
if eof(f) then
writeln('Файл пуст')
else begin
writeln('Игрушки для детей в возрасте ',age, ' лет по цене не более ', price);
while not(eof(f)) do begin
read(f, toy);
if (toy.price<=price) and (age in [toy.age1..toy.age2]) then
writeln(toy.name, '-', toy.color, '-', toy.price);
end { while }
end; { if }
close(f);
readln;
end; { req1 }
procedure req2(var f: TToysFile);
{ Определение самого распространённого цвета игрушек }
var
clist: TColorList;
i, imax: integer;
toy: TToy;
MaxFreq: integer;
found: boolean;
begin
{ считываем цвета в массив м одновременно проставляем частоту }
clist.count := 0;
reset(f);
while not(eof(f)) do begin
read(f, toy);
found := false;
for i:= 1 to clist.count do
if toy.color = clist.colors[i].color then begin
inc(clist.colors[i].freq);
found := true;
break;
end; { if }
if not found then begin
inc(clist.count);
clist.colors[clist.count].color := toy.color;
clist.colors[clist.count].freq := 1;
end; { if }
end; { while }
close(f);
{ ищем в массиве цвет с наибольшей частотой }
MaxFreq := 0;
imax := 0;
for i:= 1 to clist.count do
with clist.colors[i] do
if freq>MaxFreq then begin
MaxFreq := freq;
imax := i;
end; { if }
writeln('Наиболее часто встречается ', clist.colors[imax].color);
readln;
end; { req2 }
procedure req3(var f: TToysFile);
{ печать самой дешевой игрушки данного названия }
var
price: TPrice;
toy, cheapest: TToy;
name: TName;
taken: boolean;
begin
clrscr;
write('Название ');
readln(name);
reset(f);
seek(f,0);
if eof(f) then
writeln('Файл пуст')
else begin
taken := false;
while not(eof(f)) do begin
read(f, toy);
if (toy.name = name) then
if not(taken) or (toy.price<cheapest.price) then begin
cheapest := toy;
taken := true;
end; { if }
end { while }
end; { if }
close(f);
writeln('Самая дешевая игрушка ',name, ' стоит ', cheapest.price);
readln;
end; { req3 }
procedure view(var f: TToysFile);
var
toy: TToy;
i: integer;
begin
reset(f);
seek(f,0);
clrscr;
if eof(f) then
writeln('Файл пуст')
else
begin
writeln('№ Название Цена Цвет От До');
i:= 0;
while not(eof(f)) do
begin
inc(i);
read(f, toy);
with toy do
writeln(i, ' ', name, ' ':20-length(name), price, ' ',
color, ' ':10-length(color), age1, ' ', age2);
end;
end;
close(f);
readln;
end; { view }
procedure bye;
begin
clrscr;
writeln('Работа завершена');
readln;
end; { bye }
procedure init(var f: TToysFile; fName: TFileName);
begin
assign(f, fName);
if not(FileExists(fName)) then
begin
rewrite(f);
close(f);
end;
end; { init }
procedure menu;
begin
ClrScr;
writeln(' Работа с базой');
writeln('1: Запись');
writeln('2: Поиск игрушек по цене и возрасту');
writeln('3: Определение самого распространённого цвета игрушек');
writeln('4: Поиск самой дешёвой игрушки по названию');
writeln('5: Просмотр базы');
writeln('0: Завершение работы');
end; { menu }
begin { main }
init(f, 'toys.dat');
while true do
begin
menu;
readln(choice);
case choice of
1: FileInsert(f);
2: req1(f);
3: req2(f);
4: req3(f);
5: view(f);
0: begin
bye;
break;
end;
end; { case }
end; { while }
end.
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.