Помощь - Поиск - Пользователи - Календарь
Полная версия: Файл записей
Форум «Всё о Паскале» > Pascal, Object Pascal > Задачи
Rocket
Создать запись. Создать файл записей. Организовать хранение записей в файле и работу с файлом и записями.
Создать меню со следующими пунктами:
1.Добавить элемент в конец;
2.Удалить элемент по порядковому номеру;
3.Вывести элементы на экран ввиде таблицы;
4.Найти элемент по двум полям на выбор;
5.Редактировать элемент;
6.Выход.
Описать структуру "Город". У города есть название,количество жителей,статус,мэр.

Помогите чем сможете....
мисс_граффити
воспользуйся поиском
подобные задачи решались неоднократно
Rocket
Цитата(мисс_граффити @ 4.03.2007 17:15) *

воспользуйся поиском
подобные задачи решались неоднократно

Неоднократно пользовался поиском...по-видимому не особо удачно\\\
мисс_граффити
показывай, что пробовал делать
не может же быть, что не получилось совсем ничего!
Tonny_Bennet
Цитата(Rocket @ 4.03.2007 16:42) *


Описать структуру "Город". У города есть название,количество жителей,статус,мэр.



а можешь разъяснить поподробнее
Rocket
Цитата(Tonny_Bennet @ 4.03.2007 23:59) *

а можешь разъяснить поподробнее

То есть создать запись "Город" и описать его по данным параметрам.
klem4
Rocket, сходи сюда: Записи. Record. и сюда: Файлы

+ Поиск действительно, поищи "База данных", "Библиотека", "Телефонный справочник", "Типизированный файл"

Эти задачи на создание БД достаточно похожи ...
Rocket
Вот код задачи:
Program SinCity;

uses crt;


const

l1  = #218;
l2  = #192;
l3  = #191;
l4  = #217;
l5  = #196;
l6  = #179;
l7  = #197;
l8  = #195;
l9  = #180;
l10 = #193;
l11 = #194;

type

city=record
name:string;
population:longint;
mayor:string;
capital:string;
stat:string;

end;


var
f:file of city;
f1,f2:string;
p:longint;
n,i,j,c,x,x1,x2,x3,x4,x5,a:integer;
City_:array[1..10] of city;
command:byte;
d,cap:char;
stop,ex:boolean;





begin
n:=0;

assign(f,'genius.dat');

{$I-}
Reset(f);
{$I+}

if ioresult<>0 then

begin
 writeln('To creat the file?');
  writeln('1- Yes');
   writeln('2-No');
    readln(a);
     if a=1 then rewrite(f) else writeln('You must to creat the file!');end;

n:=filesize(f);


          repeat
          
           TextBackGround(9); ClrScr; TextColor(12);
  GotoXY(20,4); writeln('|--------------------[ MENU ]-----------------|');
  GotoXY(20,5); writeln('|   1 - to add new  the City                  |');
  GotoXY(20,6); writeln('|   2 - to delete the City                    |');
  GotoXY(20,7); writeln('|   3 - to remove the list on monitor         |');
  GotoXY(20,8); writeln('|   4 - to find the City                      |');
  GotoXY(20,9); writeln('|   5 - to edit the City                      |');
  GotoXY(20,10);writeln('|   6 - to escape                             |');
  GotoXY(20,11);writeln('|---------------------------------------------|');
        GotoXY(20,16);
        TextBackGround(9); TextColor(15);
     write('Enter 1, 2, 3 ,4 ,5 or 6   :  '); Readln(command);  writeln;


     case command of
1:

begin

writeln('Add new City?(Y)\(N)');
read(d);
if d='y' then

begin

n:=n+1;

writeln('Enter the name');
readln;
 readln(city_[n].name);

  writeln('Enter mayor');
    readln(city_[n].mayor);


  writeln('Enter population');
   readln(P);
    city_[n].population:=p;



      writeln('Status of capital:(Y)\(N)');
       readln(cap);
         if cap='y' then city_[n].capital:='*Capital*';
           if cap='n' then city_[n].capital:='*Settlement*';

            if p>=1000000  then city_[n].stat:='*****';
             if (p>=500000) and (p<1000000) then city_[n].stat:='****';
              if (p>=100000) and (p<500000) then city_[n].stat:='***';
               if (p>=50000) and (p<100000) then city_[n].stat:='**';
                if (p<50000) then  city_[n].stat:='*';

                write(f,city_[n]);
                writeln;


end;
end;

2:
  begin
   if n<>0 then
    begin
     write('Enter the city number: ');
      read(c);
       if c+1<=n then
        begin
         for j:=c to n-1 do
          begin
           seek(f,j);
            read(f,city_[n]);
             seek(f,j-1);
              write(f,city_[n]);
               end;
                truncate(f);
                 n:=n-1;
                  end
                  else
                  begin
                   seek(f,j-1);
                    truncate(f);
                     n:=n-1;
                     end;
                     end;
                      end;


3:
  begin
   seek(f,0);
   read(f,city_[n]);
   x1:=19;
    x2:=0;

  write(l1);
  for x:=1 to 14  do write(l5);
  write(l11);
  for x:=1 to 14  do write(l5);
  write(l11);
  for x:=1 to 14  do write(l5);
  write(l11);
  for x:=1 to 14  do write(l5);
  write(l11);
  for x:=1 to 14 do write(l5);
  writeln(l3); gotoxy(1,19);
  write(l6);write('"Name"'); gotoxy(16,19);
  write(l6);write('"Population"'); gotoxy(31,19);
  write(l6);write('"Mayor"'); gotoxy(46,19);
  write(l6);write('"Capital"'); gotoxy(61,19);
  write(l6);write('"Status"'); gotoxy(76,19);
  writeln(l6);
  x3:=(n+1)*2;
   for x4:=2 to x3-1 do
    begin
     x5:=x4 mod 2;
      x1:=x1+1;
       if x5=0 then
        begin
         write(l8);
          for x:=1 to 14  do write(l5);
           write(l7);
            for x:=1 to 14  do write(l5);
             write(l7);
              for x:=1 to 14  do write(l5);
               write(l7);
                for x:=1 to 14  do write(l5);
                 write(l7);
                  for x:=1 to 14  do write(l5);
                   writeln(l9);
                    end
                    else
                    begin

                    x2:=x2+1; gotoxy(1,x1);
                    write(l6); write(city_[x2].name); gotoxy(16,x1);
                    write(l6); write(city_[x2].population); gotoxy(31,x1);
                    write(l6); write(city_[x2].mayor); gotoxy(46,x1);
                    write(l6); write(city_[x2].capital); gotoxy(61,x1);
                    write(l6); write(city_[x2].stat); gotoxy(76,x1);
                    writeln(l6);
                    end;
                   end;
                  write(l2);
                  for x:=1 to 14  do write(l5);
                  write(l10);
                  for x:=1 to 14  do write(l5);
                  write(l10);
                  for x:=1 to 14  do write(l5);
                  write(l10);
                  for x:=1 to 14  do write(l5);
                  write(l10);
                  for x:=1 to 14  do write(l5);
                  writeln(l4);
                  readln;
                  end;




4:
  begin
  writeln('"Search"');
   writeln;
   writeln('Please,enter the name:');
    readln(f1);
     writeln('Please,enter the mayor:');
      readln(f2);
       i:=0;
       stop:=true;
        repeat
        seek(f,i);
        read(f,city_[i+1]);
        
         if (city_[i+1].name=f1) and (city_[i+1].mayor=f2) then
          begin
           seek(f,i);

   writeln;
   
   writeln('Loading, please wait..............     ');


            writeln('City: ', city_[i+1].name);
             writeln('Population: ', city_[i+1].population);
              writeln('Mayor: ', city_[i+1].mayor);
               writeln('Status: ', city_[i+1].capital,city_[i+1].stat );
               
               i:=i+1;
                stop:=false;
                   end
                    until i=n;
                    
                    if stop then
                    
                    writeln('Not found!!!');
                    
                     end;




5:
  begin
   writeln('Enter the number');
    readln(i);
     seek(f,(i-1));

    writeln('Enter the name: ');
     readln(city_[i].name);

      writeln('Enter population: ');
       readln(P);
        city_[i].population:=p;

   writeln('Enter mayor: ');
    readln(city_[i].mayor);


      writeln('Status of capital:(Y)\(N)');
       readln(cap);
         if cap='y' then city_[i].capital:='***Capital***';
           if cap='n' then city_[i].capital:='*Settlement*';

            if p>=1000000  then city_[i].stat:='*****';
             if (p>=500000) and (p<1000000) then city_[i].stat:='****';
              if (p>=100000) and (p<500000) then city_[i].stat:='***';
               if (p>=50000) and (p<100000) then city_[i].stat:='**';
                if (p<50000) then  city_[i].stat:='*';

        write(f,city_[i]);
                  writeln;

                end;





6:
 begin
ex:=true;
end;
end;
until ex;
   close(f);

end.

Всё работает,кроме 3 пункта. А именно: после закрытия файла таблица не выводит имееющиеся поля. Объясните в чем косяк,пожалуйста!
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.