Description: For practice, we will examine some real-world earthquake data. This
ID: 3554579 • Letter: D
Question
Description: For practice, 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 ("eqs7day-M1.txt") and the code included (see below) to read the data into your class and print it out. Once you have the data loaded into your vector of quakes objects (called
Explanation / Answer
using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<deque>
#include<fstream>
#include<map>
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;
}
/*float compare(const void *a , const void *b)
{
return ( (*(quake*)a).Depth - (*(quake*)b).Depth);
}
void func7(vector<quake>quakes)
{
cout<<"Assume that the worst earthquakes have the greatest depth, magnitude, and NST. Which quake was the