// FILE: voyage1.cxx // Written by Michael Main (main@colorado.edu) // This is a first example of a C++ program. The program // computes how long a trip takes. The primary purpose is // to llustrate input, output and assignments in C++. // This version takes relativity into account. #include // Provides cin and cout #include // Provides sqrt using namespace std; int main( ) { double distance; // The distance for a trip, in light years. double speed; // The speed for a trip, in fraction of c. double time_e; // The time for a trip, in years on Earth. double time_v; // The time for a trip, in years on voyage. double tau; // Einstein's relativistic factor. // Read the input. cout << "Please type the distance for the trip, in light years: "; cin >> distance; cout << "Your distance is " << distance << " light years." << endl; cout << "Please type the speed for the trip, as a fraction of c: "; cin >> speed; cout << "Your speed is " << speed << " c." << endl; // Calculations. time_e = distance / speed; tau = sqrt(1 - speed*speed); time_v = tau * time_e; // Print the output. cout << "Your trip will take " << time_e << " years on earth." << endl; cout << "Your trip will take " << time_v << " years on voyage." << endl; cout << "Space-sickness pills are available in the lounge." << endl; return 0; }