Thread: Flight Simulator Wind Speed!!

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    44

    Smile Flight Simulator Wind Speed!!

    Flight Simulator wind speed. This set of problems relates to a computer simulation if wind speed for a flight simulator. Assume that the wind speed for a particular region can be modeled by using an average value and a range of gust values that is added to the average. For example, the wind speed might be 10 miles an hour, with added noise ( which represents gusts) that ranges from 22 miles per hour to - 2 miles per hour. Use the function rand_float developed in this chapter which is :

    double rand_float (double a, double b)
    {
    return ((double) rand() / RAND_MAX ) * (b - a) + a;
    }

    Write a program to generate a data file name wind.dat that contains one hour of simulated wind speed. Each line of the data file should contain the time in seconds and the corresponding wind speed. The time should start with 0 seconds. The increment in time should be 10 seconds and the final line of the data file should correspond to 3600 seconds. The user should be prompted to enter the average wind speed and the range of values of the gusts.


    I'm just working in a menu selection where the user will be able to
    1 = Create a wind simulation
    2 = other
    3 = other
    4 = other
    5 = Quit


    I have the file created called wind.dat.
    The time from 0 seconds to 3600 seconds with an increment time of 10 seconds is done.
    Could you guys help me out just letting me know what should I do next.
    I'm not asking for code just hand example .
    Thanks
    This is what i have so far

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <iomanip>
    #include <cmath>
    
    using namespace std;
    
    void Add();
    void Delete();
    void Edit();
    void Find();
    
    double rand_float(double a, double b);
    
    int main()
    {
      
      char selection;
      	
    
    	do
      {
    	
        system("cls");
      	cout << "MENU\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': Add();    break;
          case '2': Delete(); break;	  
    	  case '3': Edit();   break;
          case '4': Find();   break;
          case '5':			  break;
          default: cout << '\a';
      	}
    
      }while( selection != '5' );
    
    	return 0;
    }//end main()
    
    //function definitions
    void Add()
    {
    	  system("cls");
    
    	  const double HIGH_GUSTS(22);
    	  const double LOW_GUSTS(-2);
    
    	  int i = 0;
    	  int Max_Seconds = 3600;
    	  double Avg_Wind, num1;
    	  
    	  
    	  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;
    
    	  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++)
    	  {
    
    	   	//Avg_Wind = rand_float (22 ,-2);
    
    	 	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 Delete()
    {
        system("cls");
    
        system("pause");
    }
    
    void Edit()
    {
    	system("cls");
       
        system("pause");
    }
    
    void Find()
    {
        system("cls");
      
        system("pause");
    }
    
    double rand_float (double a, double b)
    {
    	return ((double) rand() / RAND_MAX ) * (b - a) + a;
    }

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    Code:
    for (i = 0; i <= Max_Seconds; i++)
    	  {
    
    	   	//Avg_Wind = rand_float (22 ,-2);
    
    	 	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
    		
    		}
    
    
    
    		
    	  }

    >for (i = 0; i <= Max_Seconds; i++)
    if ( ( i % 10 ) == 0 )

    why do all then when u can set the increment to 10.

    >Avg_Wind = rand_float (22 ,-2);
    u r reassigning avg_wind,thats not avg_wind,but thats the quantity that should be added to avg_wind to simulate the wind at that second.

    >avg_wind=rand_float(22,-2)

    the range 22,-2 is not standard,that was just an example,u have to get that value from the user.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    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;
    }

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    I have a question guys!
    If I want to display * to show an histogram of the wind speed how could I do that
    Ex.
    If wind speed is 10 mph I like to displat ********** next to the number

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    take the sample case:
    avgwind =10;
    rangeofgusts(22,-2)

    so windatinstant=avgwind+randfloat(22,-2);







    >histogram
    u can do it something like this
    Code:
    for(int i=1;i<=windspeedatinstant;i++)
    cout<<"*";
    but windspeedatinstant should be an integer.
    Last edited by qqqqxxxx; 03-17-2006 at 01:10 AM.

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    Taking this example if I want to display for example when the Avg_Wind = 2 I want to display two ** next to it
    like the output will look like this


    1 *
    2 **
    3 ***
    4 ****
    5 *****
    6 ******

    So if I add just a * after Avg_Wind in this code it doesn't do anything so could you guys show me a way to this
    inside this for loop!
    Thank you
    Code:
    	  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
    		
    		}
    	 
    		
    	  }

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    use a function call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 11:29 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Replies: 6
    Last Post: 01-08-2006, 02:49 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM