Solution
Darshan answered on
Oct 23 2021
assignment.cpp
assignment.cpp
 C++ implementation to read
 file word by word
#includeÂ
its/stdc++.h
using namespace std;
void loadConfiguration();
void generateWindSpeedData(vecto
float>Â f);
void generateStormData(vecto
float>Â f);
void generateBurstData(vecto
float>Â f);
void saveToFile();
vecto
string>Â v;
vecto
float>Â f;
int wind[362];
int strome[362];
int burst[362];
int main()
{
    loadConfiguration();
    generateWindSpeedData(f);
    generateStormData(f);
    generateBurstData(f);
    saveToFile();
    return 0;
}
void generateWindSpeedData(vecto
float>Â 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(vecto
float>Â 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(vecto
float> 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,...