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

The speed of sound varies depending on the medium through which it travels. In g

ID: 3818885 • Letter: T

Question

The speed of sound varies depending on the medium through which it travels. In general, sound travels fastest in of such as stell, solver in liquid media such as water, and slowest of all in gases such as air. The following table shows the approximate speed of sound, measured in feet per second,in air, water and steel write a program that displays a menu allowing the user to select air water or steel after the User made a selection, the number of feet a sound wave will travel in the selected medium should be entered. program will then display the amount of time it take (Round the answer to four decimal places) input validation: decide how the program should handle an illegal input for the menu choice or a negative value for the distance Use enumerated data type to manage your menu choice air, water, steel include: a detailed pseudocode large and readable screen shot of your input/output window. Enter the number of feet a sound wave will travel in selected medium as 20000 Display the time taken

Explanation / Answer

/* program to compute time taken by sound to travel a distance through a selected medium */
#include<stdio.h>

typedef enum
{
       air=1,
       water=2,
       steel=3,
       stop=4
       }medium;

int accept();
double compute(int,int);   

int accept() /* function accepts input */
{
int d=0;
printf(" Enter the number of Feet to travel by sound wave :");
scanf("%d",&d);
return(d);
}

double compute(int d,int s) /* function computes the time taken */
{
double t;
t=(double)d/s;
return t;
}

main()
{
medium choice;
int speed,dist=0;
do
{
printf(" ===M E N U==== 1. Air 2. Water 3. Steel 4. Exit Enter your choice: ");
   scanf("%d",&choice);
   switch(choice)
   {
   case air: dist=accept(); /* calling accept function */
   speed=1100;
       printf(" Time taken in Air :%g",compute(dist,speed)); /*calling compute functin and print the result */
              break;
   case water: dist=accept();
       speed=4900;
       printf(" Time taken in Water :%g",compute(dist,speed)); /*calling compute functin and print the result */
              break;
   case steel:dist=accept();
   speed=16400;
             printf(" Time taken in Steel :%g",compute(dist,speed)); /*calling compute functin and print the result */
              break;
   case stop:   printf(" Program Terminated ");
              break;
   default: printf(" Invalid Choice ."); break;
}
}while(choice!=4);

}

---------------------------------------------------------------------------------------------------------------------------------------

Ouput:


===M E N U====
1. Air
2. Water
3. Steel
4. Exit
Enter your choice: 1
Enter the number of Feet to travel by sound wave :20000
Time taken in Air :18.1818

===M E N U====
1. Air
2. Water
3. Steel
4. Exit
Enter your choice: 2
Enter the number of Feet to travel by sound wave :20000
Time taken in Water :4.08163

===M E N U====
1. Air
2. Water
3. Steel
4. Exit
Enter your choice: 3
Enter the number of Feet to travel by sound wave :20000
Time taken in Steel :1.21951

===M E N U====
1. Air
2. Water
3. Steel
4. Exit
Enter your choice: 4
Program Terminated

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