Есть программа - модель менеджера задач. Она почти готова,осталось только решить 1 проблему:при выборе 3 пункта меню получается зацикливани программы!(Так же в 1 пункте везде нужно ставить 2 readln чтобы программа ожидала нажатие клавиши ,иначе просто работает дальше.)
Вот собственно код:
Код:
program PID;
uses crt;
type proc=record
id:integer;
rs:integer;
numb:integer;
time:integer;
stime:integer;
end;
mas_proc_type=array [1..3] of proc;
var res,pro,key,n,i,did:integer;mas_proc:mas_proc_type;label s,e,c,cont;
begin
randomize;
res:=100;pro:=0;n:=0;
s:clrscr;
writeln('----------PID-----------');
writeln;
writeln('=======MENU=========');
writeln('1)Add process');
writeln('2)Delete process');
writeln('3)Show all');
writeln('4)Exit');
readln(key);
case key of
1: begin
if (res=0) then
begin
writeln('There are no free resourses!');
readln;readln;
goto s;
end;
if (pro>3) then
begin
writeln('You cannot add another process!');
readln;readln;
goto s;
end;
write('Process time: '); read(mas_proc[pro+1].time);
write('Quantity of resourses: '); read(mas_proc[pro+1].rs);
if (mas_proc[pro+1].rs>res) then
begin
writeln('Too many resourses!');
readln;
goto s;
end;
mas_proc[pro+1].numb:=n+1;
write('Starttime: '); read(mas_proc[pro+1].stime);
mas_proc[pro+1].id:=random(100);
for i:=1 to 3 do if (mas_proc[i].id=mas_proc[pro+1].id) then
mas_proc[pro+1].id:=mas_proc[pro+1].id+random(10);
writeln('Process have been added!');
write('Process id:');textcolor(green);
writeln(mas_proc[pro+1].id);textcolor(white);
write('Process number:');textcolor(green);
writeln(mas_proc[pro+1].numb);textcolor(white);
readln;readln;
res:=res-mas_proc[pro+1].rs;
pro:=pro+1;n:=n+1;
goto s;
end;
2: begin
if (pro=0) then begin
writeln('There is no process to delete!');
readln;
goto s;
end;
writeln('Write id of process you want do delete');
readln(did);
for i:=1 to 3 do
if (did=mas_proc[i].id) then
begin
c:mas_proc[i].id:=0;
res:=res+mas_proc[i].rs;
if (i=2) then begin
mas_proc[2].id:=mas_proc[3].id;
mas_proc[2].rs:=mas_proc[3].rs;
mas_proc[2].numb:=mas_proc[3].numb;
mas_proc[2].time:=mas_proc[3].time;
mas_proc[2].stime:=mas_proc[3].stime;
end;
if (i=1) then begin
mas_proc[1].id:=mas_proc[2].id;
mas_proc[1].rs:=mas_proc[2].rs;
mas_proc[1].numb:=mas_proc[2].numb;
mas_proc[1].time:=mas_proc[2].time;
mas_proc[1].stime:=mas_proc[2].stime;
mas_proc[2].id:=mas_proc[3].id;
mas_proc[2].rs:=mas_proc[3].rs;
mas_proc[2].numb:=mas_proc[3].numb;
mas_proc[2].time:=mas_proc[3].time;
mas_proc[2].stime:=mas_proc[3].stime;
end;
mas_proc[3].numb:=0;
mas_proc[3].time:=0;
mas_proc[3].stime:=0;
mas_proc[3].rs:=0;
pro:=pro-1;
if (did=0) then goto cont;
end;did:=0;
readln;goto s;
end;
3: begin
for i:=1 to 3 do mas_proc[i].stime:=-mas_proc[i].stime;
repeat
cont:clrscr;
writeln('г===T====T===========T======¬');
writeln('¦ № ¦ ID ¦ Resources ¦ Time ¦');
writeln('¦===+====+===========+======¦');
for i:=1 to 3 do mas_proc[i].stime:=mas_proc[i].stime+1;
delay(1000);
if (mas_proc[1].stime>=mas_proc[1].time) then begin i:=1;goto c;end;
if (mas_proc[1].numb<>0) then
writeln('¦ ',mas_proc[1].numb,' ¦ ',mas_proc[1].id:2,' ¦ ',mas_proc[1].rs:7,' ¦ ',mas_proc[1].stime:4,' ¦');
if (mas_proc[2].stime>=mas_proc[2].time) then begin i:=2;goto c;end;
if (mas_proc[2].numb<>0) then
writeln('¦ ',mas_proc[2].numb,' ¦ ',mas_proc[2].id:2,' ¦ ',mas_proc[2].rs:7,' ¦ ',mas_proc[2].stime:4,' ¦');
if (mas_proc[3].stime>=mas_proc[3].time) then begin i:=3;goto c;end;
if (mas_proc[3].numb<>0) then
writeln('¦ ',mas_proc[3].numb,' ¦ ',mas_proc[3].id:2,' ¦ ',mas_proc[3].rs:7,' ¦ ',mas_proc[3].stime:4,' ¦');
writeln('L===¦====¦===========¦======-');
until KeyPressed;
readln;
goto s;
end;
4: begin
writeln('Press enter');
goto e;
end;
end;
e:readln;
end.
Больше всего волнует проблемма с выводом 3 пункта!