Set the task for Pascal: To simulate the work of a photo studio serving reporters, photographers and paparazzi, with the paparazzi being served last. In the preparation of photographs consumed resources in the required quantity. As resources run out, service is suspended until new resources arrive, and there is a reserve that can be used to service reporters. Information about available resources and unserved customers in the queue should be available at any time.
The question is actually not in the construction of the program, but in some parts of it, namely, the program closes with an error - "" Unexpected exception to EAccessViolation. Access violation at address 0075CD31 in module 'PascalABC.exe'. Read of address 00003288. The program is completed (photo.pas line 45) "
The program is still far from complete, but it has already driven me into a dead end, please help me figure out what my mistakes are.
Here is the code:
program photo; uses crt, timers; type ukazatel = ^elem_spiska; elem_spiska = record znach : Integer; next : ukazatel; end; var reporter, photographer, paparazzi, rand, i, resources, rezerv, m: integer; head, p, q : ukazatel; {процедура обслуживания} procedure service; begin if resources = 0 then begin p := head; {начать с головы списка} while p^.next^.znach <> 2 do p := p^.next; q := p^.next; {удаляемый элемент} p^.next := q^.next; {связка «через один»} dispose(q); rezerv := rezerv - 1; end else begin p := p^.next; {переход к следующему элементу списка} resources := resources - 1; end; end; {процедура добавления очереди} procedure turn; var t, o: integer; begin t := Random(3)+0; writeln(t); p := head^.next; if p = nil then begin new(p); p^.znach := t; p^.next := nil; end else if (p^.znach = 0) and (t > 0) then begin p^.znach := t; p^.next^.znach := 0; p^.next^.next := nil; end else begin new(q); q := p^.next; q^.znach := t; p^ := q^; dispose(q); end; end; {процедура запуска обслуживания} procedure open_service; var u: integer; begin u := 1; new(p); new(q); new(head); head^.znach := u; randomize; reporter := 2; photographer := 1; paparazzi := 0; resources := 100; rezerv := 100; while rezerv > 0 do begin turn; writeln(p^.znach); sleep(1000); turn; sleep(1000); writeln(p^.znach); service; sleep(1500); end; end; begin WriteLn('Фото Ателье'); writeln('1 - открыть заведение'); writeln('2 - Закрыть заведение'); read(m); case m of 1: open_service; 0: exit; end; end.