1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
// This program is designed to tell a user the Relitivistic Length, mass and time
//of something going a certain speed under c
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
int main()
{
char choice; // User's choice
float c; //Speed of light
c = 299792458;
cout << "Welcome to Craig McRae's Relitivity Calculator!" << endl;
cout << "What would you like to calculate?" << endl;
cout << "A) Relitivistic Length, Mass and Time dilation" << endl;
cout << "B) Relitivistic Velocity addition" << endl;
cin >> choice;
if ( choice == A ) // here it says A is not defined
{
float V; //Speed
float length, mass, time; //Initial mass, length, and time
float Rlength, Rmass, Rtime; //Relitivistic Length, mass and time
float y; //Gamma or Lorentz transform
cout << "How fast are you going? (m/s)";
cin >> V;
while ( V >= c )
{cout << "IMPOSSIBLE! NOTHING CAN GO THAT FAST!" << endl;
cout << "How fast are you REALLY going? (m/s)";
cin >> V;
}
cout << "How long were you traveling at this speed? (in seconds) ";
cin >> time;
cout << "Enter your mass in kg: ";
cin >> mass;
cout << "Enter your length in meters: ";
cin >> length;
y = sqrt(1 - ((V*V)/(c*c)));
Rmass = mass / y;
Rtime = time / y;
Rlength = length * y;
cout << "Traveling at a speed of " << V << "m/s, to an observer at rest you would appear to have a length of " << Rlength << " meters, a mass of " << Rmass << " kg, and " << time << " seconds for you would be " << Rtime << " seconds for the observer!" << endl;
}
if ( choice == B ) // here it says B is not defined
{
float V1, V2, Vf; //Velocities
char ans;
cout << "What is the first velocity?";
cin >> V1;
cout << "What is the second Velocity?";
cin >> V2;
cout << "Are they going in the same direction? (Y/N)";
cin >> ans;
if ( ans == Y) // here it says Y is not defined
V2 = -1 * V2;
//Calculations
Vf = abs(V1 + V2);
V2 = -1 * V2;
Vf = Vf/(1 + (V1*V2)/(c*c));
cout << " " << endl;
cout << Vf << endl; //I incomplete final cout statement for testing
}
return 0;
}
|