virginia |
11.08.2012 12:57 |
Паскаль. Задача о расписании поездов
{Создать массив(расписание движения),хранящий информацию о 20 поездах,отправляющихся со станции Воронеж.
Каждый элемент расписания содержит информацию:номер поезда,пункт назначения,время отправления,количество свободных мест
в вагонах типа св,купе,плацкарт.а)упорядочить массив по пункту назначения.Вывести информацию о поездах,отходящих в заданный период
времени и следующих до заданного пункта назначения в типизированный файл}.помогите сделать вывод в типизированный файл
Код:
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils,
Windows;
const
n=20;
type
traininfo=record
numbertrain:integer;
destination:string;
timeofdeparture_h:integer;
timeofdeparture_m:integer;
sv:Integer;
compartment:integer;
plackart:integer;
end;
tmas=array [1..n] of traininfo;
var
train:tmas;
i,t_h,t_m:Integer;
time1,time2:real;
destination,s:string;
f,f1:Text;
//-----------------------------------------------------------------
procedure vvoddannuh;
var
i,numbertrain,timeofdeparture_h,timeofdeparture_m,
sv,compartment,plackart:Integer;
destination:String;
f:Text;
begin
Assign(f,'train_1.txt');
Rewrite(f);
writeln (f,'------------------------------------------------------------');
writeln (f,'номер / пункт назначения / время отпр. / св / купе / плацк. ');
writeln (f,'------------------------------------------------------------');
for i:=1 to n do
begin
Write('введи номер поезда: ');
Readln(numbertrain);
Write('введи пункт назначения: ');
Readln(destination);
Write('введи время отправления (чч мм): ');
Readln(timeofdeparture_h,timeofdeparture_m);
Write('введи количество свободных мест в св: ');
Readln(sv);
Write('введи количество свободных мест в купе: ');
Readln(compartment);
Write('введи количество свободных мест в плацкарте: ');
Readln(plackart);
writeln(f,numbertrain:5,destination:19,timeofdeparture_h:8,timeofdeparture_m:3,sv:8,compartment:7,plackart:8);
writeln
end;
Close(f)
end;
//-----------------------------------------------------------------
Procedure vuvoddannuh(a:tmas);
var
i:Integer;
f:Text;
begin
Assign(f,'train_2.txt');
Rewrite(f);
writeln (f,'------------------------------------------------------------');
writeln (f,'номер / пункт назначения / время отпр. / св / купе / плацк. ');
writeln (f,'------------------------------------------------------------');
for i:=1 to n do
writeln(f,a[i].numbertrain:5,a[i].destination:19,a[i].timeofdeparture_h:8,a[i].timeofdeparture_m:3,a[i].sv:8,a[i].compartment:7,a[i].plackart:8);
Close(f)
end;
//------------------------------------------------------------------------------------------
Procedure Read_data(Var a: tmas);
Var
i,j:Integer;
f:Text;
C:Char;
begin
Assign(f,'train_1.txt');
Reset(f);
readln(f);
readln(f);
readln(f);
for i:=1 to n do
begin
read(f,a[i].numbertrain);
repeat
read(f,C);
until C<>' ';
a[i].destination:=C;
repeat
read(f,C);
if C<>' ' then a[i].destination:=a[i].destination+C;
until C=' ';
readln(f,a[i].timeofdeparture_h,a[i].timeofdeparture_m,a[i].sv,a[i].compartment,a[i].plackart);
end;
Close(f)
end;
//------------------------------------------------------------------------------------------
Procedure Swap(Var k, l: traininfo);
Var m:traininfo;
begin
m := k;
k := l;
l := m;
end;
// --------------------------------------------------------------------------
Procedure sortirovka;
var
x:traininfo;
i,j:Integer;
begin
for i:=1 to n-1 do
for j:=1 to n-i do
if train[j].destination>train[j+1].destination then
Swap(train[j],train[j+1]);
end;
//--------------------------------------------------------------------------------
Procedure search_train(a:tmas;destination:string;tm1,tm2:real);
var
i,S:Integer;
f:Text;
begin
Assign(f,'train_2.txt');
Append(f);
Writeln(f);
S:=0;
for i:=1 to n do
if (a[i].destination=destination) and
(a[i].timeofdeparture_h+a[i].timeofdeparture_m/100>=tm1) and
(a[i].timeofdeparture_h+a[i].timeofdeparture_m/100<=tm2) then
begin
Writeln(f,'номер поезда: ',a[i].numbertrain);
Writeln(f,'пункт назначения: ',a[i].destination);
Writeln(f,'время отправления: ',a[i].timeofdeparture_h,'-',a[i].timeofdeparture_m);
Writeln(f,'количество мест в св: ',a[i].sv) ;
Writeln(f,'количество мест в купе: ',a[i].compartment);
Writeln(f,'количество мест в плацкарте: ',a[i].plackart);
Writeln(f);
S:=S+1
end;
if S=0 then writeln(f,'таких поездов нет');
Close(f);
end;
begin
SetConsoleOutputCP(1251);
if FileExists('train_1.txt')then
begin
read_data(train);
assign(f,'train_1.txt');
reset(f);
while not eof(f) do
begin
readln(f,s);
writeln(s);
end;
close(f);
sortirovka;
vuvoddannuh(train);
Writeln('введи пункт назначения:');
Readln(destination);
writeln('введи период времени(формат ввода чч мм) с');
readln(t_h,t_m);
time1:=t_h+t_m/100;
writeln('по');
Readln(t_h,t_m);
time2:=t_h+t_m/100;
search_train(train,destination,time1,time2);
assign(f1,'train_2.txt');
reset(f1);
while not eof(f1) do
begin
readln(f1,s);
writeln(s)
end;
close(f1)
end
else vvoddannuh;
Writeln('Для выхода нажмите enter');
readln
end.
|