#include <iostream>
#include <cmath>
#include <iomanip>
// Class to represent a spacecraft
class Spacecraft {
public:
Spacecraft(const std::string& name, double x, double y)
: name(name), x(x), y(y), distanceTraveled(0.0) {}
// Method to launch the spacecraft
void launch() {
std::cout << name << " has launched into space!\n";
}
// Method to travel to a new position
void travel(double newX, double newY) {
double distance = std::sqrt(std::pow(newX - x, 2) + std::pow(newY - y, 2));
x = newX;
y = newY;
distanceTraveled += distance;
std::cout << name << " traveled to (" << std::fixed << std::setprecision(2)
<< x << ", " << y << "). Distance traveled: " << distance << " units.\n";
}
// Method to land the spacecraft
void land() {
std::cout << name << " has landed at (" << std::fixed << std::setprecision(2)
<< x << ", " << y << "). Total distance traveled: " << distanceTraveled << " units.\n";
}
private:
std::string name;
double x, y; // Current position
double distanceTraveled;
};
int main() {
// Create a spacecraft
Spacecraft spacecraft("Voyager", 0.0, 0.0);
// Simulate the space exploration
spacecraft.launch();
spacecraft.travel(100.0, 150.0); // Travel to a new position
spacecraft.travel(-50.0, 200.0); // Travel to another position
spacecraft.land();
return 0;
}