include stdio include graphics include math define getmaxx define getm

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define x getmaxx()
#define y getmaxy()
#define N 20
void DrawGraph(int kol,float mas1[],float mas2[])
{ int driver,mode,rez,i,lenx,leny,grx,gry,depth,points1[14],points2[14];
float max,kx,ky;
char st[20];
clrscr();
driver=9;
mode=2;
initgraph(&driver,&mode,"");
rez=graphresult();
if(rez!=grOk)
{ printf ("Oshibka inicializacii grafiki");
getch();
return;
}
grx=x/13;
gry=y*11/12;
setcolor(15);
settextstyle(8,0,1);
settextjustify(1,2);
outtextxy(x/2,5,"2 Diagrammy");
setcolor(2);
line(grx,y-gry,grx,gry);
line(grx,y-gry,floor(grx*1.1+0.5),floor((y-gry)*1.3+0.5));
line(grx,y-gry,floor(grx*0.9+0.5),floor((y-gry)*1.3+0.5));
line(grx,gry,x-grx,gry);
line(x-grx,gry,floor(x-grx*1.3+0.5),floor(gry*1.01+0.5));
line(x-grx,gry,floor(x-grx*1.3+0.5),floor(gry*0.99+0.5));
lenx=x*10/13;
leny=y*3/4;
max=mas1[0];
for(i=0;i<kol;i++)
{ if(mas1[i]>max) max=mas1[i];
if(mas2[i]>max) max=mas2[i];
}
ky=max/(float)leny;
kx=lenx/(4.0*kol);
depth=floor(kx/1.5+0.5);
settextstyle(0,0,1);
settextjustify(2,1);
for(i=1;i<=10;i++)
{ line(floor(grx*0.9+0.5),gry-(leny*i/10),floor(grx*1.1+0.5),gry-(leny*i/10));
line(grx,gry-(leny*i/10),grx+depth*2,gry-(leny*i/10)-floor(depth*1.65+0.5));
line(grx+depth*2,gry-(leny*i/10)-floor(depth*1.65+0.5),grx+depth*2+lenx,gry-(leny*i/10)-floor(depth*1.65+0.5));
sprintf(st,"%.2f",max*i/10.);
setcolor(15);
outtextxy(floor(grx*0.9+0.5),gry-(leny*i/10),st);
setcolor(2);
}
line(grx,gry,grx+depth*2,gry-floor(depth*1.65+0.5));
line(grx+depth*2,gry-floor(depth*1.65+0.5),grx+depth*2+lenx,gry-floor(depth*1.65+0.5));
for(i=0;i<kol;i++)
{
points1[0]=grx+floor(kx*(4*i+3)+0.5);
points1[1]=gry-floor(depth*0.15+0.5);
points1[2]=points1[0]+depth;
points1[3]=points1[1]-floor(depth*0.6+0.5);
points1[4]=points1[2];
points1[5]=points1[3]-floor(mas1[i]/ky+0.5);
points1[6]=points1[4]-floor(2*kx+0.5);
points1[7]=points1[5];
points1[8]=points1[6]-depth;
points1[9]=points1[7]+floor(depth*0.6+0.5);
points1[10]=points1[8]+floor(2*kx+0.5);
points1[11]=points1[9];
points2[0]=grx+floor(kx*(4*i+4.5)+0.5);
points2[1]=gry-floor(depth*1.2+0.5);
points2[2]=points2[0]+depth;
points2[3]=points2[1]-floor(depth*0.6+0.5);
points2[4]=points2[2];
points2[5]=points2[3]-floor(mas2[i]/ky+0.5);
points2[6]=points2[4]-floor(2*kx+0.5);
points2[7]=points2[5];
points2[8]=points2[6]-depth;
points2[9]=points2[7]+floor(depth*0.6+0.5);
points2[10]=points2[8]+floor(2*kx+0.5);
points2[11]=points2[9];
setcolor(10);
setfillstyle(1,10);
bar(grx+floor(kx*(4*i+2.5)+0.5),gry-floor(depth*1.2+0.5),grx+floor(kx*(4*i+4.5)+0.5),gry-floor(mas2[i]/ky+depth*1.2+0.5));
setfillstyle(1,2);
fillpoly(6,points2);
line(points2[10],points2[11],points2[4],points2[5]);
setcolor(12);
setfillstyle(1,12);
bar(grx+floor(kx*(4*i+1)+0.5),gry-floor(depth*0.15+0.5),grx+floor(kx*(4*i+3)+0.5),gry-floor(mas1[i]/ky+depth*0.15+0.5));
setfillstyle(1,4);
fillpoly(6,points1);
line(points1[10],points1[11],points1[4],points1[5]);
setcolor(15);
sprintf(st,"%d",i+1);
outtextxy((points1[8]+points1[10])/2,floor(gry*1.02+0.5),st);
}
outtextxy(grx-10,floor(gry*1.02+0.5),"0");
outtextxy(grx-2,y-gry-5,"Y");
outtextxy(x-grx+10,gry,"X");
}
main (void)
{ int kol;
float diag1[N],diag2[N];
FILE *f;
f=fopen("input.txt","r");
for(kol=0;!feof(f) && kol<N;kol++)
{ fscanf(f,"%f",&diag1[kol]);
fscanf(f,"%f",&diag2[kol]);
}
DrawGraph(kol,diag1,diag2);
getch();
}