Построить график частоты встречаемости букв — Pascal(Паскаль)

program bdz;
uses crt,graph;
type mas=array[1..26] of integer;
Var a:mas;
    f:text;
    x,y,s:string;
    i,j,allcount,mx,h:integer;
    gd,gm,c,y0,xi,yi:integer;
    msx,msy:real;
begin
clrscr;
allcount:=0;
s:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
writeln('Napiwite codergimoe');
readln(x);
assign(f,'new.txt');
rewrite(f);
write(f,x);
close(f);
reset(f);
while not EOF(f) do
read(f,y);
for i:=1 to 26 do
a[i]:=0;
for i:=1 to length(y) do
if pos(UpCase(y[i]),s)>0 then
 begin
  a[pos(UpCase(y[i]),s)]:=a[pos(Upcase(y[i]),s)]+1;
  allcount:=allcount+1;
 end
else writeln('Text ne codergit bykv');
close(f);
mx:=0;{найдем максимальное значение}
for i:=1 to 26 do
if a[i]>mx then mx:=a[i];
gd:=0;
initgraph(gd,gm,'');{переходим в графический режим}
y0:=getmaxY-40;{низ диаграммы}
msy:=(y0-40)/mx;{вертикальный масштаб}
msx:=(getmaxX-40)/25;{горизонтальный масштаб}
for i:=1 to 26 do
 begin
  s:=chr(i+64);{символ букв}
  if i=16 then c:=6 else c:=i;{все цвета кроме черного}
  setcolor(c);
  xi:=round(i*msx)-10;{}
  if a[i]>0 then yi:=y0-round(a[i]*msy){}
  else yi:=y0-11;
  outtextXY(xi,getmaxY-40,s);{выводим буквы}
  setfillstyle(1,c);
  bar(xi,yi,xi+10,y0-10);{рисуем цветные прямоугольники}
  str(a[i],s);
  outtextXY(xi,yi-10,s);{выводим значение}
 end;
readln
end.

Leave a Comment

− 1 = 3