Computer Science, asked by naghmaneyaz, 4 months ago

write a program in c++ to accept distance travelled by a car and time taken from the user and calculate its speed​

Answers

Answered by aroush93
2

Answer:

mark brainliest

Explanation:

When an object moves in a straight line at a steady speed, we can calculate its speed if we know how far it travels and how long it takes. This equation shows the relationship between speed, distance traveled and time taken:

Speed is distance divided by the time taken.

For example, a car travels 30 kilometers in 2 hours.

Its speed is 30 ÷ 2 = 15km/hr.

Formula used :

Distance = Speed * Time

Time = Distance / Speed

Speed = Distance / Time

Examples:

Input : distance(km) : 48.5 time(hr) : 2.6

Output : Speed(km / hr) : 18.653846153

Input : speed(km / hr) : 46.0 time(hr) : 3.2

Output : Distance(km) : 147.2

Input : distance(km) : 48.5 speed(km / hr) : 46.0

Output : Time(hr) : 1.0543

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

// 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;

}

Similar questions