0

```
// The Physics Game.cpp : Defines the entry point for the console application.
//Rodney Jenkins
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
double eqOne_vf(double Vi , double a , double t) {
return ( Vi + (a * t) );
}
double eqTwo_x(double Vf , double Vi , double t) {
return (0.5 * ((Vf - Vi) * t));
}
double eqThree_x(double Vi, double t, double a){
return Vi * t + 0.5 * a * t * t;
}
double eqFour_vfsQ(double Vi, double x, double a){
return (Vi * Vi) + (2 * (a * x));
}
double eqFive_x(double Vi, double t){
return Vi * t + .5 * t * t;
}
double eqSix_Rf(double m, double d){
return (m * 9.8) * sin(d) ;
}
double eqSeven_w(double f, double fr, double x){
return (f - fr) * x;
}
double eqEight_Ke(double m, double V){
return .5 * m * V * V;
}
double eqNine_W(double f, double x){
return f * x;
}
double eqTen_PE(double m, double h){
return m * 9.8 * h;
}
double eqEleven_w(double kef, double kei){
return kef - kei;
}
double eqTwelve_kei_PEi(double kei, double PEi){
return kei + PEi;
}
double eqThirteen_P(double m, double v){
return m * v;
}
double eqFourteen_I(double f, double t){
return f * t;
}
double eqFifteen_p( double mf, double mi){
return mf - mi;
}
double eqSixteen_a( double Vf, double Vi, double t){
return (Vf - Vi) / t;
}
int _tmain(int argc, _TCHAR* argv[]) {
int choice;
do
{
cout<<"Which equation would you like to use\n";
cout<<"1 - Vi + (a * t) \n";
cout<<"2 - 0.5 * (Vf - Vi) * t \n";
cout<<"3 - Vi * t + .5 * a * t * t \n";
cout<<"4 - ( Vi * Vi) + 2 * (a * x)\n";
cout<<"5 - Vi * t + .5 * t * t\n";
cout<<"6 - w = (m * 9.8) * sin d\n";
cout<<"7 - (f - fr) * x \n";
cout<<"8 - .5 * m * V^2\n";
cout<<"9 - f * x\n";
cout<<"10 - m * 9.8 * h\n";
cout<<"11 - kef - kei\n";
cout<<"12 - Kei + PEi\n";
cout<<"13 - m * v\n";
cout<<"14 - f * t\n";
cout<<"15 - mf - mi\n";
cout<<"16 - Vf - Vi / t\n";
cout<<"Choice: ";
cin>> choice;
srand(time(0)); // Initialize random number generator.
int randomNumber = rand();
double answer = 0;
switch (choice)
{
case 1:
{
double Vi = (randomNumber % 100) + 1;
double a = (randomNumber % 75) + 1;
double t = (randomNumber % 60) + 1;
cout << " The initial velocity is "<< Vi << " Meters Per second\n";
cout << " The acceleration is " << a << " Meters Per Second^2.\n";
cout << " The time is " << t << " seconds\n";
cout<<" What is the final Velocity\n";
cin>> answer;
if ( answer == eqOne_vf(Vi ,a , t)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<<eqOne_vf(Vi ,a , t);
}
}
break;
case 2:
{
double Vf = (randomNumber % 100) + 1;
double Vi = (randomNumber % 75) + 1;
double t = (randomNumber % 60) + 1;
cout << " The final velocity is " << Vf << " Meters Per Second \n";
cout << " The initial velocity is "<< Vi << " Meters Per Second \n";
cout << " The time is " << t << " seconds \n";
cout << " What is the displacement ?";
cin >> answer;
if ( answer == eqTwo_x(Vf ,Vi , t)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is " << eqTwo_x(Vf ,Vi , t);
}
}
break;
case 3:
{
double Vi = (randomNumber % 100) + 1;
double t = (randomNumber % 75) + 1;
double a = (randomNumber % 60) + 1;
cout << " The inital velocity is "<< Vi << "Meters Per second\n";
cout << " The time is "<< t << "seconds\n";
cout << " The acceleration is "<<a << "Meters Per Second^2.\n";
cout<<" What is the displacement ?";
cin>> answer;
if ( answer == eqThree_x(Vi ,t , a)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<<eqThree_x(Vi ,t , a);
}
}
break;
case 4:
{
double Vi = (randomNumber % 100) + 1;
double x = (randomNumber % 75) + 1;
double a = (randomNumber % 60) + 1;
cout << " The inital velocity is "<< Vi << "Meters per Second\n";
cout << " The acceleration is "<< a << "Metes Per second^2\n";
cout << " The displacement is "<< x << "Meters\n";
cout<<" What is the final velocity^2\n";
cin>> answer;
if ( answer == eqFour_vfsQ(Vi ,x , a)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<<eqFour_vfsQ(Vi ,a , x);
}
}
break;
case 5:
{
double Vi = (randomNumber % 75) + 1;
double t = (randomNumber % 60) + 1;
cout << " The inital velocity is "<< Vi << "Meters per Second\n";
cout << " The time is "<< t << " seconds \n";
cout<<"What is the displacement ?";
cin>> answer;
if ( answer == eqFive_x(Vi ,t)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<<eqFive_x(Vi ,t);
}
}
break;
case 6:
{
double m = (randomNumber % 100) + 2;
double d = (randomNumber % 100) + 1;
cout<<"The weight of the object is "<< m <<" kg \n";
cout<<"The incline is "<< d <<" degrees\n";
cout<<"What is the resulting force?";
cin>> answer;
if ( answer == eqSix_Rf(m ,d)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqSix_Rf(m,d) <<" N \n";
}
}
break;
case 7:
{
double f = (randomNumber % 100) + 2;
double fr = (randomNumber % 100) + 1;
double x = (randomNumber % 100) + 1;
cout<<"The force of the object is "<< f <<" N \n";
cout<<"The friction is "<< fr <<" N \n";
cout <<"The displacement is "<< x << "Meters\n";
cout<<"What was the amount of work done?";
cin>> answer;
if ( answer == eqSeven_w(f ,fr, x)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqSeven_w(f, fr, x) <<" J \n";
}
}
break;
case 8:
{
double m = (randomNumber % 100) + 2;
double V = (randomNumber % 100) + 1;
cout<<"The mass of the object is "<< m <<" kg \n";
cout<<"The velocity of the object is "<< V <<" Meters Per Seconds \n";
cout<<"What is the kinetic energy?";
cin>> answer;
if ( answer == eqEight_Ke(m ,V )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqEight_Ke(m, V) <<" KE \n";
}
}
break;
case 9:
{
double f = (randomNumber % 100) + 2;
double x = (randomNumber % 100) + 1;
cout << " The displacement is "<< x << "Meters\n";
cout<<"The force of the object is "<< f <<"N \n";
cout<<"What is the work?";
cin>> answer;
if ( answer == eqNine_W(f ,x )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqNine_W(f ,x ) <<" J\n";
}
}
break;
case 10:
{
double m = (randomNumber % 100) + 2;
double h = (randomNumber % 100) + 1;
cout<<"The mass of the object is "<< m <<" kg \n";
cout<<"The height of the object is "<< h <<" Meters\n";
cout<<"What is the potential Energy?";
cin>> answer;
if ( answer == eqTen_PE(m ,h )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<<eqTen_PE(m ,h ) <<" PE\n";
}
}
break;
case 11:
{
double kef = (randomNumber % 100) + 2;
double kei = (randomNumber % 100) + 1;
cout<<"The kinetic energy final is"<< kef <<"\n";
cout<<"The kinetic energy initial is"<< kei <<"\n";
cout<<"What is the work done?";
cin>> answer;
if ( answer == eqEleven_w(kef ,kei )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqEleven_w(kef ,kei ) <<" J\n";
}
}
break;
case 12:
{
double kei = (randomNumber % 100) + 1;
double PEi = (randomNumber % 100) + 2;
cout<<"The kinect energy initial is "<< kei <<"\n";
cout<<"The potential energy initial is "<< PEi <<"\n";
cout<<"What is the kinetic energy final + potential Energy final?";
cin>> answer;
if ( answer == eqTwelve_kei_PEi(kei ,PEi )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<<eqTwelve_kei_PEi(kei ,PEi ) <<" \n";
}
}
break;
case 13:
{
double m = (randomNumber % 100) + 1;
double v = (randomNumber % 100) + 2;
cout<<"The mass of the object is "<< m <<" kg \n";
cout<<"The velocity is "<< v <<" Meters Per Seconds^2 \n";
cout<<"What is the momentum?";
cin>> answer;
if ( answer == eqThirteen_P(m ,v )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqThirteen_P(m ,v ) <<" \n";
}
}
break;
case 14:
{
double f = (randomNumber % 100) + 2;
double t = (randomNumber % 60) + 1;
cout<<"The force of the object is "<< f <<" N \n";
cout<<"The time is "<< t << " seconds \n";
cout<<"What is the impulse?";
cin>> answer;
if ( answer == eqFourteen_I(f ,t )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqFourteen_I(f ,t ) <<" \n";
}
}
break;
case 15:
{
double mf = (randomNumber % 1000) + 2;
double mi = (randomNumber % 1000) + 1;
cout<<"The Momentum final is"<< mf <<"\n";
cout<<"The Momentum initial is"<< mi <<"\n";
cout<<"What is the change in momentum?";
cin>> answer;
if ( answer == eqFifteen_p(mi ,mf )){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqFifteen_p(mi ,mf) <<" \n";
}
}
break;
case 16:
{
double Vf = (randomNumber % 100) + 1;
double Vi = (randomNumber % 75) + 1;
double t = (randomNumber % 60) + 1;
cout << " The final velocity is " << Vf << " Meters Per Second \n";
cout << " The initial velocity is "<< Vi << " Meters Per Second \n";
cout << " The time is " << t << " seconds \n";
cout << " What is the acceleration?";
cin >> answer;
if ( answer == eqSixteen_a(Vf ,Vi ,t)){
cout << "That's correct\n";
} else {
cout << "That's incorrect the answer is "<< eqSixteen_a(Vf ,Vi ,t) <<" \n";
}
}
break;
default:
cout<< choice <<" is an invalid choice choose again.\n";
}
} while (choice != 0);
system("pause");
}
```