const n=4;
{массив названий}
kt:array[1..n] of string=('Otlicniki','Horoshisty','Uspevayushie',
'Neuspevayushie');
var z:array [1..n] of integer; {Задаём массив}
i,x,y,x1,y1,r,a,b,s:integer;
st:string;
begin
clrscr;
writeln('Vvedite kolichestvo po kategoriyam'); {Вывод на экран}
for i:=1 to n do
begin
write(i,' ',kt[i],' ');
readln(z[i]);
end;
initgraph(x,y,'');{Подключение графического режима}
s:=0;
for i:=1 to n do
s:=s+z[i];
x:=getmaxX div 2; {Начало координат в центре экрана}
y:=getmaxY div 2;
r:=150; {Радиус окружности}
b:=round(360*z[1]/s); {Рисуем круг}
setcolor(9);
setfillstyle(1,9);
pieslice(x,y,0,b,r);
str(100*z[1]/s:0:2,st);
x1:=x+round(r*cos(pi*b/360));{середина сектора по внешней границе для Х}
if x1>=x then x1:=x1+30{правее центра диаграммы}
else x1:=x1-140;{левее}
y1:=y-round(r*sin(pi*b/360));{по Y}
if y1<x then y1:=y1-20{выше}
else y1:=y1+20;{ниже}
outtextXY(x1,y1,kt[1]+' '+ st+' %');
for i:=2 to n-1 do
begin
a:=round(360*z[i]/s)+b;
setcolor(i);
setfillstyle(1,i);
pieslice(x,y,b,a,r);
str(100*z[i]/s:0:2,st);
x1:=x+round(r*cos(pi*(a+b)/360));
if x1>=x then x1:=x1+30
else x1:=x1-140;
y1:=y-round(r*sin(pi*(a+b)/360));
if y1<x then y1:=y1-20
else y1:=y1+20;
outtextXY(x1,y1,kt[i]+'='+st+'%');
b:=a;
end;
setcolor(n);
setfillstyle(1,n);
pieslice(x,y,b,360,r);
str(100*z[n]/s:0:2,st);
x1:=x+round(r*cos(pi*(360+b)/360));
if x1>=x then x1:=x1+30
else x1:=x1-140;
y1:=y-round(r*sin(pi*(360+b)/360));
if y1<x then y1:=y1-20
else y1:=y1+20;
outtextXY(x1,y1,kt[n]+' '+st+'%');
readln;
end.

