A car completes its journey in three parts. It travels the first X km of its journey at an average
speed of x_Speed m/s and the next Y km at an average speed of y_Speed km/h. The car completes the
last part of its journey at an average speed of z_Speed km/h in z_Minutes minutes. Here X, x_Speed, Y,
y_Speed, z_Speed, and z_Minutes are all variables whose values you will have to take as an input from the
user. Find the average speed for its entire journey, giving your answer in km/h.
speed =
distance
time
#include<iostream>
using namespace std;
int main(){
double X, x_Speed, Y, y_Speed, z_Speed, z_Minutes;
cout<<"Enter X (KM): "<<endl;
cin>>X;
cout<<"Enter x_Speed (m/s): "<<endl;
cin>>x_Speed;
cout<<"Enter Y (km): "<<endl;
cin>>Y;
cout<<"Enter y_Speed (km/h): "<<endl;
cin>>y_Speed;
cout<<"Enter z_Speed (km/h): "<<endl;
cin>>z_Speed;
cout<<"Enter z_Minutes: "<<endl;
cin>>z_Minutes;
double num = (X + Y )+((z_Speed*z_Minutes) / 60);
double deno = (5 * X) / (18 * x_Speed) + (Y/y_Speed) + (z_Speed/60);
double speed = num / deno;
cout<<"Total distance is: "<<num<<endl;
cout<<"Total time taken is: "<<deno<<endl;
cout<<"Average speed is: "<<speed<<endl;
}
Comments
Leave a comment