The following table shows the approximate speed of sound in air, water, and stee
ID: 3594079 • Letter: T
Question
The following table shows the approximate speed of sound in air, water, and steel: medium air water steel speed 1100 feet per second 4900 feet per second 16400 feet per second Writ amount of time it will take. e a function to map distance that a sound wave will travel in a specific medium to the approximate The function should be named getTra string parameter represents the type of medium whose acceptable values are "air", "water", or "steel". The integer parameter represents the distance in feet to travel in the specified medium. The function should return a float that is the time in seconds needed for the desired sound transmission. velTime and has two parameters: a string and an integer. The After function design, continue to write code to interact with users for computing the time needed for a specific medium and a specified distance by using your defined getTravelTime function. Your code shall prompt for a medium type and an integer distance and then display the travel time needed. Function specifications: Function name o getTravelTime . Parameters o a string representing type of mecdium o an integer representing a distance . Return value a float representing travel time needed For example, if the parameter values are steel and 8200, then the return value should be 0.5 o User interface specifications: Input The program prompts for two data, in the order of medium type and distance. o . Output Display the amount of time in seconds needed for the desired sound travel. oExplanation / Answer
Here is the cpp function
float getTravelTime(string m, int d)
{
int s;
if(m=="air")
s=1100;
else if(m=="water")
s=4900;
else if(m=="steel")
s=16400;
else
{
cout <<"Invalid medium "; return 0;
}
float t=(float)d/s; // time = distance/speed
return t;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.