Ошибка:Ожидался идентификатор - Pascal ABC

Узнай цену своей работы

Формулировка задачи:

Листинг программы
  1. type
  2. PTClient = ^TClient;
  3. TClient = object;
  4. constructor create(value: integer);
  5. function get_id: integer;
  6. private
  7. ID: integer;
  8. end;
  9. constructor TClient.create(value: integer);
  10. begin
  11. ID := value;
  12. end;
  13. function TClient.get_id: integer;
  14. begin
  15. get_id := ID;
  16. end;
Выдает
Ошибка:Ожидался идентификатор
вот в этом месте: constructor create(тут value: integer); function get_id: integer;

Решение задачи: «Ошибка:Ожидался идентификатор»

textual
Листинг программы
  1. Program bank;
  2. const
  3.   n  = 10;
  4.   n5 =  6;
  5.   n6 =  3;
  6.   nT = 50;
  7.  
  8. function f1: integer;
  9. begin
  10.   f1 := random(4) + 2;
  11. end;
  12. function f2: integer;
  13. begin
  14.   f2 := random(10);
  15. end;
  16.  
  17. (***** TClient *****)
  18. type
  19.   PTClient = ^TClient;
  20.   TClient = class
  21.  
  22.     constructor create(value: integer);
  23.     function get_id: integer;
  24.  
  25.   private
  26.     ID: integer;
  27.   end;
  28.  
  29. constructor TClient.create(value: integer);
  30. begin
  31.   ID := value;
  32. end;
  33. function TClient.get_id: integer;
  34. begin
  35.   get_id := ID;
  36. end;
  37.  
  38.  
  39. type
  40.   T = PTClient;
  41.  
  42.   PTQueueItem = ^TQueueItem;
  43.   TQueueItem = class
  44.     item: T;
  45.     next: PTQueueItem;
  46.  
  47.     constructor create(value: T);
  48.   end;
  49.  
  50.   TQueue = class
  51.     constructor create;
  52.     destructor destroy;
  53.  
  54.     procedure get(var value: T);
  55.     procedure put(const value: T);
  56.  
  57.     function is_empty: boolean;
  58.  
  59.   private
  60.     front, back: PTQueueItem;
  61.   end;
  62.  
  63.  
  64.  
  65. constructor TQueueItem.create(value: T);
  66. begin
  67.   item := value;
  68.   next := nil;
  69. end;
  70.  
  71. constructor TQueue.create;
  72. begin
  73.   front := nil; back := nil;
  74. end;
  75.  
  76. destructor TQueue.destroy;
  77. var value: T;
  78. begin
  79.   while not is_empty do get(value);
  80. end;
  81.  
  82. procedure TQueue.get(var value: T);
  83. var pt: PTQueueItem;
  84. begin
  85.   if is_empty then begin
  86.     writeln('Trying to Get from the empty queue !'); halt(101)
  87.   end;
  88.  
  89.   pt := front;
  90.   front := front^.next;
  91.  
  92.   value := pt^.item;
  93.   dispose(pt);
  94. end;
  95.  
  96.  
  97. procedure TQueue.put(const value: T);
  98. var pt: PTQueueItem;
  99. begin
  100.   pt := new(PTQueueItem, create(value));
  101.   if is_empty then begin
  102.     front := pt; back := pt;
  103.   end
  104.   else begin
  105.     back^.next := pt;
  106.     back := pt;
  107.   end;
  108. end;
  109.  
  110.  
  111. function TQueue.is_empty: boolean;
  112. begin
  113.   is_empty := (front = nil)
  114. end;
  115.  
  116.  
  117. type
  118.   status = (
  119.     _busy = 0, _waiting, _vacation
  120.   );
  121.  
  122.   PTCasher = ^TCasher;
  123.   TCasher = object
  124.  
  125.     state: status;
  126.     work_time, ID: integer; { *** const *** }
  127.     working_time, this_client: integer;
  128.  
  129.   public
  130.     constructor create(_id, _work: integer);
  131.     function handle(var changed: integer): status;
  132.     procedure next;
  133.   end;
  134.  
  135.  
  136. constructor TCasher.create(_id, _work: integer);
  137. begin
  138.   ID := _id; work_time := _work; state := _waiting;
  139.  
  140.   working_time := work_time;
  141. end;
  142.  
  143. function TCasher.handle(var changed: integer): status;
  144. begin
  145.   changed := 0;
  146.  
  147.   if state = _busy then begin
  148.     dec(this_client);
  149.     dec(working_time);
  150.  
  151.     if this_client = 0 then begin
  152.       state := _waiting; changed := 1;
  153.     end;
  154.   end;
  155.  
  156.   if state = _vacation then begin
  157.     inc(working_time);
  158.     if working_time > 0 then begin
  159.       state := _waiting; working_time := work_time; changed := 1;
  160.     end;
  161.   end;
  162.  
  163.   if state = _waiting then begin
  164.     if changed = 0 then dec(working_time);
  165.     if working_time <= 0 then begin
  166.       state := _vacation; working_time := -n6; changed := 1;
  167.     end;
  168.   end;
  169.  
  170.   handle := state;
  171. end;
  172.  
  173. procedure TCasher.next;
  174. begin
  175.   state := _busy;
  176.   this_client := f2;
  177. end;
  178.  
  179.  
  180. type
  181.   TManager = object
  182.     queue: TQueue;
  183.     cash_workers: array[0 .. pred(n)] of PTCasher;
  184.  
  185.     current_time, after_prev_enter: integer;
  186.  
  187.   public
  188.     constructor create;
  189.     destructor destroy;
  190.  
  191.     procedure run;
  192.   end;
  193.  
  194. constructor TManager.create;
  195. var i: integer;
  196. begin
  197.   current_time := 0; after_prev_enter := 0;
  198.   for i := 0 to pred(n) do
  199.     cash_workers[i] := new(PTCasher, create(i + 1, n5));
  200. end;
  201.  
  202. destructor TManager.destroy;
  203. var i: integer;
  204. begin
  205.   for i := 0 to pred(n) do
  206.     dispose(cash_workers[i]);
  207. end;
  208.  
  209. procedure TManager.run;
  210. const
  211.   client_entered: integer = 0;
  212. var
  213.   i: integer;
  214.   status_changed: integer;
  215.   curr_status: status;
  216.   client: PTClient;
  217. begin
  218.  
  219.   while (current_time <= nT) or (not queue.is_empty) do begin
  220.  
  221.     for i := 0 to pred(n) do begin
  222.       status_changed := 0;
  223.       curr_status := cash_workers[i]^.Handle(status_changed);
  224.  
  225.       if status_changed <> 0 then { statistics }
  226.         case curr_status of
  227.           _vacation:
  228.             writeln('casher #', i, ' goes to rest at:: ', current_time);
  229.           _waiting:
  230.             writeln('casher #', i, ' awaiting at:: ', current_time);
  231.         end;
  232.  
  233.       if curr_status = _waiting then
  234.         if not queue.is_empty then begin
  235.  
  236.           queue.get(client);
  237.           writeln('client #', client^.get_id, ' sent to casher #', i, ' at:: ', current_time);
  238.           cash_workers[i]^.next;
  239.           dispose(client);
  240.  
  241.         end;
  242.  
  243.     end;
  244.  
  245.     if current_time <= nT then begin
  246.  
  247.       inc(after_prev_enter);
  248.       if after_prev_enter > f1 then begin
  249.  
  250.         after_prev_enter := 0;
  251.         inc(client_entered);
  252.         client := new(PTClient, create(client_entered));
  253.         queue.put(client);
  254.  
  255.       end;
  256.  
  257.     end;
  258.     inc(current_time);
  259.   end;
  260.   writeln(client_entered);
  261.  
  262. end;
  263.  
  264. var bank: TManager;
  265. begin
  266.  
  267.   bank.create;
  268.   bank.run;
  269.   bank.destroy;
  270. end.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 4.133 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут