#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
const double PI = 3.14159265358979323846;
const double DEG_TO_RAD = PI / 180.0;
// Class to represent a celestial body
class CelestialBody {
public:
CelestialBody(const std::string& name, double distanceFromSun, double orbitalPeriod)
: name(name), distanceFromSun(distanceFromSun), orbitalPeriod(orbitalPeriod), angle(0.0) {}
// Method to update the position of the celestial body
void updatePosition(double time) {
double angularVelocity = 360.0 / orbitalPeriod; // degrees per unit time
angle = fmod(angularVelocity * time, 360.0); // Update angle based on time
x = distanceFromSun * cos(angle * DEG_TO_RAD);
y = distanceFromSun * sin(angle * DEG_TO_RAD);
}
// Method to print the celestial body's information
void printInfo() const {
std::cout << name << " is at (" << std::fixed << std::setprecision(2)
<< x << ", " << y << ") from the Sun.\n";
}
private:
std::string name;
double distanceFromSun; // Distance from the Sun
double orbitalPeriod; // Orbital period in arbitrary time units
double angle; // Current angle in degrees
double x, y; // Cartesian coordinates
};
int main() {
// Create celestial bodies
std::vector<CelestialBody> celestialBodies = {
CelestialBody("Mercury", 57.9, 88.0),
CelestialBody("Venus", 108.2, 225.0),
CelestialBody("Earth", 149.6, 365.0),
CelestialBody("Mars", 227.9, 687.0)
};
// Simulation parameters
double simulationTime = 0.0;
double timeStep = 1.0; // Time step for the simulation
// Run the simulation
for (int step = 0; step < 10; ++step) {
std::cout << "Time: " << simulationTime << "\n";
for (auto& body : celestialBodies) {
body.updatePosition(simulationTime);
body.printInfo();
}
std::cout << std::endl;
simulationTime += timeStep;
}
return 0;
}