Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / Labs 2004 / LABOR1 / LABOR1

.CPP
Скачиваний:
24
Добавлен:
16.04.2013
Размер:
3.4 Кб
Скачать
//бва®Ё¬ Ја дЁЄ дг­ЄжЁЁ ў DOS

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <process.h>
#include <math.h>

//а §¬Ґал ®Є­  ўлў®¤  ў ¬Ёа®ў®© бЁб⥬Ґ Є®®а¤Ё­ в
double xLeft, xRight, yBottom, yTop;
//а §¬Ґал ®Є­  ўлў®¤  ў ЇЁЄбҐ«пе ­  нЄа ­Ґ ¬®­Ёв®а 
int    nLeft, nRight, mBottom, mTop;


//ЇҐаҐе®¤ ®в x Є ЇЁЄбҐ«о n
inline int xn(double x)
{
	return (x - xLeft)/(xRight - xLeft)*(nRight - nLeft) + nLeft;
}

//ЇҐаҐе®¤ ®в y Є ЇЁЄбҐ«о m
inline int ym(double y)
{
	return (y - yBottom)/(yTop - yBottom)*(mTop - mBottom) + mBottom;
}



//Ї®¤Є«о祭ЁҐ Ја дЁзҐбЄ®© ЎЁЎ«Ё®вҐЄЁ
void RunGraphics()
{
  int mode, res, driver = DETECT;
  initgraph(&driver, &mode,"c:\\borlandc\\bgi");
  if((res = graphresult()) != grOk)
  {
	 printf("\nGraphics error: %s\n", grapherrormsg(res));
	 exit(1);
  }
}


void CreatWindow()
{
//®ЇаҐ¤Ґ«Ё¬ Ї®«Ґ ўлў®¤  ­  нЄа ­Ґ ¬®­Ёв®а 
//­ҐЄ®в®ал©  ­ «®Ј ®Є­  ў Windows
	int winLeft = 50, winRight = 550, winBottom = 430, winTop = 100;


	setfillstyle(SOLID_FILL,3);
	bar(winLeft, winTop, winRight, winBottom);

	setcolor(12);
	outtextxy(winLeft+5, winTop+7, "Korneev V");

	setcolor(15);
	outtextxy(winLeft+150, winTop+7, "Graphics to DOS");

	setcolor(15);
	rectangle(winLeft+3, winTop+17, winRight-3, winBottom-3);

  setfillstyle(SOLID_FILL,LIGHTGRAY);
	bar(winLeft+5, winTop+19, winRight-5, winBottom-5);

	setviewport(winLeft+5, winTop+19, winRight-5, winBottom-5,1);

}






void main()
{
//а §¬Ґал ®Є­  ў ¬Ёа®ўле Є®®а¤Ё­ в е Ё ў ЇЁЄбҐ«пе
	xLeft = -2; xRight =  10; yBottom =  -2; yTop =  2;
	nLeft = 100; nRight = 350; mBottom = 250; mTop = 50;



//Ї®¤Є«о祭ЁҐ Ја дЁзҐбЄ®© ЎЁЎ«Ё®вҐЄЁ
	RunGraphics();

//ᮧ¤ Ґ¬ Ї®«Ґ ўлў®¤ 
	CreatWindow();




//®д®а¬«пҐ¬ ®Є­® ўлў®¤  ­  нЄа ­Ґ ¬®­Ёв®а 

//гбв ­®ўЄ  ЄЁбвЁ: 1) бвЁ«м - бЇ«®и­®©
					//  2) 梥⠧ Єа бЄЁ - бЁ­Ё©
	setfillstyle(SOLID_FILL,BLUE);
	bar(nLeft,mBottom,nRight,mTop);
//гб ­®ўЄ  ЇҐа : 1) бвЁ«м - бЇ«®и­®©
				 //  2) в®«йЁ­  «Ё­Ё© - 3 ЇЁЄбҐ«п
				 //  3) 梥⠫Ё­Ё© - ЎҐ«л©
  setlinestyle(SOLID_LINE,0,3);
  setcolor(YELLOW);
	rectangle(nLeft,mBottom,nRight,mTop);

//аЁб㥬 Є®®а¤Ё­ в­лҐ ®бЁ

//гб ­®ўЄ  ЇҐа : 1) бвЁ«м - бЇ«®и­®©
				 //  2) в®«йЁ­  «Ё­Ё© - 1 ЇЁЄбҐ«п
				 //  3) 梥⠫Ё­Ё© - паЄ®-Ј®«гЎ®©
	setlinestyle(SOLID_LINE,0,1);
	setcolor(LIGHTCYAN);

	int nb, ne, mb, me;
	nb = xn(xLeft); mb = ym(0);
	ne = xn(xRight); me = ym(0);
	line(nb,mb,ne,me);

	nb = xn(0); mb = ym(yBottom);
	ne = xn(0); me = ym(yTop);
	line(nb,mb,ne,me);


//­ §ў ­ЁҐ Ја дЁЄ  Ё ®бҐ©
	setcolor(15);
	outtextxy((nLeft+nRight)/2-30, mTop+25, "Y = sin(X)");
	outtextxy(nLeft-35, (mBottom+mTop)/2, "Y");
	outtextxy((nLeft+nRight)/2, mBottom+25, "X");


//ўлў®¤Ё зЁб«  ў¤®«м ®бҐ©
  char ss[10];
  sprintf(ss,"%6.1lf",xLeft);
  outtextxy(nLeft-30,mBottom+7,ss);
  sprintf(ss,"%6.1lf",xRight);
  outtextxy(nRight-30,mBottom+7,ss);
  sprintf(ss,"%6.1lf",yBottom);
  outtextxy(nLeft-55,mBottom-7,ss);
  sprintf(ss,"%6.1lf",yTop);
  outtextxy(nLeft-55,mTop+3,ss);




//аЁб㥬 Ја дЁЄ бЁ­гб 
	int N = 50;
	double x, y, dx = (xRight - xLeft)/N;

	setcolor(12);
	x = xLeft; y = sin(x);
	nb = xn(x);  mb = ym(y);
	moveto(nb,mb);
	for(int i=1; i<=N; i++)
	{
		x = xLeft + dx*i; y = sin(x);
		nb = xn(x); mb = ym(y);
		lineto(nb,mb);
	}





	getch();
closegraph();
}
Соседние файлы в папке LABOR1