CPE Assignment Goal: flight simulation wind speed Have an already created file that has certain parameters in it First line: average wind speed, gust value, total duration of the simulation that you...

1 answer below »


CPE Assignment



  • Goal: flight simulation wind speed

  • Have an already created file that has certain parameters in it


    • First line: average wind speed, gust value, total duration of the simulation that you want to create, step (every 10 seconds, outfit the wind speed and storm - make simulation work every 10 seconds)


      • Example, 7200 seconds, step is 30 ~ every 30 seconds, simulator will check for whatever its checking for


    • Second line: storm probability (value in percentage), minimum and maximum storm amplitude, minimum and maximum duration for the storm


      • Checks if storm happens or not


        • If storm happens - randomize its strength between the possible minimum and maximum amplitude + randomize its duration between the minimum and maximum duration



    • Third line: microburst probability, minimum and maximum amplitude, minimum duration and maximum duration


      • Microburst only happens in storm

      • Example: 0.75% or 7% or 70% or 30%










Step 1



  • Open file you just created (created manually using text document and call it simulation configuration) and read values in that file into variables you create in the program (you can read them into arrays)







Step 2



  • Generate windspeed

  • Gust value

  • Gust value can go with or against wind speed - minimum and maximum wind speed you can have


    • Maximum wind speed = (average windspeed + gust value)

    • Minimum wind speed = (average windspeed - gust value)

    • To generate windspeed - have a random value between max and min for every iteration/step


      • For every step you generate a random number

      • Can do that using a loop



  • Generate random windspeed for each iteration (simulation time / step) and store in different variable or array or same variable you loop

  • Print variables into file I create using the program (not manually)


    • Print time, random wind speed that you got in that file








Step 3



  • Storm probability

  • Generate random number between 0 and 1

  • If that random number is less than the probability, then a storm happens

  • If that random number is more than the probability, then it doesn’t happen

  • When a storm happens,

  • Random wind speed created and storm speed (additional value for wind created in a storm)

  • If there’s a storm, create a random storm speed for the additional wind speed in a storm and create a duration


    • Give these values 0 if there is no storm


  • Create a file

  • Output in it the time, if there is a storm, the storm speed, the storm duration, and average/randomized windspeed







Step 4



  • If probability happens, generate a random number for microburst speed and duration and output them into a file and add them to the storm speed and wind speed

  • Has to be a storm for microburst to exist - need to have if statement before microburst checking


    • If there is a storm then there might exist a microburst depending on the probability


  • Output everything in file







Step 5



  • Add average wind speed + storm speed + microburst speed and output them in the file depending on time

Answered 2 days AfterOct 20, 2021

Answer To: CPE Assignment Goal: flight simulation wind speed Have an already created file that has certain...

Darshan answered on Oct 23 2021
122 Votes
assignment.cpp
assignment.cpp
// C++ implementation to read
// file word by word
#include 
using namespace std;
void loadConfiguration();
void generateWindSpeedData(vector f);
void generateStormData(vector f);
void generateBurstData(vector f);
void saveToFile();
vector v;
vector f;
int wind[362];
int strome[362];
int burst[362];
int main()
{
    loadConfiguration();
    generateWindSpeedData(f);
    generateStormData(f);
    generateBurstData(f);
    saveT
oFile();
    return 0;
}
void generateWindSpeedData(vector f)
{
    int random;
    int min = f[0]-f[1];
    int max = f[0]+f[1];
    srand((unsigned) time(NULL));
 int j=0;
  ofstream MyFile("WindSpeedData.txt");
    for(int i=0;  i< f[2]*3600;)
    {
        MyFile << i << ",";
        random = min + rand() % (( max + 1 ) - min);
        MyFile << random << endl;
        wind[j]=random;
        i=i+f[3];
        j=j+1;
    }
  MyFile.close(); 
}
void generateStormData(vector f)
{
    int random,random2;
   ofstream MyFile("StormData.txt");
    int min = f[0]-f[1];
    int max = f[0]+f[1];
    int min2 = f[5]-f[6];
    int max2 = f[5]+f[6];
    int min3 = f[7]-f[8];
    int max3 = f[7]+f[8];
int j=0;
    for(int i=0;  i< f[2]*3600;)
    {
        MyFile << i << ",";
        random = rand() % 2;
        if( random < f[4])
        {
            random2 = min2 + rand() % (( max2 + 1 ) - min2);
            MyFile << random2 << ",";
            strome[j]=random2;
            random = min3 + rand() % (( max3 + 1 ) - min3);
            MyFile << random << ",";
            random = min + rand() % (( max + 1 ) - min);
            MyFile << random+random2 << endl;
        }
        else
        {
            MyFile << 0 << endl;
                        strome[j]=0;
        }
        i=i+f[3];
                j=j+1;
    }
  MyFile.close();
}
void generateBurstData(vector f )
{
            int random,random2;
   ofstream MyFile("BurstData.txt");
    int min = f[0]-f[1];
    int max = f[0]+f[1];
    int min2 = f[10]-f[11];
    int max2 = f[10]+f[11];
    int min3 = f[12]-f[13];
    int max3 = f[12]+f[13];
    int j=0;
    for(int i=0;  i< f[2]*3600;)
    {
        MyFile << i << ",";
        random = rand() % 2;
        if( random < f[9])
        {
            random2 = min2 + rand() % (( max2 + 1 ) - min2);
            MyFile << random2 << ",";
            burst[j]=random2;
 
            random = min3 + rand() % (( max3 + 1 ) - min3);
            MyFile << random << ",";
            random = min + rand() % (( max + 1 ) - min);
            MyFile << random+random2 << endl;
        }
        else
        {
            MyFile << 0 << endl;            burst[j]=0;
        }
        i=i+f[3];
                j=j+1;
    }
  MyFile.close();
}
void loadConfiguration()
{

    fstream file;
    string word, t, q, filename;
    filename = "simulationConfiguration.txt";
    file.open(filename.c_str());
    while (file >> word)
    {
            stringstream ss(word);
            while (ss.good()) {
        string substr;
        getline(ss, substr, ',');
        v.push_back(substr);
    }
    }

 for_each(v.begin(), v.end(), [&f](const string &ele) { f.push_back(stod(ele)); });
 
      file.close();
}
void saveToFile()
{
    int sum[362];

    ofstream MyFile("WindSimulation.txt");

    for(int i=0;i<360;i++)
    {
        MyFile << i << ",";
        sum[i] = wind[i] + burst[i] + strome[i];
        MyFile << sum[i] << ",";
        if(strome[i]==0)
                MyFile << 0 << endl;
        else
                MyFile << 1 << endl;
    }
MyFile.close();
}
BurstData.txt
0,4,0,12
10,3,2,13
20,0
30,0
40,6,2,18
50,3,0,15
60,0
70,0
80,4,4,14
90,6,4,14
100,7,4,15
110,5,3,16
120,6,1,15
130,0
140,7,0,16
150,6,3,16
160,3,3,11
170,7,1,18
180,0
190,3,4,15
200,0
210,5,0,16
220,6,2,15
230,0
240,0
250,7,0,18
260,0
270,3,2,13
280,0
290,0
300,0
310,3,2,11
320,0
330,0
340,4,1,16
350,0
360,0
370,7,3,17
380,0
390,5,0,13
400,3,3,11
410,5,4,16
420,4,4,13
430,0
440,0
450,0
460,7,4,17
470,5,4,13
480,5,4,14
490,0
500,0
510,0
520,0
530,0
540,0
550,6,1,15
560,0
570,3,2,13
580,6,1,18
590,5,4,14
600,0
610,0
620,0
630,0
640,5,0,13
650,4,3,15
660,3,3,11
670,7,0,15
680,4,4,14
690,0
700,5,0,16
710,0
720,7,4,17
730,0
740,0
750,7,4,18
760,0
770,3,4,12
780,4,1,12
790,4,4,12
800,0
810,6,0,18
820,7,0,15
830,7,2,18
840,0
850,0
860,0
870,5,2,14
880,3,0,11
890,0
900,0
910,0
920,0
930,0
940,0
950,5,3,15
960,5,3,16
970,0
980,7,1,15
990,0
1000,6,0,16
1010,5,1,13
1020,7,0,16
1030,6,2,15
1040,0
1050,0
1060,0
1070,0
1080,0
1090,0
1100,4,1,16
1110,0
1120,3,3,14
1130,0
1140,0
1150,0
1160,3,4,14
1170,3,3,11
1180,5,3,17
1190,0
1200,0
1210,0
1220,3,1,13
1230,3,1,13
1240,0
1250,0
1260,0
1270,4,0,15
1280,3,0,11
1290,0
1300,3,4,15
1310,6,2,17
1320,0
1330,0
1340,0
1350,0
1360,0
1370,0
1380,3,4,14
1390,6,0,16
1400,3,2,13
1410,3,1,15
1420,0
1430,0
1440,4,2,16
1450,3,1,14
1460,3,0,14
1470,0
1480,0
1490,0
1500,0
1510,6,0,18
1520,3,0,11
1530,7,1,18
1540,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here