Question: Please complete this c++ code without changing main function class Vec3d { }; class Body { private: string name; double mass; // mass of the
Please complete this c++ code without changing main function
| class Vec3d { | |
| }; | |
| class Body { | |
| private: | |
| string name; | |
| double mass; // mass of the body | |
| double radius; // size of the body (assumes spherical) | |
| Vec3d pos; // pos = (x,y,0) ignore z for now. x,y should be based on orbital radius | |
| Vec3d v; // v = 0 next week we have to calculate | |
| Vec3d a; // a = 0 next week we compute gravitational acceleration due to all other bodies | |
| Body() : name(), pos(), v(), a() {} | |
| friend ostream& operator <<(ostream& s, const Body& b) { | |
| } | |
| friend istream& operator >>(istream& s, Body& b) { | |
| } | |
| }; | |
| int main() { | |
| ifstream solarsystem("solarsystem.dat"); | |
| char buf[1024]; | |
| solarsystem.getline(buf, sizeof(buf)); // throw out first line | |
| Body sun, mercury, venus, earth, moon; | |
| solarsystem >> sun >> mercury >> venus >> earth; | |
| // read in the name of each body | |
| // compute average distance of each body from sun (average of perihelion and aphelion) | |
| // pick t = a random number from 0 to 2*pi | |
| // | |
| // calculate x,y = r cos t, r sin t | |
| // put into pos vector (x,y, 0) | |
| // next step (not necessary this week) | |
| // calculate V | |
| // pretend all orbits are circular | |
| // calculate the length of the circular path around the sun 2*pi * r | |
| // look up time it takes to orbit | |
| // convert to meters and seconds | |
| // v = distance around the sun / orbital period in seconds | |
| cout << sun << mercury << venus << earth; | |
| } |
Please write c++ code
solarsystem.bat
Name Orbits Mass(kg) Diam(m) Perihelion(m) Aphelion(m) orbPeriod(days) rotationalPeriod(hours) axialtilt(deg) orbinclin(deg) Sun NaN 1.9891e30 1.391684e9 0 0 0 587.28 0 0 Mercury Sun 0.330e24 4.879e6 4.6e10 6.98e10 88 1407.6 0.01 7.0 Venus Sun 4.87e24 1.2104e7 1.075e11 1.089e11 224.7 -5832.5 177.4 3.4 Earth Sun 5.97e24 1.2756e7 1.471e11 1.521e11 365.2425 23.9 23.4 0.0 Moon Earth 0.073e24 3.475e6 0.363e9 0.406e9 27.3 655.7 6.7 5.1 Mars Sun 0.642e24 6.792e7 2.066e11 2.492e11 687.0 24.6 25.2 1.9 Jupiter Sun 1898e24 1.42984e8 7.405e11 8.166e11 4331 9.9 3.1 1.3 Saturn Sun 568e24 1.20536e8 1.3526e12 1.5145e12 10747 10.7 26.7 2.5 Io Jupiter 893.2e20 3643.2e6 421.6e6 421.6e6 1.769138 NaN NaN NaN Europa Jupiter 480.0e20 3121.6e6 670.9e6 670.9e6 3.551181 NaN NaN NaN Ganymede Jupiter 1481.9e20 5262.4e6 1070.4e6 1070.4e6 7.154553 NaN NaN NaN Callisto Jupiter 1075.9e20 4820.6e6 1882.7e6 1882.7e6 16.689018 NaN NaN NaN Phobos Mars 1.05e-16 22.4e3 9.378e6 9.378e6 .319 NaN NaN NaN Deimos Mars 5e11 12.2e3 23.495e6 23.495e6 1.262 NaN NaN NaN
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
