Earthquake Data

Earthquake Data

Description: For this assignment we will examine some real-world earthquake data. This data is the report of earthquakes from around the world for the last 7 days. First, you will need to create a class, called quake, to hold the earthquake data. The format is as follows:

Source (string)

ID (string)

Version (int)

DateTime (string)

Latitude (float)

Longitude (float)

Magnitude (float)

Depth (float)

NST (Number of stations reporting) (int)

Region (string)

Please use these names (minus the initial capitals) for your class field names. The only variable that is public is ID, the rest are private. You will need to write accessor and mutator functions for each variable (other than ID) and additionally a showQuake() function. You will then use the datafile included and the code included to read the data into your class and print it out. If you want an additional challenge, feel free to write the main on your own and don’t use my code other than for reference. Feel free to do both, of course. Once you have the data loaded into your vector of quakes objects (called ‘quakes’), you will need to do some data analysis. Each bit of analysis should be its own function. Your answers to the following should be output.

Details:

1. What was the worst earthquake, measured by magnitude, in the last week? (give the magnitude, depth, and region as your answer)

2. Which earthquake was ‘felt’ by the most stations? (SAA)

3. What was the average magnitude for the earthquakes in the last week?

4. What was the average depth of these earthquakes?

5. Repeat 3 and 4, but only include earthquakes with magnitude 2.0 or greater.

6. (harder) Which region reported the most earthquakes in the last week? (2 points)

7. (harder) List the regions and the total number of quakes reported in that region. (2 points)

8. (hardest) Is there a correlation between the magnitude and the depth? Why or why not? (4 pts)

9. (hardest) Is there a correlation between the magnitude and the NST? Why or why not? (4 pts)

10. (bonus) Assume that the worst earthquakes have the greatest depth, magnitude, and NST. Which quake was the ‘worst’? Give the Top 5 sorted by this metric. (10 points)

Code Bits: The read portion of the program has been provided; it goes in main, so please use it. It uses the function named in the standard format, so please make sure yours match.

“”””””””””

int main()

{

set up vector of quake objects

vector<quake> quakes;

open file for reading

ifstream infile;

infile.open(“eqs7day-M1.txt”);

check to see if the file opened correctly

if(infile.fail())

{

cout << “File not found.” << endl;

return 0;

}

set up temp variables for reading in the file

string tempString;

int tempInt;

float tempFloat;

char tempChar;

string tempDatetime;

while there is still data in the file..

while(infile.good())

{

set up temp quake object

quake temp;

tempDatetime = “”;

read source

check to make sure I am getting valid data

if(!getline(infile, tempString, ‘,’))

break;

cout << tempString << “, “;

temp.setSource(tempString);

read id

getline(infile, tempString, ‘,’);

temp.id = tempString;

cout << temp.id << “, “;

read version

getline(infile, tempString, ‘,’);

cout << tempString << “, “;

temp.setVersion(atoi(tempString.c_str()));

read first part of date time stamp

getline(infile, tempString, ‘,’);

tempDatetime+=tempString;

cout << tempString << “, “;

read second part of date time step, add it

getline(infile, tempString, ‘,’);

tempDatetime+=tempString;

cout << tempString << “, “;

read last part of date time stamp, add it

getline(infile, tempString, ‘,’);

tempDatetime+=tempString;

cout << tempString << “, “;

set the datetime

cout << tempDatetime << “, “;

temp.setDatetime(tempDatetime);

read the latitude

getline(infile, tempString, ‘,’);

cout << tempString << “, “;

temp.setLatitude(atof(tempString.c_str()));

read the longitude

getline(infile, tempString, ‘,’);

cout << tempString << “, “;

temp.setLongitude(atof(tempString.c_str()));

read the magnitude

getline(infile, tempString, ‘,’);

cout << tempString << “, “;

temp.setMagnitude(atof(tempString.c_str()));

read the depth

getline(infile, tempString, ‘,’);

cout << tempString << “, “;

temp.setDepth(atof(tempString.c_str()));

read the number of stations reporting

getline(infile, tempString, ‘,’);

cout << tempString << “, “;

temp.setNST(atoi(tempString.c_str()));

read the region

getline(infile, tempString);

cout << tempString << “, “;

temp.setRegion(tempString);

push temp to the vector of quakes

quakes.push_back(temp);

if you want to see the records one line at a time…

cout << “Next? “;

cin >> tempString;

}

show the quake data for verification of proper reading

for (int i = 0; i < quakes.size(); i++)

{

quakes[i].showQuake();

}

return 0;

}