ok this is what I have so far
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
void Wind_Speed();
void Storms_Wind();
void Microbursts();
void View_Wind();
double rand_float(double a, double b);
int main()
{
char selection;
do
{
system("cls");
cout << " Wind Speed Simulation by Dilmer Valecillos CS1600-001 " << endl;
cout << " -----------------------------------------------------\n\n"
<< " MENU\n"
<< " ----\n\n"
<< "1. Create wind speed simulation \n"
<< "2. Create wind speed with storms \n"
<< "3. Create wind speed with microbursts \n"
<< "4. View wind simulation \n"
<< "5. Quit\n\n"
<< " SELECTION: ";
//get menu selection
selection = cin.get();
//process selection
switch( selection)
{
case '\n': break;
case '1': Wind_Speed(); break;
case '2': Storms_Wind(); break;
case '3': Microbursts(); break;
case '4': View_Wind(); break;
case '5': break;
default: cout << '\a';
}
}while( selection != '5' );
return 0;
}//end main()
//function definitions
void Wind_Speed()
{
system("cls");
int i = 0;
int Max_Seconds = 3600;
double Avg_Wind;
double High_Gust, Low_Gust, Upper_Limit;
ofstream wind;
wind.open("wind.dat");
cout << " |---- Dilmer Valecillos [CS1600-001] ----|" << endl;
cout << "\n\n Enter the average of wind speed (mhp) : " ;
cin >> Avg_Wind;
cout << "\n\n Enter high gusts range (mhp) : " ;
cin >> High_Gust;
cout << "\n\n Enter low gusts range (mhp) : " ;
cin >> Low_Gust;
Upper_Limit = Avg_Wind + High_Gust;
wind.setf(ios::fixed | ios::showpoint); // Set Formats in the file
wind.precision(2);
cout.setf(ios::fixed | ios::showpoint); // Set Formats to display on the screen
cout.precision(2);
for (i = 0; i <= Max_Seconds; i++) // Seconds from 0 to Max_Seconds which is 3600 seconds or an hour
{
Avg_Wind = rand_float (Upper_Limit, Low_Gust);
if ( ( i % 10 ) == 0 )
{
wind << setw(4) << i << " " << Avg_Wind << endl; // Write data to a file wind.dat
cout << setw(4) << i << " " << Avg_Wind << endl; // Outputs the information to the screen
}
}
wind.close();
system("pause");
}
void Storms_Wind()
{
system("cls");
system("pause");
}
void Microbursts()
{
system("cls");
system("pause");
}
void View_Wind()
{
system("cls");
int seconds; // Since the first column is a whole number I declate it as a int
double Wind_Speed; // The wind result in the second column has decimals so it must be a double number
ifstream Read_file; //To read info from a file
Read_file.open("wind.dat"); // To open the file for reading
Read_file >> seconds >> Wind_Speed; // Read first and second column in this case seconds and wind speed
while (! Read_file.eof()) // Read the data until the end of the File
{
Read_file >> seconds >> Wind_Speed; // Read the first column and the second colum of the file
cout << setw(4) << seconds << " " << Wind_Speed << endl; // Show the info on the screen with a width of 4
}
Read_file.close(); // Close the file
system("pause");
}
double rand_float (double a, double b)
{
return ((double) rand() / RAND_MAX ) * (b - a) + a;
}