Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовые / Курсовые ЭТМО / 04 / RAB
.CPP#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <math.h>
int centerX=40; /* koordinates of center */
int centerY=430;
float minxval=0; /* diapazons of values */
float maxxval=2000;
float minyval=0;
float maxyval=50;
float scaleX=400; /* value: ed/unit */
float scaleY=10;
int stepX=100; /* graphics: pixels/unit */
int stepY=75;
int Del=10; /* kol-vo delenii / unit */
int df=3; /* dlinna shtriha for delenii */
int pr=0; /* otstup setki ot kraev (units) */
int ot=5; /* otstup osei ot kraev */
int sk=13; /* otstup ot verha for text */
int Delay=0; /* pause between pixels */
float t1=0.01; /* param T1 */
char *path="i:\\borlandc\\bgi";
/* path for egavga.cpi */
int driver,mode,errorcode;
void setka();
void logo();
void graphic(float);
void initialization();
int ask();
float quest();
//---------------------------------------------------------
void main()
{
int i,t;
initialization(); /* initialization of graphics */
logo();
setka(); /* print the cells */
t=ask(); /* asking the amount of graphics */
for (i=1; i<=t; i++)
{
setcolor(i+1); /* setting the color of graphic */
graphic(quest()); /* drawing graphics */
}
if (t>0) getch();
closegraph();
}
//------- initialization of graphics --------------------
void initialization()
{
driver=DETECT;
mode=0;
initgraph(&driver,&mode,path);
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key....");
getch();
exit(1); /* terminate program if error */
}
}
//------- cells drawing --------------------------------
void setka()
{
int ax,bx,ay,by,c;
int x,y;
int maxX=getmaxx(); /* detecting max pixel amount */
int maxY=getmaxy();
char *val;
bx=div(centerX,stepX).quot
+div(maxX-centerX,stepX).quot;
/* amount of the sells */
ax=div(centerX,stepX).rem;
/* otstup ot kraya to 1st cell */
by=div(centerY,stepY).quot
+div(maxY-centerY,stepY).quot;
/* amount of then cells */
ay=div(centerY,stepY).rem;
/* otstup ot kraya to 1st sell */
setcolor(LIGHTGREEN);
/* outputting shtrihov */
/* OX */ /* OX */
for (x=Del*pr; x<=Del*(bx-pr) ; x++)
{
c=ax+x*stepX/Del;
line(c,centerY-df,c,centerY+df);
}
/* OY */
for (y=Del*pr; y<=Del*(by-pr) ; y++)
{
c=ay+y*stepY/Del;
line(centerX-df,c,centerX+df,c);
}
setcolor(LIGHTBLUE);
/* cells */
/* horizontal lines */ /* horizontal lines */
for (x=pr; x<=bx-pr ; x++)
{
c=ax+x*stepX;
line(c,ay+pr*stepY,c,ay+(by-pr)*stepY);
moveto(c+3,centerY+5);
itoa(x*scaleX, val, 10);
outtext(val);
}
/* vertical lines */
for (y=pr; y<=by-pr ; y++)
{
c=ay+y*stepY;
line(ax+pr*stepX,c,ax+(bx-pr)*stepX,c);
moveto(centerX+3,c+5);
itoa((by-pr-y)*scaleY, val, 10);
outtext(val);
}
setcolor(WHITE);
/* Osi s metkami */
line(ot,centerY,maxX-ot,centerY);
line(centerX,ot+sk,centerX,maxY-ot);
moveto(maxX-5-ot,centerY-3);
outtext(">");
moveto(centerX-3,ot+sk);
outtext("^");
moveto(maxX-8-ot,centerY+5);
outtext("w");
moveto(centerX+7,ot+2+sk);
outtext("F");
}
//--------- zapros kolichestva graphikov ----------------
int ask()
{
int bg;
gotoxy(1,1);
printf("Enter amount of graphics: ");
gotoxy(30,1);
scanf("%d",&bg);
gotoxy(1,1);
printf(" ");
gotoxy(30,1);
return(bg);
}
//--------- zapros koeffitsienta B ----------------------
float quest()
{
float bg;
gotoxy(1,1);
printf("Enter the B value ");
gotoxy(30,1);
scanf("%f",&bg);
/* Proverka godnosti znachenii */
while ((bg>0.8)||(bg<0.2))
{
gotoxy(1,1);
printf("Plase, enter correct value ");
gotoxy(30,1);
scanf("%f",&bg);
}
gotoxy(1,1);
printf(" ");
gotoxy(30,1);
return(bg); /* Vozvrat kolichestva graphicov */
}
//---------- Graphic drawing ---------------------------
void graphic(float kb)
{
int i;
float x,y,lx,ly;
int maxX=getmaxx();
/* Proverka godnosti znachenii */
lx=0;
ly=0;
for (i=0; i<maxX; i++)
{
x=i-centerX;
x=x/stepX;
x=x*scaleX; /* Vichislenie znacheniya X ot i */
y=atan(x*t1)-atan(x*kb*t1);
y=180*y/3.141528;/* Vychislenie znacheniya Y ot X */
y=(y/scaleY);
y=y*stepY; /* Find koord Y ot ego znacheniya*/
delay(Delay);
moveto(lx,ly); /* set previous koord of line */
lx=i;
ly=centerY-y;
//if ((x>=minxval)&(x<=maxxval))
if (i>=1) lineto(lx,ly);
}
}
//---------- Logo ---------------------------------------
void logo()
{
setfillstyle(SOLID_FILL,YELLOW);
bar(20,20,getmaxx()-20,100);
setcolor(0);
outtextxy(50,30," Kursach po OOP");
outtextxy(50,50," Studenta gruppy ETMO - 24 Pasjutina Antona");
outtextxy(50,70," na temu: 'Fazochastotnye harakteristiki'");
setfillstyle(SOLID_FILL,BLUE);
bar(20,120,getmaxx()-20,270);
setcolor(WHITE);
outtextxy(50,130," Tehnicheskoe zadanie. ");
outtextxy(50,150," Postroit' semeistvo krivwh - fazochastotnyh harakteristik");
outtextxy(50,170,"dinamicheskogo zvena po formule F(w)=arctg(wT1)-arctg(wT2), ");
outtextxy(50,190,"gde T1=10mc, T2=B*T1, B vvoditsya v dialogovom rezhime 0.2<=B<=0.8");
outtextxy(50,210," Kolichestvo krivyh vvoditsya takzhe v dialogovom rezhime ");
outtextxy(50,230," OX: 0..2000 c-1 shag 400 c-1");
outtextxy(50,250," OY: 0..50 grad shag 50 grad");
setfillstyle(SOLID_FILL,RED);
bar(20,290,getmaxx()-20,330);
setcolor(YELLOW);
outtextxy(50,305,"Press any key to continue...");
getch();
setfillstyle(SOLID_FILL,BLACK);
bar(1,1,getmaxx(),getmaxy()) ;
}
//---------------------------------------------------------