Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Speed of Sound The following shows the approximate speed of sound in air, wa

ID: 3752012 • Letter: T

Question

The Speed of Sound The following shows the approximate speed of sound in air, water, and steel Air 1,100 feet per second Water 4,900 feet per second Steel 16,400 feet per second Write a program that displays a menu allowing the user to select air, water, or steel. After the user has made a selection, he or she should be asked to enter the distance a sound wave will travel in the selected medium. The program will then display the amount of time it will take. Round the answer to four decimal places.) Input Validation: Check that the user has selected one of the available choices from the menu. Do not accept distances less than O

Explanation / Answer

Ans:

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice;
int distance;
double amountOfTime;
const double Air = 1100;
const double Water = 4900;
const double Steel = 16400;
for(int i = 0; i < 5; ++i)
{
system("cls");
cout << "The Speed of Sound in a Medium ";
cout << "Please Select a Medium ";
cout << "1. Air ";
cout << "2. Water ";
cout << "3. Steel ";
cout << "Select the Desired Number : ";
cin >> choice;
cout << "Now enter the distance (feet) the sound wave will travel in the selected medium: ";
cin >> distance;
cout << setprecision (4) << fixed;
if (distance <= 0)
{
cout << " You must enter a value greater than zero ";
}
else if (choice >= 1 && choice <=3)
{
switch (choice)
{
case 1: amountOfTime = distance / Air;
break;
case 2: amountOfTime = distance / Water;
break;
case 3: amountOfTime = distance / Steel;
}
cout << endl << "The time it takes sound to travel this distance in the selected medium is ";
cout << amountOfTime;
cout << " seconds" << endl;
cin.sync();
cin.get();
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote