Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <conio.h>
- #include <stdio.h>
- #include <math.h>
- float newparam(float anb) {
- char sta[20];
- char cha;
- int ia=0;
- sta[ia]='\0';
- setcolor(3);
- rectangle(50, 320+anb, 150, 355+anb);
- setcolor(0);
- do {
- cha=getch();
- if((cha>='0')&&(cha<='9')) {
- sta[ia]+=cha;
- sta[ia+1]='\0';
- ia++;
- }
- switch(cha) {
- case '.':
- case '-':{
- sta[ia]+=cha;
- sta[ia+1]='\0';
- ia++;
- }break;
- case 8: {
- setfillstyle(1,15);
- bar(70,(331+anb)-5,70+strlen(sta)*8,(331+anb)+15);
- sta[strlen(sta)-1]='\0';
- ia--;
- }break;
- }
- outtextxy(70,331+anb,sta);
- }while(cha!=13);
- setcolor(0);
- rectangle(50, 320+anb, 150, 355+anb);
- float ab=atof(sta);
- //sprintf(st,a);рнгпdlya tablicy
- printf("%f",ab);
- return ab;
- }
- void tablenum(float a, float b)
- {
- int i;
- float x1, x2;
- char num1[100], num2[100];
- setcolor(0);
- for(i=-5; i<=5; i++)
- {
- x1=a*sin(i)+b*cos(i);
- sprintf(num1,"%.2f",x1);
- if((x1>0)||(x1==0)) sprintf(num1," %.2f",x1);
- outtextxy(135,170+18*i,num1);
- x2=a*tan(i)+b;
- sprintf(num2,"%.2f",x2);
- if((x2>0)||(x2==0)) sprintf(num2," %.2f",x2);
- outtextxy(220,170+18*i,num2);
- }
- }
- float f1(float a, float b, float xa)
- {
- float x;
- x=a*sin(xa)+b*cos(xa);
- return x;
- }
- float f2(float a, float b, float xa)
- {
- float x;
- x=a*tan(xa)+b;
- return x;
- }
- void grafic(float a,float b)
- {
- float xa;
- float xxa;
- float dxa=1.0/260;
- xa=-5;
- xxa=0;
- while(xa<=5)
- {
- if((50<(200-round(f1(a,b,xa))))&&(200-round(f1(a,b,xa))<360))
- {putpixel(350+round(xxa),200-round(f1(a,b,xa)),2);}
- if((50<(200-round(f2(a,b,xa))))&&(200-round(f2(a,b,xa))<360))
- {putpixel(350+round(xxa),200-round(f2(a,b,xa)),4);}
- xxa=xxa+0.1;
- xa=xa+dxa;
- //tablenum(a, b);
- }
- tablenum(a, b);
- }
- void gr()
- {
- setbkcolor(15);
- floodfill(200,200,WHITE);
- setcolor(0);
- rectangle(10, 30, 292, 280);
- line(104, 30, 104, 280);
- line(198, 30, 198, 280);
- line(320, 0, 320, 400);
- line(10, 70, 292, 70);
- line(0, 400, 639, 400);
- rectangle(50, 360, 150, 395);
- rectangle(50, 320, 150, 355);
- setcolor(0);
- char a[] = "a=", b[] = "b=", y[] = "Y", x[] = "X", o[] = "0", y1[] = "Y1", y2[] = "Y2";
- outtextxy(55, 331, a);
- outtextxy(55, 371, b);
- outtextxy(465, 35, y);
- outtextxy(605, 204, x);
- outtextxy(50, 45, x);
- outtextxy(145, 45, y1);
- outtextxy(225, 45, y2);
- outtextxy(470, 201, o);
- line(479, 40, 479, 360);//y
- line(350, 200, 610, 200);//x
- line(479, 40, 476, 43);
- line(479, 40, 482, 43);
- line(610, 200, 607, 197);
- line(610, 200, 607, 203);
- setcolor(0);
- rectangle(170,320,315,390);
- char *xt[12]={"-5","-4","-3","-2","-1","0","1","2","3","4","5","\0"};
- for(int i=-5; i<=5; i++)
- outtextxy(55,170+18*i,xt[i+5]);
- for(float i=350.0; i<=605.0;i=i+26)
- line(i,195,i,205);
- for(float j=50.0; j<=360.0;j=j+50)
- line(474,j,484,j);
- outtextxy(345,206,"-5");
- outtextxy(371,206,"-4");
- outtextxy(397,206,"-3");
- outtextxy(423,206,"-2");
- outtextxy(449,206,"-1");
- outtextxy(501,206,"1");
- outtextxy(527,206,"2");
- outtextxy(553,206,"3");
- outtextxy(579,206,"4");
- outtextxy(605,206,"5");//x
- outtextxy(490,45,"150");
- outtextxy(490,95,"100");
- outtextxy(490,145,"50");
- outtextxy(490,245,"-50");
- outtextxy(490,295,"-100");
- outtextxy(490,345,"-150");
- setcolor(2);
- outtextxy(180,330,"Y1=a*sin(x)+b*cos(x)");
- setcolor(4);
- outtextxy(180,370,"Y2=a*tg(x)+b");
- }
- void k(int x1, int y1, int x2, int y2, char *s, int col)
- {
- setcolor(col);
- rectangle(x1,y1,x2,y2);
- setcolor(0);
- outtextxy(x1+10,(y2-y1)/3+y1, s);
- }
- void knopkiupr()
- {
- char ch;
- int xr,yr;
- int nk=1;
- float a;
- float b;
- do {
- getmouseclick(WM_LBUTTONDOWN,xr,yr);
- if((xr>=470)&&(xr<=570)&&(yr>=420)&&(yr<=460)) {
- ch='e';
- k(50, 420,150,460, "NEW PARAM", 0);
- k(270, 420, 370,460, "GRAFIC", 0);
- k(470, 420, 570, 460, "EXIT", GREEN);}
- if((xr>=50)&&(xr<=150)&&(yr>=420)&&(yr<=460)) {
- k(50, 420,150,460, "NEW PARAM",GREEN );
- k(470, 420, 570, 460, "EXIT", 0);
- k(270, 420, 370,460, "GRAFIC", 0);
- setcolor(0);
- bar(70,325,145,350);
- bar(70,365,145,390);
- bar(110,75,190,280);
- bar(200,75,280,280);
- bar(350,40,610,360);
- line(479, 40, 479, 360);//y
- line(350, 200, 610, 200);//x
- for(float i=350.0; i<=605.0;i=i+26)
- line(i,195,i,205);
- for(float j=50.0; j<=360.0;j=j+50)
- line(474,j,484,j);
- outtextxy(465, 35, "Y");
- outtextxy(605, 204, "X");
- outtextxy(470, 201, "0");
- line(479, 40, 476, 43);
- line(479, 40, 482, 43);
- line(610, 200, 607, 197);
- line(610, 200, 607, 203);
- outtextxy(345,206,"-5");
- outtextxy(371,206,"-4");
- outtextxy(397,206,"-3");
- outtextxy(423,206,"-2");
- outtextxy(449,206,"-1");
- outtextxy(501,206,"1");
- outtextxy(527,206,"2");
- outtextxy(553,206,"3");
- outtextxy(579,206,"4");
- outtextxy(605,206,"5");//x
- outtextxy(490,45,"150");
- outtextxy(490,95,"100");
- outtextxy(490,145,"50");
- outtextxy(490,245,"-50");
- outtextxy(490,295,"-100");
- outtextxy(490,345,"-150");
- a=newparam(0.0);
- b=newparam(40.0);
- }
- if((xr>=270)&&(xr<=370)&&(yr>=420)&&(yr<=460)) {
- grafic(a,b);
- k(270, 420, 370,460, "GRAFIC",GREEN );
- k(50, 420,150,460, "NEW PARAM", 0);
- k(470, 420, 570, 460, "EXIT", 0);
- }
- if(kbhit()) {
- ch = getch();
- switch (ch)
- {
- case 'n':{
- k(50, 420,150,460, "NEW PARAM",GREEN );
- k(470, 420, 570, 460, "EXIT", 0);
- k(270, 420, 370,460, "GRAFIC", 0);
- setcolor(0);
- bar(70,325,145,350);
- bar(70,365,145,390);
- bar(110,75,190,280);
- bar(200,75,280,280);
- bar(350,40,610,360);
- line(479, 40, 479, 360);//y
- line(350, 200, 610, 200);//x
- for(float i=350.0; i<=605.0;i=i+26)
- line(i,195,i,205);
- for(float j=50.0; j<=360.0;j=j+50)
- line(474,j,484,j);
- outtextxy(465, 35, "Y");
- outtextxy(605, 204, "X");
- outtextxy(470, 201, "0");
- line(479, 40, 476, 43);
- line(479, 40, 482, 43);
- line(610, 200, 607, 197);
- line(610, 200, 607, 203);
- outtextxy(345,206,"-5");
- outtextxy(371,206,"-4");
- outtextxy(397,206,"-3");
- outtextxy(423,206,"-2");
- outtextxy(449,206,"-1");
- outtextxy(501,206,"1");
- outtextxy(527,206,"2");
- outtextxy(553,206,"3");
- outtextxy(579,206,"4");
- outtextxy(605,206,"5");//x
- outtextxy(490,45,"150");
- outtextxy(490,95,"100");
- outtextxy(490,145,"50");
- outtextxy(490,245,"-50");
- outtextxy(490,295,"-100");
- outtextxy(490,345,"-150");
- a=newparam(0.0);
- b=newparam(40.0);
- } break;
- case 'g':{
- k(270, 420, 370,460, "GRAFIC",GREEN );
- k(50, 420,150,460, "NEW PARAM", 0);
- k(470, 420, 570, 460, "EXIT", 0);
- }
- grafic(a,b); break;
- case 'e':{
- k(50, 420,150,460, "NEW PARAM", 0);
- k(270, 420, 370,460, "GRAFIC", 0);
- k(470, 420, 570, 460, "EXIT", GREEN);
- ch='e';
- } break;
- case 77:
- if(nk<3)
- nk++;
- k(50, 420,150,460, "NEW PARAM", 0);
- k(270, 420, 370,460, "GRAFIC", 0);
- k(470, 420, 570, 460, "EXIT", 0);
- switch(nk){
- case 1: k(50, 420,150,460, "NEW PARAM", GREEN);break;
- case 2: k(270, 420, 370,460, "GRAFIC", GREEN);break;
- case 3: k(470, 420, 570, 460, "EXIT", GREEN);}break;
- case 75:
- if(nk>1) nk--;
- k(50, 420,150,460, "NEW PARAM", 0);
- k(270, 420, 370,460, "GRAFIC", 0);
- k(470, 420, 570, 460, "EXIT", 0);
- switch(nk){
- case 1: k(50, 420,150,460, "NEW PARAM", GREEN); break;
- case 2: k(270, 420, 370,460, "GRAFIC", GREEN); break;
- case 3: k(470, 420, 570, 460, "EXIT", GREEN); break;
- }break;
- case 13:
- switch(nk) {
- case 1:
- setcolor(0);
- bar(70,325,145,350);
- bar(70,365,145,390);
- bar(110,75,190,280);
- bar(200,75,280,280);
- bar(350,40,610,360);
- line(479, 40, 479, 360);//y
- line(350, 200, 610, 200);//x
- for(float i=350.0; i<=605.0;i=i+26)
- line(i,195,i,205);
- for(float j=50.0; j<=360.0;j=j+50)
- line(474,j,484,j);
- outtextxy(465, 35, "Y");
- outtextxy(605, 204, "X");
- outtextxy(470, 201, "0");
- line(479, 40, 476, 43);
- line(479, 40, 482, 43);
- line(610, 200, 607, 197);
- line(610, 200, 607, 203);
- outtextxy(345,206,"-5");
- outtextxy(371,206,"-4");
- outtextxy(397,206,"-3");
- outtextxy(423,206,"-2");
- outtextxy(449,206,"-1");
- outtextxy(501,206,"1");
- outtextxy(527,206,"2");
- outtextxy(553,206,"3");
- outtextxy(579,206,"4");
- outtextxy(605,206,"5");//x
- outtextxy(490,45,"150");
- outtextxy(490,95,"100");
- outtextxy(490,145,"50");
- outtextxy(490,245,"-50");
- outtextxy(490,295,"-100");
- outtextxy(490,345,"-150");
- a=newparam(0.0);
- b=newparam(40.0);
- break;
- case 2:grafic(a,b); break;
- case 3: ch='e'; break;
- }
- }
- }
- } while (ch!='e');
- }
- int main(void)
- {
- int GrDr, GrMod, rez;
- GrDr = DETECT;
- initgraph(&GrDr, &GrMod, " "); // GrDr - графический драйвер;
- //GrMod -графический режим;
- // третий параметр- путь до графического //драйвера;
- rez = graphresult();
- if (rez != grOk)
- {
- printf("\n Error graph modeи");
- return(1);
- }
- gr();
- k(50, 420,150,460, "NEW PARAM", GREEN);
- k(270, 420, 370,460, "GRAFIC", 0);
- k(470, 420, 570, 460, "EXIT", 0);
- knopkiupr();
- closegraph();
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement