COOL PLUS PLUS


COOL PLUS PLUS

COOL PLUS PLUS


The other day, I helped my C++ professor to derive an equation for a problem we had to do. The problem needed to be programmed into C++. The problem was that there is a man whose car is parked on the railroad track and he had to get off of it as fast as he could. The thing is that he had ran out of gas and was stuck on the track! Even worse, there was a train on the way! Thankfully, the trains horn blares and the man hears the horn. The man is able to get out of the way before his car is destroyed by the train. The man got out of the way just in time!


Now, lets think here. What would we need to program this problem into C++? We would need the speed of sound, the man's reaction time, the distance that the train travelled along with the speed of the train. Here is the code I came up with, check it out:


/* CS110 Fall 2011 Assignment 4


using namespace std;


int main( int argc, char* argv[])


float distance; //Output


float reactiontime = 0.215;


int velocityofsound = 1126;


int velocityoftrain; //Input


cout<< " Enter the velocity (between 1 and 400) of the train in ft/s: ";


distance = (velocityoftrain*reactiontime)/(1-velocityoftrain/velocityofsound); //D = (VT*TR)/(1-VT/VS)


Dedicated to your Success!


Nashua C Tutors


Jamaal's Blog by Topic





Leave a Reply

Your email address will not be published. Required fields are marked *