Guest User

Untitled

a guest
Dec 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct vect {
  9. double x;
  10. double y;
  11. double z;
  12. };
  13.  
  14. void show(vect, int = 4);
  15.  
  16. vect summ(vect, vect);
  17.  
  18. vect sub(vect, vect);
  19.  
  20. vect multi(vect, double);
  21.  
  22. vect multi(double, vect);
  23.  
  24. vect multi(vect, vect);
  25.  
  26. int main(int count, char *args[]) {
  27. vect a{};
  28. a.x = 1;
  29. a.y = 2;
  30. a.z = 3;
  31. vect b{};
  32. b.x = 4;
  33. b.y = -5;
  34. b.z = 6;
  35. auto c = multi(a, b);
  36. show(c, 2);
  37. }
  38.  
  39. vect summ(vect a, vect b) {
  40. vect c{};
  41. c.x = a.x + b.x;
  42. c.y = a.y + b.y;
  43. c.z = a.z + b.z;
  44. return c;
  45. }
  46.  
  47. vect sub(vect a, vect b) {
  48. vect c{};
  49. c.x = a.x - b.x;
  50. c.y = a.y - b.y;
  51. c.z = a.z - b.z;
  52. return c;
  53. }
  54.  
  55. vect multi(vect in, double num) {
  56. vect res{};
  57. res.x = in.x * num;
  58. res.y = in.y * num;
  59. res.z = in.z * num;
  60. return res;
  61. }
  62.  
  63. vect multi(double num, vect in) {
  64. return multi(in, num);
  65. }
  66.  
  67. vect multi(vect a, vect b) {
  68. vect res{};
  69. res.x = a.y * b.z - b.y * a.z;
  70. res.y = a.z * b.x - b.z * a.x;
  71. res.z = a.x * b.y - b.x * a.y;
  72. return res;
  73. }
  74.  
  75. void show(vect shown, int size) {
  76. cout << "(" << setw(size) << shown.x << ";" << setw(size) << shown.y << ";" << setw(size) << shown.z << ")" << endl;
  77. }
Add Comment
Please, Sign In to add comment