Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. class Point
  8. {
  9.     public:
  10.         string id;
  11.         double vx;
  12.         double vy;
  13.         double vz;
  14.         double m;
  15.        
  16.         Point(string id = "~",
  17.                 double vx = 0,
  18.                 double vy = 0,
  19.                 double vz = 0,
  20.                 double m = 0)
  21.         {
  22.             this->id = id;
  23.             this->vx = vx;
  24.             this->vy = vy;
  25.             this->vz = vz;
  26.             this->m = m;
  27.         }
  28.        
  29.         void printPoint()
  30.         {
  31.             cout << "label: " << id << '\n'
  32.                 << "x_velocity: " << vx << '\n'
  33.                 << "y_velocity: " << vy << '\n'
  34.                 << "z_velocity: " << vz << '\n'
  35.                 << "mass: " << m << "\n\n";
  36.         }
  37. };
  38.  
  39.  
  40.  
  41. class Space
  42. {
  43.     vector<Point> points;
  44.    
  45.     public:
  46.        
  47.         void add(string id, double vx, double vy, double vz, double m)
  48.         {
  49.             class Point *to_add = new Point(id, vx, vy, vz, m);
  50.             this->points.push_back(*to_add);
  51.         }
  52.        
  53.         void qdm(double &px, double &py, double &pz);      
  54.        
  55.         string fastest()
  56.         {
  57.             float vMax = -3.402822e+38;
  58.             string result;
  59.             for (auto i = this->points.begin(); i != this->points.end(); i++)
  60.             {
  61.                 float v = sqrt(pow(i->vx, 2) + pow(i->vy, 2) + pow(i->vz, 2));
  62.                 if (v > vMax)
  63.                 {
  64.                     vMax = v;
  65.                     result = i->id;
  66.                 }
  67.             }
  68.             cout << "the fastest point is [" << result << "] [speed = " << vMax << "]\n\n";
  69.             return result;
  70.         }
  71.                
  72.         void printSpace()
  73.         {
  74.             for (auto i = this->points.begin(); i != this->points.end(); i++)
  75.                 i->printPoint();
  76.         }  
  77. };
  78.  
  79.  
  80.  
  81. int main()
  82. {
  83.     Space *s = new Space();
  84.     s->add("punto 1", 5, 6, 7, 8);
  85.     s->add("punto 2", 2, 3, 6, 6);
  86.     s->add("punto 3", 1, 4, 9, 7);
  87.     s->printSpace();
  88.     s->fastest();
  89.     //s->qdm();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement