Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EGR-126 - Lab 10 – Chapter 7 – One – Dimensional Arrays For this program, we wil

ID: 3684740 • Letter: E

Question

EGR-126 - Lab 10 – Chapter 7 – One – Dimensional Arrays

For this program, we will create two one-dimensional arrays:

int id[MAX_SIZE]

int mph[MAX_SIZE]

We will also read in an input file, storm1.txt, that contains some data about hurricanes:

An identification number for each hurricane

The max wind speed mph;

storm 1;

file       edit       format view help

142      38

153     135

162     59

177     76

181     63

We will read in this input file, and using the wind speed mph, determine the category of each hurricane. We will also determine the hurricane with the fastest speed.We will print a report

QUESTION:

from project chapter7_5.cpp below , create an input file called storm1.txt (content as shown above), and it must be placed in the following directory:

. . . Projectschapter7_5chapter7_5

Write this code and get it working.Paste you code here:

Paste a screenshot of the output screen:

Given: a project was created in c++ ( chapter7_5.cpp)

/*program chapter 7_5*/

/*this program reads storm values from a data file */

#include

#include

using namespace std;

//function prototypes.

double category(double speed);

int main()

{

// declare and initialize variables.

const int MAX_size = 500;

int k(0), npts, id[MAX_size];

double mph[MAX_size], max(0);

ifstream fin("storml.txt");

if (fin.fail())

{

cerr << " could not open file storml.txt" << endl; exit(1);

}

// read data and determine maximun mph.

fin >> id[k] >> mph[k];

while (!fin.fail())

{

if (mph[k]) > max)

{

max = mph[k];

}

++k;

fin >> id[k] >> mph[k];

}// end while

npts = k;

//print hurricaine report.

if (max >= 74)

{

cout << " storm that qualify as hurricanes "

<< " identification peak wind (mph) category ";

}

else

{

cout << " no hurricanes in the file ";

}

for (k = 0; k < npts; ++k)

{

if (mph[k] >= 74)

{

if (mph[k] == max)

{

cout << " " << id[k] << "* " << mph[k] << mph [k] << " "

<< category(mph[k]) << endl;

}

else

{

cout << " " << id[k] << "* " << mph[k] << mph[k] << " "

<< category(mph[k]) << endl;

}

}//end if k

}// end for

fin.close();

return 0;

}

/*this function determines the hurricaine intensity*/

/*category.*/

double category(double speed)

{

//declare variables.

int intensity(1);

//determine category.

if (speed >= 155)

{

intensity = 5;

}

else if (speed >= 131)

{

intensity = 4;

}

else if (speed >= 111)

{

intensity = 3;

}

else if (speed >= 96)

{

intensity = 2;

}

return intensity;

}

Explanation / Answer

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

int main()

{

ifstream file("strom.txt");

int size;

file >> size;

vector<int> mph(size);

int x = 0;

while(x < size && file >> mph[n])

{

++x;

}

for(int x = 0; x < size; ++x)

{

cout << mph[x];

category (mph);

}

cout << ' ';

}

double category(double speed)

{

//declare variables.

int intens;

//determine category.

if (mph >= 155)

{

intens = 5;

}

else if (mph >= 131)

{

intens= 4;

}

else if (mph >= 111)

{

intens = 3;

}

else if (mph >= 96)

{

intens = 2;

}

return intens;

}