Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3.  
  4. using namespace std;
  5.  
  6. const int n=8;
  7. void MinMax(int n,double arr[],double &min, double &max)
  8. {
  9. min=arr[0];
  10. max=arr[0];
  11.  
  12. for(int i=0; i<n; i++)
  13. {
  14. if(arr[i]<min) min=arr[i];
  15. if(arr[i]>max) max=arr[i];
  16. }
  17. cout<<"Min: "<<min<<endl;
  18. cout<<"Max: "<<max<<endl;
  19. }
  20. void Points(int n,double arr[],double arr1[],int x0, int y0, double xmin, double ymin,double sx, double sy,int sp, int sl)
  21. {
  22. double Xp, Yp;
  23. for(int i=0; i<n; i++)
  24. {
  25. Xp=x0+(arr[i]-xmin)/sx;
  26. Yp=y0-(arr1[i]-ymin)/sy;
  27. switch(sp)
  28. {
  29. case 0: putpixel(Xp,Yp,6);
  30. case 1: circle(Xp,Yp,5);
  31. case 2: line(Xp-2,Yp,Xp+2,Yp);
  32. line(Xp,Yp-2,Xp,Yp+2);
  33. case 3: line(Xp-2,Yp-2,Xp+2,Yp+2);
  34. line(Xp-2,Yp+2,Xp+2,Yp-2);
  35. }
  36. if(sl==1)
  37. {
  38. if(i==0)
  39. moveto(Xp,Yp);
  40. else lineto(Xp,Yp);
  41. }
  42. }
  43. }
  44. void Axis(int dir,int x0, int y0, int P, int D, double min, double S)
  45. {
  46. char t[20];
  47.  
  48. if(dir==0) // ΠΏΠΎ x
  49. {
  50. settextjustify(1,2);
  51. line(x0,y0,x0+P,y0);
  52. int I = P/D-1;
  53. for(int i=0; i < I; i++)
  54. {
  55. line(x0+i*D,y0,x0+i*D,y0+5);
  56.  
  57. gcvt(min+i*D*S,6.2, t);
  58. outtextxy(x0+i*D,y0+10, t);
  59. }
  60. }
  61. else if(dir==1)
  62. {
  63. settextjustify(2,1);
  64. line(x0,y0,x0,y0-P);
  65. int I = P/D-1;
  66. for(int i=0; i < I; i++)
  67. {
  68. line(x0,y0-i*D,x0-5,y0-i*D);
  69.  
  70. gcvt(min+i*D*S,6.2, t);
  71. outtextxy(x0-10,y0-i*D,t);
  72. }
  73. }
  74. }
  75.  
  76. int main()
  77. {
  78. initwindow(800,800);
  79. int x0=100; int y0=600;
  80. int Px=600; int Py=550;
  81. int Dx=40; int Dy=40;
  82. double VhodX[8]={0.2,1.3,2.4,5.6,4.4,7.8,6.7,11.6};
  83. double VhodY[8]={10.3,9.8,4.5,6.7,3.3,2.2,8.9,13.6};
  84. double xmin,xmax,ymin,ymax;
  85. cout<<"Point x: "<<endl;
  86. MinMax(n,VhodX,xmin,xmax);
  87. cout<<"Point y: "<<endl;
  88. MinMax(n,VhodY,ymin,ymax);
  89.  
  90. double Sx=(xmax-xmin)/Px;
  91. double Sy=(ymax-ymin)/Py;
  92. cout<<"Sx= "<<Sx<<endl;
  93. cout<<"Sy= "<<Sy<<endl;
  94. setcolor(9);
  95. Points(n,VhodX,VhodY,x0,y0,xmin,ymin,Sx,Sy,3,1);
  96. Axis(0,x0,y0,Px,Dx,xmin,Sx);
  97. Axis(1,x0,y0,Py,Dy,ymin,Sy);
  98. getch();
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement