Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <graphics.h>
- using namespace std;
- const int n=8;
- void MinMax(int n,double arr[],double &min, double &max)
- {
- min=arr[0];
- max=arr[0];
- for(int i=0; i<n; i++)
- {
- if(arr[i]<min) min=arr[i];
- if(arr[i]>max) max=arr[i];
- }
- cout<<"Min: "<<min<<endl;
- cout<<"Max: "<<max<<endl;
- }
- void Points(int n,double arr[],double arr1[],int x0, int y0, double xmin, double ymin,double sx, double sy,int sp, int sl)
- {
- double Xp, Yp;
- for(int i=0; i<n; i++)
- {
- Xp=x0+(arr[i]-xmin)/sx;
- Yp=y0-(arr1[i]-ymin)/sy;
- switch(sp)
- {
- case 0: putpixel(Xp,Yp,6);
- case 1: circle(Xp,Yp,5);
- case 2: line(Xp-2,Yp,Xp+2,Yp);
- line(Xp,Yp-2,Xp,Yp+2);
- case 3: line(Xp-2,Yp-2,Xp+2,Yp+2);
- line(Xp-2,Yp+2,Xp+2,Yp-2);
- }
- if(sl==1)
- {
- if(i==0)
- moveto(Xp,Yp);
- else lineto(Xp,Yp);
- }
- }
- }
- void Axis(int dir,int x0, int y0, int P, int D, double min, double S)
- {
- char t[20];
- if(dir==0) // ΠΏΠΎ x
- {
- settextjustify(1,2);
- line(x0,y0,x0+P,y0);
- int I = P/D-1;
- for(int i=0; i < I; i++)
- {
- line(x0+i*D,y0,x0+i*D,y0+5);
- gcvt(min+i*D*S,6.2, t);
- outtextxy(x0+i*D,y0+10, t);
- }
- }
- else if(dir==1)
- {
- settextjustify(2,1);
- line(x0,y0,x0,y0-P);
- int I = P/D-1;
- for(int i=0; i < I; i++)
- {
- line(x0,y0-i*D,x0-5,y0-i*D);
- gcvt(min+i*D*S,6.2, t);
- outtextxy(x0-10,y0-i*D,t);
- }
- }
- }
- int main()
- {
- initwindow(800,800);
- int x0=100; int y0=600;
- int Px=600; int Py=550;
- int Dx=40; int Dy=40;
- double VhodX[8]={0.2,1.3,2.4,5.6,4.4,7.8,6.7,11.6};
- double VhodY[8]={10.3,9.8,4.5,6.7,3.3,2.2,8.9,13.6};
- double xmin,xmax,ymin,ymax;
- cout<<"Point x: "<<endl;
- MinMax(n,VhodX,xmin,xmax);
- cout<<"Point y: "<<endl;
- MinMax(n,VhodY,ymin,ymax);
- double Sx=(xmax-xmin)/Px;
- double Sy=(ymax-ymin)/Py;
- cout<<"Sx= "<<Sx<<endl;
- cout<<"Sy= "<<Sy<<endl;
- setcolor(9);
- Points(n,VhodX,VhodY,x0,y0,xmin,ymin,Sx,Sy,3,1);
- Axis(0,x0,y0,Px,Dx,xmin,Sx);
- Axis(1,x0,y0,Py,Dy,ymin,Sy);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement