Answer to Question #250952 in C++ for Phenominal1

Question #250952
A passenger train travels at a speed of 72 km/h. A man on the passenger train observes a
goods train travelling at a speed of 54 km/h in the opposite direction. If the good train passes him in X
seconds, write a C++ function to find the length of the goods train.
1
Expert's answer
2021-10-13T20:37:35-0400

Source code

#include <iostream>


using namespace std;


int main()
{
    int speed1=72;
    int speed2=54;
    int X;
    cout<<"\nEnter number of seconds: ";
    cin>>X;
    //convert seconds into hours
    float X2=X/3600.0;
    float distance=(speed1+speed2)*X2;
    
    cout<<"\nThe length of the goods train = "<<distance;


    return 0;
}


Output






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS