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

Description : For this assignment we will examine some real-world earthquake dat

ID: 652640 • Letter: D

Question

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

Explanation / Answer

Program:-

#include<iostream>

#include<cstdio>

#include<cmath>

#include<cstdlib>

#include<cstring>

#include<string>

#include<algorithm>

#include<vector>

#include<stack>

#include<deque>

#include<fstream>

#include<map>

using namespace std;

class quake

{

     private:

          string Source;

          int Version;

          string DateTime;

          float Lattitude;

          float Longitude;

          float Magnitude;

          float Depth;

          int NST;

          string Region;

     public :

          string id;

    

     //accessors

     string getsource()

     {

          return Source;

     }

     int version()

     {

          return Version;

     }

     string getDateTime()

     {

          return DateTime;

     }

     float getLongitude()

     {

          return Longitude;

     }

     float getLattitude()

     {

          return Lattitude;

     }

     float getMagnitude()

     {

          return Magnitude;

     }

     float getDepth()

     {

          return Depth;

     }

     int getNST()

     {

          return NST;

     }

     string getRegion()

     {

          return Region;

     }

     // mutators

     void setSource(string a)

     {

          Source = a;

     }

     void setVersion(int a)

     {

          Version = a;

     }

     void setDatetime(string a)

     {

          DateTime = a;

     }

     void setLattitude(float a)

     {

          Lattitude = a;

     }

     void setLongitude(float a)

     {

          Longitude =a;

     }

     void setMagnitude(float a)

     {

          Magnitude =a;

     }

     void setNST(int a)

     {

          NST = a;

     }

     void setRegion(string a)

     {

          Region = a;

     }

     void setDepth(float a)

     {

          Depth = a;

     }

    

     void showquake()

     {

          cout<<" deatils about the quake is"<<endl;

          cout<<id<<endl;

          cout<<Source<<endl;

          cout<<Version<<endl;

          cout<<DateTime<<endl;

          cout<<Longitude<<endl;

          cout<<Lattitude<<endl;

          cout<<Magnitude<<endl;

          cout<<Depth<<endl;

          cout<<Region<<endl;

     }

};

void func1(vector <quake>quakes)

{

     int index=0;

     float max;

     cout<<"What was the worst earthquake, measured by magnitude, in the last week? "<<endl;

     max = quakes[0].getMagnitude();

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

     {

          if(max < quakes[i].getMagnitude())

          {

               max = quakes[i].getMagnitude();

               index = i;

          }

     }

     int i = index;

     cout<<quakes[i].getMagnitude()<<endl;

     cout<<quakes[i].getDepth()<<endl;

     cout<<quakes[i].getRegion()<<endl;

     cout<<"-------------------------"<<endl<<endl;

}

void func2(vector<quake>quakes)

{

     cout<<"What was the average magnitude for the earthquakes in the last week?"<<endl;

     float sum = 0;

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

     {

          sum += quakes[i].getMagnitude();

     }

     cout<<(double)(sum/(quakes.size()))<<endl;

     cout<<"-------------------------"<<endl<<endl;

}

void func3(vector<quake>quakes)

{

     cout<<"What was the average depth of these earthquakes?"<<endl;

     float sum = 0;

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

     {

          sum += quakes[i].getDepth();

     }

     cout<<(double)(sum/(quakes.size()))<<endl;

     cout<<"-------------------------"<<endl<<endl;

}

void func4(vector<quake>quakes)

{

     int index=0,max;

     cout<<"Which region reported the most earthquakes in the last week?"<<endl;

     max = quakes[0].getNST();

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

     {

          if(max < quakes[i].getNST())

          {

               max = quakes[i].getNST();

               index = i;

          }

     }

     int i = index;

     cout<<quakes[i].getRegion()<<endl;

     cout<<"-------------------------"<<endl<<endl;

}

void func5(vector<quake>quakes)

{

     cout<<"List the regions and the total number of quakes reported in that region."<<endl;

     cout<<"region NST"<<endl;

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

     {

          cout<<quakes[i].getRegion()<<" "<<quakes[i].getNST()<<endl;

     }

     cout<<"-------------------------"<<endl<<endl;

}

void func6(vector<quake>quakes)

{

     cout<<"Which earthquake was felt by the most stations?"<<endl;

     map<string, int>m;

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

     {

          m[quakes[i].id] = 0;

     }

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

     {

          m[quakes[i].id] += 1;

     }

    

     int max = INT_MIN,index;

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

     {

          if(m[quakes[i].id] > max)

          {

               max = m[quakes[i].id];

               index = i;

          }

     }

     cout<<quakes[index].id<<endl;

     cout<<"-------------------------"<<endl<<endl;

}

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.setLattitude(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);

     }

     func1(quakes);

     func2(quakes);

     func3(quakes);

     func4(quakes);

     func5(quakes);

     func6(quakes);

     return 0;

}