Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
30
Добавлен:
09.03.2016
Размер:
5 Кб
Скачать
program h12;

uses
  CRT;

const
  DataFName = 'H12.DAT';
  LinesPP =    19;
  MaxItems =   999;

type
  CarRec = record
             Name:    string[17];
             Country: string[13];
             Power:   real;
             Fuel:    real;
             Speed:   real;
           end;

var
  Cars:      array[1..MaxItems] of CarRec;
  CarsTotal: word;

procedure ShowTable;
var
  Lines,
  Total:   word;
  EOFile:  boolean;
  RK:      char;
begin
  Total:= 0;
  EOFile:= false;

  while not EOFile do begin
    Lines:= 0;

    Writeln;
    Writeln(' -----------------------------------------------------',
            '-------------------------');
    Writeln('    N  Ќ §ў ­ЁҐ          ‘вp ­            Њ®й­®бвм    ',
            '    ђ б室  Њ ЄбЁ¬ «м­ п ');
    Writeln('       (¬ pЄ )                           ¤ўЁЈ вҐ«п,   ',
            '   в®Ї«Ёў ,     бЄ®p®бвм,');
    Writeln('                                               «.б.   ',
            '  «/100 Є¬          Є¬/з ');
    Writeln(' ----- ----------------- ------------- -------------- ',
            '------------ ------------');

    while (not EOFile) and (Lines<LinesPP) do begin
      Inc(Lines);
      Inc(Total);
      with Cars[Total] do
      Writeln('  ',Total:3,'  ',Name,'':17-Length(Name),' ',
              Country,'':13-Length(Country),' ',Power:11:2,'   ',
              Fuel:11:2,'   ',Speed:11:2);

      EOFile:= Total>=CarsTotal;
    end;

    Writeln(' -----------------------------------------------------',
            '-------------------------');
    if not EOFile then begin
      Write(' Џp®ЎҐ« ¤«п Їp®¤®«¦Ґ­Ёп Ё«Ё [Esc] ¤«п ўл室  Ё§ Їp®б¬®вp  ');
      repeat RK:= ReadKey until RK in [' ',^[];
      EOFile:= RK=^[;
    end
    else begin
      Write(' Љ®­Ґж бЇЁбЄ . Ќ ¦¬ЁвҐ Їp®ЎҐ« ¤«п ўл室  ');
      repeat until ReadKey=' ';
    end;
    Writeln;
  end;
end; { ShowTable }

procedure AddElement;
var
  WD:    CarRec;
  Loop,
  Loop2: word;
begin
  Writeln;
  with WD do begin
    Write('   Ќ §ў ­ЁҐ ..................... ');
    Readln(Name);
    Write('   ‘вp ­  ....................... ');
    Readln(Country);
    Write('   Њ®й­®бвм, «.б. ............... ');
    Readln(Power);
    Write('   ђ б室 в®Ї«Ёў , «/100 Є¬ ..... ');
    Readln(Fuel);
    Write('   Њ Єб.бЄ®p®бвм, Є¬/з .......... ');
    Readln(Speed);
  end;

{ „®Ў ў«Ґ­ЁҐ б гЇ®p冷稢 ­ЁҐ¬ Ї® ¬®й­®бвЁ ¤ўЁЈ вҐ«п }
  Loop:= 1;
  while (Loop<=CarsTotal) and (Cars[Loop].Power<=WD.Power) do Inc(Loop);
  for Loop2:= CarsTotal+1 downto Loop+1 do Cars[Loop2]:= Cars[Loop2-1];

  Inc(CarsTotal);
  with Cars[Loop] do begin
    Name:= Copy(WD.Name,1,17);
    Country:= Copy(WD.Country,1,13);
    Power:= WD.Power;
    Fuel:= WD.Fuel;
    Speed:= WD.Speed;
  end;
end; { AddElement }

procedure DelElement;
var
  DelItem,Loop: word;
begin
  Writeln;
  Write('  Ќ®¬Ґp н«Ґ¬Ґ­в  ¤«п г¤ «Ґ­Ёп (1-',CarsTotal,') .... ');
  Readln(DelItem);

  for Loop:= DelItem to CarsTotal-1 do Cars[Loop]:= Cars[Loop+1];
  Dec(CarsTotal);
end; { DelElement }

function Menu: byte;
const
  Fns: array[0..3] of string[20] = (
       '‚л室',
       'Џp®б¬®вpҐвм в Ў«Ёжг',
       '„®Ў ўЁвм н«Ґ¬Ґ­в',
       '“¤ «Ёвм н«Ґ¬Ґ­в');

var
  MK:   char;
  Loop: byte;
begin
  for Loop:= 1 to 20 do Writeln;
  Writeln('ЪДДДДДВДДДДДДДДДДДДДДДДДДДДДДДї');
  Writeln('і  N  і  Ќ §ў ­ЁҐ дг­ЄжЁЁ     і');
  Writeln('ГДДДДДЕДДДДДДДДДДДДДДДДДДДДДДДґ');
  for Loop:= 1 to 3 do
  Writeln('і  ',Loop,'  і  ',Fns[Loop],'':21-Length(Fns[Loop]),'і');
  Writeln('ГДДДДДЕДДДДДДДДДДДДДДДДДДДДДДДґ');
  Writeln('і  0  і  ‚л室                і');
  Writeln('АДДДДДБДДДДДДДДДДДДДДДДДДДДДДДЩ');
  Write('   ');
  repeat MK:= ReadKey until MK in ['0'..'3',^[];

  if MK=^[ then Loop:= 0 else Loop:= Ord(MK)-$30;
  Writeln(Loop,'     ',Fns[Loop]);

  Menu:= Loop;
end; { Menu }

var
  MenuKey:  byte;
  CarNo:    word;
  DataFile: file of CarRec;

begin
  Writeln;
  Writeln('>> —⥭ЁҐ д ©«  ¤ ­­ле ',DataFName,'...');

  CarsTotal:= 0;
  FillChar(Cars,SizeOf(Cars),0);

  Assign(DataFile,DataFName);
{$I-}
  Reset(DataFile);
{$I+}
  if IOResult<>0 then Rewrite(DataFile)
  else while not EOF(DataFile) do begin
    Inc(CarsTotal);
    Read(DataFile,Cars[CarsTotal]);
  end;
  Close(DataFile);

  repeat
    MenuKey:= Menu;
    case MenuKey of
      1: ShowTable;
      2: AddElement;
      3: DelElement;
    end;
  until MenuKey=0;

  Writeln;
  Writeln('>> ‡ ЇЁбм д ©«  ¤ ­­ле ',DataFName,'...');

  Assign(DataFile,DataFName);
  Rewrite(DataFile);
  for CarNo:= 1 to CarsTotal do Write(DataFile,Cars[CarNo]);
  Close(DataFile);
end.
Соседние файлы в папке graph