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
|
/*
This program will allow you to generate wind speeds between specific average wind speed values. Users will be prompted for the average wind speed, minimum and maximum windspeeds, and the program will automatically
display a table that shows the values between the maximum and minimum average windspeeds (+gust). There will be an asterik displayed for 300 seconds next to the values if a storm is encountered.
Date: 10/17/2014
Language: C++
*/
//Author: Taisei Yamada.
#include <iostream>
using namespace std;
double rand_float(double, double);
double rand_float_prob(double, double);
int main ()
{
double wind_speed, maxgust, mingust, avg_windspeed, min_prob, max_prob, probability, max_avgwindspeed, min_avgwindspeed;
int time, stormtime;
char repeat='y';
cout << "Welcome to the Flight Simulator Wind Speed calculator. This program allows you to generate a table of wind speeds for 3600 seconds, considering the minimum gust, maximum gust and the wind speed. Asteriks will be displayed next to ech wind speed for a duration of 300 seconds (5 minutes) if a storm is encountered. \n";
while (repeat=='y')
{
cout << "Enter the value for the average wind speed: ";
cin >> avg_windspeed;
cout << "Enter the value for the minimum gust: ";
cin >> mingust;
cout << "Enter the value for the maximum gust (it must be greater than the minimum gust): ";
cin >> maxgust;
cout << "TIME | " << "WINDSPEED\n";
cout << "--------------------------\n";
for (time=0; time<=3600; time+=10)
{
wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
if (probability <=0.005)
{
stormtime = time+300;
}
if(stormtime)
wind_speed+=10;
min_avgwindspeed = avg_windspeed+mingust;
max_avgwindspeed = avg_windspeed+maxgust;
min_prob=0;
max_prob=1;
if(stormtime)
{
cout << time << " " << wind_speed << " *" << endl;
stormtime -= 10;
}
else
{
cout << time << " " << wind_speed << endl;
}
}
cout << "Would you like to continue with different values? If yes, press y or press any other key to exit otherwise.\n";
cin >> repeat;
}
return 0;
}
double rand_float(double min_avgwindspeed, double max_avgwindspeed)
{
double wind_speed;
wind_speed = ((double)rand()/RAND_MAX) * (max_avgwindspeed-min_avgwindspeed) + min_avgwindspeed;
return wind_speed;
}
double rand_float_prob(double min_prob, double max_prob)
{
double probability;
probability= ((double)rand()/RAND_MAX) * (max_prob-min_prob) + min_prob;
return probability;
}
|