Answer to Question #250935 in C++ for hamn

Question #250935

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-14T03:45:11-0400
#include <iostream>
using namespace std;
int main(){
    int rspeed;
    rspeed = 72 + 54;
    float time;
    cout<<"Input the time in seconds taken to pass the good train: ";
    cin>>time;
    float length = (float) rspeed*1000/3600 * time; //convert speed to m/s because time is in seconds
    cout<<"Length of the good train = "<<length<<" meters.\n";
    return 0;
}

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