1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#include <iostream>
#include <iomanip>
using namespace std;
void menu();
void car(double, double, double, double);
void air(double, double, double, double);
void hel(double, double, double, double);
void hyd(double, double, double, double);
int main()
{
cout << showpoint << fixed << setprecision(1);
int option;
double time;
double distancemeters = 0;
double distancemiles = 0;
const double meters_mile = 1609;
cout << " DISTANCE FROM SOUND IN GASES\n\n";
do
{
menu();
cin >> option;
cout << endl;
switch (option)
{
case 1:
{
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30. \n";
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
}
car(time, distancemeters, distancemiles, meters_mile);
break;
}
case 2:
{
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30. \n";
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
}
air(time, distancemeters, distancemiles, meters_mile);
break;
}
case 3:
{
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30. \n";
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
}
hel(time, distancemeters, distancemiles, meters_mile);
break;
}
case 4:
{
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30. \n";
cout << "Enter the number of seconds elapsed: ";
cin >> time;
cout << endl ;
}
hyd(time, distancemeters, distancemiles, meters_mile);
break;
}
case 5:
break;
default:
cout << "You must select 1, 2, 3, or 4.\n\n";
break;
}
}
while (option != 5);
cout << "Programmer: E. R.\n";
return 0;
}
void menu()
{
cout << "1. Distance in carbon dioxide\n";
cout << "2. Distance in air\n";
cout << "3. Distance in helium\n";
cout << "4. Distance in hydrogen\n";
cout << "5. Quit\n\n";
cout << "Enter your choice (1-5): ";
}
void car(double time, double distancemeters, double distancemiles, double meters_mile)
{
const double carbonspeed = 258.0;
distancemeters = carbonspeed * time;
distancemiles = distancemeters / meters_mile;
cout << "The distance travelled in carbon is " << distancemeters << " meters or " << distancemiles << " miles.\n";
cout << "The sound source is ";
if (distancemiles < 1)
cout << "very close.\n\n";
else if (distancemiles < 5)
cout << "moderately close.\n\n";
else
cout << "far away.\n\n";
}
void air(double time, double distancemeters, double distancemiles, double meters_mile)
{
const double airspeed = 331.5;
distancemeters = airspeed * time;
distancemiles = distancemeters / meters_mile;
cout << "The distance travelled in air is " << distancemeters << " meters or " << distancemiles << " miles.\n";
cout << "The sound source is ";
if (distancemiles < 1)
cout << "very close.\n\n";
else if (distancemiles < 5)
cout << "moderately close.\n\n";
else
cout << "far away.\n\n";
}
void hel(double time, double distancemeters, double distancemiles, double meters_mile)
{
const double heliumspeed = 972.0;
distancemeters = heliumspeed * time;
distancemiles = distancemeters / meters_mile;
cout << "The distance travelled in helium is " << distancemeters << " meters or " << distancemiles << " miles.\n";
cout << "The sound source is ";
if (distancemiles < 1)
cout << "very close.\n\n";
else if (distancemiles < 5)
cout << "moderately close.\n\n";
else
cout << "far away.\n\n";
}
void hyd(double time, double distancemeters, double distancemiles, double meters_mile)
{
const double hydrogenspeed = 1270.0;
distancemeters = hydrogenspeed * time;
distancemiles = distancemeters / meters_mile;
cout << "The distance travelled in hydrogen is " << distancemeters << " meters or " << distancemiles << " miles.\n";
cout << "The sound source is ";
if (distancemiles < 1)
cout << "very close.\n\n";
else if (distancemiles < 5)
cout << "moderately close.\n\n";
else
cout << "far away.\n\n";
}
|