Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <limits.h>
  4.  
  5. using namespace std;
  6.  
  7. void MinMax(int n, double arr[], double &min, double &max){
  8. for(int i= 0; i<n; i++){
  9. if(arr[i] > max) max = arr[i];
  10. if(arr[i] < min) min = arr[i];
  11. }
  12. }
  13. void Points(int n, double vhx[], double vhy[], double x0, double y0, double xmin, double ymin, double Sx, double Sy, double Sp, double Sl){
  14. for(int i = 0; i < n; i++){
  15. int xp = x0+(vhx[i] - xmin);
  16. int yp = y0-(vhy[i] - ymin);
  17. putpixel(xp,yp,7);
  18. }
  19. for(int i = 1; i < n; i++){
  20. line(x0+vhx[i-1], y0-vhy[i-1], x0+vhx[i], y0-vhy[i]);
  21. }
  22. }
  23.  
  24. void Axis(int dir, double x0, double y0, double P, double D, double Min, double S){
  25. if(dir == 1){
  26. line(x0, y0, x0+P, y0);
  27. int Ip = P/D;
  28. for(int i = 0; i<Ip; i++){
  29. line(x0+i*D,y0,x0+i*D,y0+5);
  30. char k[100];
  31. gcvt(Min+i*D*S,3,k);
  32. outtextxy(x0+i*D,y0+15,k);
  33. }
  34. }
  35. else {
  36. line(x0, y0, x0, y0-P);
  37. int Jp = P/D;
  38. for(int j = 0; j < Jp; j++){
  39. line(x0,y0-j*D,x0-5,y0-j*D);
  40. char k[100];
  41. gcvt(Min+j*D*S,3,k);
  42. outtextxy(x0-35,y0-j*D-5,k);
  43. }
  44. }
  45. }
  46.  
  47. int main() {
  48. int n = 8;
  49. double x0 = 50;
  50. double y0 = 600;
  51. double Px = 600;
  52. double Py = 550;
  53. double Dx = 40;
  54. double Dy = 40;
  55. double vhx[8] = {17.8, 1.3, 391.4, 61.4, 0.15, 581.52, 195.1, 124.73};
  56. double vhy[8] = {93.4, 0.2, 13.4, 64.4, 150.2, 518.52, 135.1, 74.73};
  57. double minX = INT_MAX;
  58. double minY = INT_MAX;
  59. double maxX = INT_MIN;
  60. double maxY = INT_MIN;
  61. initwindow(800,800, "p1");
  62. MinMax(n, vhx, minX, maxX);
  63. MinMax(n, vhy, minY, maxY);
  64. double Sx = (maxX - minX)/Px;
  65. double Sy = (maxY - minY)/Py;
  66. //Points(n, vhx, vhy, x0, y0, minX, minY, Sx, Sy, 0, 0);
  67. Axis(1,x0,y0,Px,Dx,minX,Sx);
  68. Axis(0,x0,y0,Py,Dy,minY,Sy);
  69. getch();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement