Advertisement
brospresident

Untitled

Oct 24th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. class Point {
  10. private:
  11. double x;
  12. double y;
  13. double z;
  14.  
  15. public:
  16. Point() {
  17. this->x = 0;
  18. this->y = 0;
  19. this->z = 0;
  20. }
  21.  
  22. Point(double X, double Y) {
  23. this->x = X;
  24. this->y = Y;
  25. this->z = 0;
  26. }
  27.  
  28. Point(double X, double Y, double Z) {
  29. this->x = X;
  30. this->y = Y;
  31. this->z = Z;
  32. }
  33.  
  34. double getX() {
  35. return this->x;
  36. }
  37.  
  38. double getY() {
  39. return this->y;
  40. }
  41.  
  42. double getZ() {
  43. return this->z;
  44. }
  45.  
  46. double getRadius() {
  47. return sqrt(pow(this->x, 2) + pow(this->y, 2) + pow(this->z, 2));
  48. }
  49.  
  50. double getPhi() {
  51. double arg = this->y / this->x;
  52. if (this->x >= 0) {
  53. return atan(arg);
  54. }
  55. return atan(arg) + M_PI;
  56. }
  57.  
  58. double getTheta() {
  59. if (this->z == 0) return 0;
  60.  
  61. double arg = sqrt(pow(this->x, 2) + pow(this->y, 2)) / this->z;
  62.  
  63. return atan(arg);
  64. }
  65.  
  66. };
  67.  
  68. int main () {
  69. double X, Y, Z;
  70.  
  71. string line;
  72. while (getline(cin, line)) {
  73. vector<double> numbers;
  74. stringstream ss(line);
  75.  
  76. for (double i; ss >> i; ) {
  77. numbers.push_back(i);
  78. if (ss.peek() == ';') {
  79. ss.ignore();
  80. }
  81.  
  82. if (ss.peek() == ' ') {
  83. double X = numbers[0], Y = numbers[1], Z = numbers[2];
  84. if (X && Y && Z) {
  85. Point p(X, Y, Z);
  86.  
  87. cout << "r=" << p.getRadius() << "; phi=" << p.getPhi() << "; theta=" << p.getTheta() << endl;
  88. }
  89. else if (X && Y) {
  90. Point p(X, Y);
  91. cout << "r=" << p.getRadius() << "; phi=" << p.getPhi() << endl;
  92. }
  93.  
  94. numbers.clear();
  95. }
  96. }
  97.  
  98. }
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement