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
|
#ifndef MANATEESIGHTING_H
#define MANATEESIGHTING_H
class ManateeSighting
{
private:
std::string location;
std::string sightDate[50];
int manateeCount[50];
int numCount;
double avg; // Average count for location
int maxCnt; // Maximum count for location
std::string maxDate; // Date maximum recorded
std::string monthWithMostSightings;
public:
// Constructor
ManateeSighting::ManateeSighting(std::string loc, std::string date[],
int cnt[], int numOfFlights)
{
for(int x = 0; x < numOfFlights; x++)
{
sightDate[x] = date[x];
manateeCount[x] = cnt[x];
}
numCount = numOfFlights;
location = loc;
}
std::string ManateeSighting::GetLocation()
{
return location;
}
std::string ManateeSighting::SetLocation(std::string loc)
{
location = loc;
}
std::string ManateeSighting::MonthWithMostSightings()
{
DetermineMax();
return monthWithMostSightings;
}
double ManateeSighting::Avg()
{
CalculateAvg();
return avg;
}
int ManateeSighting::MaxCnt()
{
DetermineMax();
return maxCnt;
}
std::string MaxDate()
{
DetermineMax();
return maxDate;
}
// Determine the average number of sightings per location
void ManateeSighting::CalculateAvg()
{
int total = 0;
for each(int c in manateeCount)
total += c;
avg = total / numCount;
}
// Determines the maximum number of manatees
// sighted on any one given date. Uses a parallel
// array to determine the actual date.
// Calls method to set the month name.
void ManateeSighting::DetermineMax()
{
int maxCntIndex = 0;
for (int i = 1; i < numCount; i++)
{
if (manateeCount[i] > manateeCount[maxCntIndex])
maxCntIndex = i;
}
maxCnt = manateeCount[maxCntIndex];
maxDate = sightDate[maxCntIndex];
monthWithMostSightings = ReturnMonth(maxDate);
}
// Given a date in the format of mm/dd/yyyy
// the name of the month is returned.
std::string ManateeSighting::ReturnMonth(std::string someDate)
{
std::string monthName[] = {"January", "February", "March",
"April", "May", "June", "July",
"August", "September",
"October", "November",
"December"};
int datePosition = someDate.find('/');
std::string strDateOfMonth = someDate.substr(0, datePosition);
int dateOfMonth = FromString<int>(strDateOfMonth);
return monthName[dateOfMonth - 1];
}
template<typename T>
T FromString(const std::string& str)
{
std::istringstream ss(str);
T ret;
ss >> ret;
return ret;
}
}
#endif
|