Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Circle{
  4. float radius;
  5. float CenterX;
  6. float CenterY;
  7. };
  8.  
  9. struct Vec
  10. {
  11. float x;
  12. float y;
  13. };
  14.  
  15. struct Matrix{
  16. float a[3][3];
  17. };
  18.  
  19. void intpart(float*);
  20. void intpart(float&);
  21.  
  22. void change(float*);
  23. void change(float&);
  24.  
  25. void move(Circle*,Vec*);
  26. void move(Circle&,Vec&);
  27.  
  28. void multiply(Matrix*,float*);
  29. void multiply(Matrix&,float&);
  30.  
  31. void intpart(float *a)
  32. {
  33. *a = int(*a);
  34. }
  35. void intpart(float &a)
  36. {
  37. a=int(a);
  38. }
  39.  
  40. void change(float *a) {
  41. *a = -1 * (*a);
  42. }
  43.  
  44. void change(float &a)
  45. {
  46. a=-1*a;
  47. }
  48.  
  49. void move(Circle *a,Vec *b)
  50. {
  51. a->CenterX= a->CenterX + b->x;
  52. a->CenterY = a->CenterY+ b->y;
  53. }
  54.  
  55. void move(Circle &a,Vec &b)
  56. {
  57. a.CenterX+=b.x;
  58. a.CenterY+=b.y;
  59. }
  60.  
  61. void multiply(Matrix *a,float *b)
  62. {
  63. for(int i=0;i<3;i++)
  64. for(int j=0;j<3;j++)
  65. a->a[i][j] *= *b;
  66. }
  67.  
  68. void multiply(Matrix &a,float &b)
  69. {
  70. for(int i=0;i<3;i++)
  71. for(int j=0;j<3;j++)
  72. a.a[i][j] *= b;
  73. }
  74. int main() {
  75. float num = 3.65;
  76. float &numRef = num;
  77. intpart(&num);
  78. intpart(numRef);
  79. std::cout << num << " " << numRef << std::endl;
  80.  
  81. float num1 = -3.789;
  82. float num2 = 4.5;
  83. float &num2Ref = num2;
  84. change(&num1);
  85. change(num2Ref);
  86. std::cout << num1 << " " << num2 << std::endl;
  87.  
  88. Circle k;
  89. k.radius = 4;
  90. k.CenterX = 5;
  91. k.CenterY = 6;
  92. Vec a;
  93. a.x = 2;
  94. a.y = 2;
  95. Circle &kRef = k;
  96. Vec &aRef = a;
  97. move(&k, &a);
  98. move(kRef,aRef);
  99. std::cout << k.CenterX << " " << k.CenterY << std::endl;
  100. std::cout << kRef.CenterX << " " << kRef.CenterY << std::endl;
  101.  
  102. Matrix p, l;
  103. int v = 0;
  104. for (int i = 0; i < 3; i++)
  105. for (int j = 0; j < 3; j++) {
  106. p.a[i][j] = v;
  107. l.a[i][j] = v;
  108. v++;
  109. }
  110. float b = -3;
  111. multiply(&p, &b);
  112. for (int i = 0; i < 3; i++){
  113. for (int j = 0; j < 3; j++) {
  114. std::cout << p.a[i][j] << " ";
  115. }
  116. std::cout<<std::endl;
  117. }
  118. Matrix& lRef = l;
  119. float& bRef = b;
  120. multiply(lRef,bRef);
  121. for (int i = 0; i < 3; i++){
  122. for (int j = 0; j < 3; j++) {
  123. std::cout << l.a[i][j] << " ";
  124. }
  125. std::cout<<std::endl;
  126. }
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement