Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- class Point
- {
- public:
- string id;
- double vx;
- double vy;
- double vz;
- double m;
- Point(string id = "~",
- double vx = 0,
- double vy = 0,
- double vz = 0,
- double m = 0)
- {
- this->id = id;
- this->vx = vx;
- this->vy = vy;
- this->vz = vz;
- this->m = m;
- }
- void printPoint()
- {
- cout << "label: " << id << '\n'
- << "x_velocity: " << vx << '\n'
- << "y_velocity: " << vy << '\n'
- << "z_velocity: " << vz << '\n'
- << "mass: " << m << "\n\n";
- }
- };
- class Space
- {
- vector<Point> points;
- public:
- void add(string id, double vx, double vy, double vz, double m)
- {
- class Point *to_add = new Point(id, vx, vy, vz, m);
- this->points.push_back(*to_add);
- }
- void qdm(double &px, double &py, double &pz);
- string fastest()
- {
- float vMax = -3.402822e+38;
- string result;
- for (auto i = this->points.begin(); i != this->points.end(); i++)
- {
- float v = sqrt(pow(i->vx, 2) + pow(i->vy, 2) + pow(i->vz, 2));
- if (v > vMax)
- {
- vMax = v;
- result = i->id;
- }
- }
- cout << "the fastest point is [" << result << "] [speed = " << vMax << "]\n\n";
- return result;
- }
- void printSpace()
- {
- for (auto i = this->points.begin(); i != this->points.end(); i++)
- i->printPoint();
- }
- };
- int main()
- {
- Space *s = new Space();
- s->add("punto 1", 5, 6, 7, 8);
- s->add("punto 2", 2, 3, 6, 6);
- s->add("punto 3", 1, 4, 9, 7);
- s->printSpace();
- s->fastest();
- //s->qdm();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement