| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- Uses Graph,Crt;
- Const
- Path = '';
- Xpol = 25;
- YPol = 25;
- PieX = 200;
- PieY = 200;
- Radius = 100;
- Type TypeVal = record
- num : Integer;
- per : Real;
- end;
- Var
- num_of_elem,type_of_diag : byte;
- values : array [1..15] of TypeVal;
- Summa : Integer;
- {---------=====================================---------------}
- Procedure GetValues;
- var
- i:Byte;
- begin
- ClrScr;
- Summa := 0;
- Num_of_elem := 0;
- for i := 1 to 15 do values[i].num := 0;
- WriteLn('Вводите элементы (не более 15), конец ввода - 0');
- i := 0;
- repeat
- inc(i);
- ReadLn(values[i].num);
- until (i > 14) or (values[i].num = 0);
- WriteLn('Введите тип диаграмы(1-один график, 0-много графиков)');
- ReadLn(type_of_diag);
- for i := 1 to 15 do if values[i].num <> 0 then inc(num_of_elem);
- if type_of_diag = 1 then
- For i := 1 to num_of_elem do Summa := Summa + values[i].num
- else
- for i := 1 to num_of_elem do
- if values[i].num > summa then summa := values[i].num;
- For i := 1 to num_of_elem do values[i].per := values[i].num / Summa;
- end;{GetValues}
- {-----------------------------------------}
- Procedure InitT;
- var
- Gd, Gm: Integer;
- i : byte;
- begin
- Gd := Detect;
- InitGraph(Gd, Gm,Path);
- if GraphResult <> grOk then
- WriteLn(GraphErrorMsg(GraphResult))
- else
- begin
- Rectangle(GetMaxX div 10,GetMaxY div 10,9*(GetMaxX div 10),9*(GetMaxY div 10));
- SetViewPort(GetMaxX div 10+1,GetMaxY div 10+1,9*(GetMaxX div 10)-1,9*(GetMaxY div 10)-1,ClipOn);
- SetWriteMode(XorPut);
- end;
- end;{InitT}
- {---------------------------------------}
- Procedure Chart2;
- var
- num : string;
- i : byte;
- begin
- for i := 1 to num_of_elem do
- begin
- SetFillStyle(solidfill,i);
- Bar3D(i*30,350,i*30+20,350 - round(330*values[i].per),5,true);
- Str(values[i].num,num);
- SetTextJustify(CenterText,TopText);
- OutTextXY(i*30+10,360,num)
- end;
- SetTextJustify(LeftText,TopText);
- end{chart2};
- {---------------------------------------}
- Procedure Chart;
- var
- String1,s2 : string;
- i : byte;
- LastVal,LastArc : Integer;
- begin
- for i := 1 to num_of_elem do
- begin
- Str(values[i].num,string1);
- str(round(values[i].per*100),s2);
- string1 := concat('Число ',string1,'(',s2,'%)');
- SetFillStyle(SolidFill,i);
- Bar(330,((387 div 2) - (Num_of_elem * 10)-20)+i*20,380,((387 div 2) - (Num_of_elem * 10)-20)+i*20+15);
- OutTextXY(390,((380 div 2) - (Num_of_elem * 10)-15)+i*20,string1);
- end;
- LastVal := Ypol;
- LastArc := 0;
- for i := 1 to num_of_elem do
- begin
- SetFillStyle(SolidFill,i);
- if i = 1 then
- begin
- Bar3d(Xpol,LastVal,Xpol+40,round(LastVal+Values[i].per*330),10,true);
- PieSlice(PieX,PieY,LastArc,round(Lastarc+Values[i].per*360),Radius);
- end
- else if i = num_of_elem then
- begin
- Bar3d(Xpol,LastVal,Xpol+40,round(LastVal+Values[i].per*330),10,false);
- PieSlice(PieX,PieY,LastArc,360,Radius);
- end
- else
- begin
- Bar3d(Xpol,LastVal,Xpol+40,round(LastVal+Values[i].per*330),10,false);
- PieSlice(PieX,PieY,Lastarc,round(Lastarc+Values[i].per*360),Radius);
- end;
- LastVal := round(LastVal+Values[i].per*330);
- LastArc := round(LastArc+Values[i].per*360);
- end;
- Circle(PieX,PieY,Radius);
- end; {Chart}
- {-=====================================-}
- Begin
- GetValues;
- InitT;
- if type_of_diag = 1 then Chart else chart2;
- Readln;
- CloseGraph;
- End.
|