1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
//Define a class to represent each Seismic Activity measurement event...
class RedwoodBaySeismicData {
string LocationID; //This is the station that owns this piece of data…
string Date; //The date that the values were collected…
string Time; //The time of day that the values were collected…
double SeismicSize; //Magnitude of Earthquake
public:
RedwoodBaySeismicData();
RedwoodBaySeismicData(string, string, string, double);
//The first group of member functions are used to change values...
//Functions are defined in the form of inlines.
void SetID(string ID) { LocationID = ID; }
void SetDate(string Day) { Date = Day; }
void SetTime(string Hour) { Time = Hour; }
void SetSeismicSize(double Magnitude) {SeismicSize = Magnitude; }
//The second group allows controlled access to individual value in the class...
string GetID() { return LocationID; }
string GetDate() {return Date; }
string GetTime() {return Time; }
double GetSeismicSize() { return SeismicSize;}
};
//The default constructor sets the private variable members to a harmless value...
RedwoodBaySeismicData::RedwoodBaySeismicData()
{
LocationID = "";
Date = "";
Time = "";
SeismicSize = 0.0;
}
//This initializing constructor allows you to create a object with value already set...
RedwoodBaySeismicData::RedwoodBaySeismicData(string ID, string Day, string Hour, double Magnitude)
{
LocationID = ID;
Date = Day;
Time = Hour;
SeismicSize = Magnitude;
}
class RedwoodBayDataList {
vector<RedwoodBaySeismicData> RedwoodBayDataSpots; //Create a collection of location information...
string FileName ;
public:
RedwoodBayDataList() {FileName = "RedwoodBaySeismicEventList.data";}
void PostSeismicInfo();
void WeeklyReport();
};
//Allow the user to post the values for each location...
void RedwoodBayDataList::PostSeismicInfo()
{
int K;
string Line, ID, Date, Hour;
double Magnitude;
fstream InFile("RedwoodBaySeismicEventList.data", ios::in);
//...then get the values for each location...
RedwoodBaySeismicData Buffer;
cout << "\n\t=============================================================" << endl; //This section is the report...it's really all about the formatting...
cout << "\tWeekly Report" << endl;
cout << "\t===============================================================" << endl;
cout << "\tLocation\tDate\tHour\tMagnitude" << endl;
cout << "\t===============================================================" << endl;
for(size_t K = 0; K < RedwoodBayDataSpots.size(); ++K) {
getline(InFile, Line);
ID = Line.substr(0,4);
Date = Line.substr(6,7);
Hour = Line.substr(9,3);
istringstream buf(Line.substr(5,2));
buf>> Magnitude;
RedwoodBayDataSpots[K].SetID(ID);
RedwoodBayDataSpots[K].SetDate(Date);
RedwoodBayDataSpots[K].SetTime(Hour);
RedwoodBayDataSpots[K].SetSeismicSize(Magnitude);
cout << "\t" << RedwoodBayDataSpots[K].GetID() << "\t" << RedwoodBayDataSpots[K].GetDate() << "\t" << RedwoodBayDataSpots[K].GetTime() << "\t" << RedwoodBayDataSpots[K].GetSeismicSize();
}
cout << "\t===============================================================\n\n" << endl;
}
//Declare the functions...
void RunIT();
void Menu();
int main()
{
RunIT();
}
//This function implements a simple command processor...
void RunIT()
{
RedwoodBayDataList RedwoodBayDataSpots;
string Command = "";
while(Command != "Quit") {
Menu();
cout << "Command: ";
getline(cin, Command);
if(Command == "Report")
RedwoodBayDataSpots.PostSeismicInfo();
}
}
//This function tells the user what he or she can do...
void Menu()
{
cout << "Choices...................................................." << endl;
cout << "-----------------------------------------------------------" << endl;
cout << "\tReport...displays the report." << endl;
cout << "\tQuit.....exits the program." << endl;
cout << "-----------------------------------------------------------" << endl;
}
|