Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <sstream>
- using namespace std;
- class Point {
- private:
- double x;
- double y;
- double z;
- public:
- Point() {
- this->x = 0;
- this->y = 0;
- this->z = 0;
- }
- Point(double X, double Y) {
- this->x = X;
- this->y = Y;
- this->z = 0;
- }
- Point(double X, double Y, double Z) {
- this->x = X;
- this->y = Y;
- this->z = Z;
- }
- double getX() {
- return this->x;
- }
- double getY() {
- return this->y;
- }
- double getZ() {
- return this->z;
- }
- double getRadius() {
- return sqrt(pow(this->x, 2) + pow(this->y, 2) + pow(this->z, 2));
- }
- double getPhi() {
- double arg = this->y / this->x;
- if (this->x >= 0) {
- return atan(arg);
- }
- return atan(arg) + M_PI;
- }
- double getTheta() {
- if (this->z == 0) return 0;
- double arg = sqrt(pow(this->x, 2) + pow(this->y, 2)) / this->z;
- return atan(arg);
- }
- };
- int main () {
- double X, Y, Z;
- string line;
- while (getline(cin, line)) {
- vector<double> numbers;
- stringstream ss(line);
- for (double i; ss >> i; ) {
- numbers.push_back(i);
- if (ss.peek() == ';') {
- ss.ignore();
- }
- if (ss.peek() == ' ') {
- double X = numbers[0], Y = numbers[1], Z = numbers[2];
- if (X && Y && Z) {
- Point p(X, Y, Z);
- cout << "r=" << p.getRadius() << "; phi=" << p.getPhi() << "; theta=" << p.getTheta() << endl;
- }
- else if (X && Y) {
- Point p(X, Y);
- cout << "r=" << p.getRadius() << "; phi=" << p.getPhi() << endl;
- }
- numbers.clear();
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement