Write a program that calculates the total duration of
the trip and also the direction in which the customer has travelled.
Answers
Answer:
// C++ Program to calculate speed
// distance and time
#include<iostream>
using namespace std;
// Function to calculate speed
double cal_speed(double dist, double time)
{
cout << "\n Distance(km) : " << dist ;
cout << "\n Time(hr) : " << time ;
return dist / time;
}
// Function to calculate distance traveled
double cal_dis(double speed, double time)
{
cout << "\n Time(hr) : " << time ;
cout << "\n Speed(km / hr) : " << speed ;
return speed * time;
}
// Function to calculate time taken
double cal_time(double dist, double speed)
{
cout << "\n Distance(km) : "<< dist ;
cout << "\n Speed(km / hr) : " << speed ;
return speed * dist ;
}
// Driver function
int main()
{
// Calling function cal_speed()
cout << "\n The calculated Speed(km / hr) is : "
<< cal_speed(45.9, 2.0 ) << endl ;
// Calling function cal_dis()
cout << "\n The calculated Distance(km) : "
<< cal_dis(62.9, 2.5) << endl ;
// Calling function cal_time()
cout << "\n The calculated Time(hr) : "
<< cal_time(48.0, 4.5) << endl ;
return 0;