Advertisement
Guest User

Untitled

a guest
May 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. Vector Vector::operator+(const Vector & v1)
  2. {
  3.  
  4. Vector result;
  5. result.x = this->x + v1.x;
  6. result.y = this->y + v1.y;
  7. result.z = this->z + v1.z;
  8. return result;
  9. }
  10.  
  11. int Vector::operator*(const Vector & v1)
  12. {
  13. float result;
  14. result = (this->x)*v1.get_x() + (this->y)*v1.get_y() + (this->z)*v1.get_z();
  15. return result;
  16. }
  17.  
  18. float Vector::get_x() const
  19. {
  20. return this->x;
  21. }
  22.  
  23. float Vector::get_y() const
  24. {
  25. return this->y;
  26. }
  27.  
  28. float Vector::get_z() const
  29. {
  30. return this->z;
  31. }
  32.  
  33.  
  34.  
  35. Vector::Vector(float _x, float _y, float _z)
  36. {
  37. this->x = _x;
  38. this->y = _y;
  39. this->z = _z;
  40. }
  41. const int value = 0;
  42. Vector::Vector():x(value),y(value),z(value)
  43. {
  44. ;
  45. }
  46.  
  47.  
  48.  
  49. Vector Vector::operator-(const Vector & v1)
  50. {
  51.  
  52. Vector result;
  53. result.x = this->x - v1.x;
  54. result.y = this->y - v1.y;
  55. result.z = this->z - v1.z;
  56. return result;
  57. }
  58.  
  59. Vector Vector::operator*(const int scalar)
  60. {
  61.  
  62. Vector result;
  63. result.x = this->x*scalar;
  64. result.y = this->y*scalar;
  65. result.z = this->z*scalar;
  66. return result;
  67.  
  68. }
  69.  
  70. void Vector:: print() const
  71. {
  72. std::cout << "(" << this->x << "," << this->y << "," << this->z << ")" << std::endl;
  73. }
  74.  
  75. void Vector::setter(float x, float y, float z)
  76. {
  77. this->x = x;
  78. this->y = y;
  79. this->z = z;
  80.  
  81.  
  82.  
  83. }
  84.  
  85.  
  86. std::istream & operator>>(std::istream & is, Vector& v1)
  87. {
  88. //float x, y, z;
  89. //is >> x >> y >> z;
  90. //v1.setter(v1.x, v1.y, v1.z);
  91. //std::cout <<std::endl;
  92.  
  93. return is >> v1.x >> v1.y >> v1.z;
  94. }
  95.  
  96. std::ostream & operator<<(std::ostream & os, const Vector& v1)
  97. {
  98. os << "(" << v1.x << "," << v1.y << "," << v1.z << ")";
  99. std::cout<<std::endl;
  100. return os;
  101. }
  102.  
  103. //
  104. //2
  105. std::istream & operator>>(std::istream & is, Matrix & m)
  106. {
  107. for (int i = 0; i < 3; i++)
  108. {
  109. for (int j = 0; j < 3; j++)
  110. {
  111. is >> m.matrix[i][j];
  112. }
  113. }
  114. return is;
  115. }
  116. std::ostream & operator<<(std::ostream & os, const Matrix & m)
  117. {
  118.  
  119. for (int i = 0; i < 3; i++)
  120. {
  121. for (int j = 0; j < 3; j++)
  122. {
  123. os << m.matrix[i][j] << " ";
  124. }
  125. os << std::endl;
  126. }
  127. return os;
  128. }
  129. Matrix::Matrix()
  130. {
  131. for (int i = 0; i < 3; i++)
  132. {
  133. for (int j = 0; j < 3; j++)
  134. {
  135. this->matrix[i][j] = 0;
  136. }
  137.  
  138. }
  139. }
  140. void Matrix::setter(int i, int j,int number)
  141. {
  142. this->matrix[i][j] = number;
  143. }
  144.  
  145. int Matrix::getter(int i, int j) const
  146. {
  147. return this->matrix[i][j];
  148. }
  149.  
  150. Matrix Matrix::operator*(int scalar)
  151. {
  152. Matrix tmp;
  153. for (int i = 0; i < 3; i++)
  154. {
  155. for (int j = 0; j < 3; j++)
  156. {
  157. tmp.matrix[i][j] = this->matrix[i][j] * scalar;
  158. }
  159. }
  160. return tmp;
  161. }
  162.  
  163. Matrix Matrix::operator*(Matrix another)
  164. {
  165. int sum = 0;
  166. int tmp[3][3];
  167. for (int i = 0; i < 3; i++)
  168. {
  169. for (int j = 0; j < 3; j++)
  170. {
  171. tmp[i][j] = 0;
  172. for (int k = 0; k < 3; k++)
  173. {
  174. tmp[i][j]+= (this->matrix[i][k])*(another.matrix[k][j]);
  175. }
  176.  
  177. }
  178.  
  179. }
  180. Matrix tmpo;
  181. for (int i = 0; i < 3; i++)
  182. {
  183. for (int j = 0; j < 3; j++)
  184. {
  185. tmpo.setter(i, j, tmp[i][j]);
  186. }
  187. }
  188. return tmpo;
  189. }
  190.  
  191. Matrix Matrix::operator++(int number)
  192. {
  193. Matrix old = *this;
  194. for (int i = 0; i < 3; i++)
  195. {
  196. for (int j = 0; j < 3; j++)
  197. {
  198. (this->matrix)[i][j]++;
  199. }
  200. }
  201. return old;
  202.  
  203. }
  204.  
  205. Matrix & Matrix::operator++()
  206. {
  207. for (int i = 0; i < 3; i++)
  208. {
  209. for (int j = 0; j < 3; j++)
  210. {
  211. (this->matrix)[i][j]++;
  212. }
  213. }
  214. return *this ;
  215. }
  216.  
  217. int Matrix::operator*()
  218. {
  219. return (matrix[0][0] * matrix[1][1] * matrix[2][2]);
  220. }
  221.  
  222. Matrix& Matrix::operator!()
  223. {int tmp= *(*this);
  224. if (tmp == 0)
  225. {
  226. std::cout << "There is no opposite matrix" << std::endl;
  227. return *this;
  228.  
  229. }
  230. else
  231. {
  232. std::cout << "There is an opposite matrix" << std::endl;
  233. return *this;
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement