196k views
1 vote
3. Write a program that will read in a velocity of a vehicle in miles per hour, and an amount of time traveled in minutes (both of datatype double). Then in a user defined function called CalcPrintDistance, calculate the distance traveled by the vehicle and print the distance traveled (both from the function) to the screen in miles (using 2 decimal places). CalcPrintDistance should have two parameters: the velocity and the amount of time traveled. oThe function should have different variable names from Main.oCalcPrintDistance should not return any values to main.oDo your calculations all in the function. Including the conversion of minutes to hours.Test your program with the following values:Velocity: 68.2 mphTime traveled: 34.6 minutes

1 Answer

2 votes

Answer:

// program in C++.

#include <bits/stdc++.h>

using namespace std;

// function to calculate Distance

void CalcPrintDistance(double velo,double mint)

{

// calculate Distance traveled

double dist=(velo*mint)/60;

// print the Distance

cout<<fixed<<setprecision(2)<<"Distance traveled by vehicle is:"<< dist<<" miles"<<endl;

}

// driver function

int main() {

// variables

double speed,trv_time;

cout<<"Enter the velocity (miles per hour):";

// read speed of the vehicle

cin>>speed;

cout<<"Enter the time traveled(in minutes):";

// read the time traveled

cin>>trv_time;

// call the function

CalcPrintDistance(speed,trv_time);

return 0;

}

Step-by-step explanation:

Read the velocity of vehicle and assign it to variable "speed".Read the time traveled by the vehicle and assign it to variable "trv_time".Call the function CalcPrintDistance() with parameter "speed" and "trv_time".This function will calculate the distance traveled and print it.

Output:

Enter the velocity (miles per hour):68.2

Enter the time traveled(in minutes):34.6

Distance traveled by vehicle is:39.33 miles

User BoopityBoppity
by
5.0k points