Sep 30, 2015 at 1:14am UTC
#include <iostream>
#include <string>
using namespace std;
struct MonthlyInfo
{
int totalLanded;
int totalDepated;
int greatestLanded;
int leastLanded;
};
enum Month {January, February, March, April, May, June, July, August, September, October, November, December};
void displayMonth(Month);
void getGreatest(int [], int);
int main()
{
double totalLandedyear = 0.0;
double totalDepartedyear = 0.0;
double avgLanded = 0.0;
double avgDeparted = 0.0;
MonthlyInfo *months;
months = new MonthlyInfo[12];
Month flightMonth;
cout << "Enter the data for each month" <<endl;
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
{
displayMonth(flightMonth);
cout << ":" <<endl;
cout << "Total number of planes landed: ";
cin >> months[flightMonth].totalLanded;
cout << "Total number of planes departed: ";
cin >> months[flightMonth].totalDepated;
cout << "Greatest number of planes landed in one day: ";
cin >> months[flightMonth].greatestLanded;
cout << "Least number of planes landed in one day: ";
cin >> months[flightMonth].leastLanded;
cout << "----------------------------------------------" <<endl;
}
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
totalLandedyear += months[flightMonth].totalLanded;
cout << "Total planes laned for the year: " << totalLandedyear <<endl;
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
totalDepartedyear += months[flightMonth].totalDepated;
cout << "Total planes departed for the year: " << totalDepartedyear <<endl;
avgLanded = totalLandedyear/12;
cout << "Average monthly number of landed planes: " << avgLanded <<endl;
avgDeparted = totalDepartedyear/12;
cout << "Average monthly number of departed planes: " << avgDeparted <<endl;
int leastPlanes;
int greatestPlanes;
greatestPlanes = months[January].greatestLanded;
for (flightMonth = February; flightMonth <= December; static_cast<Month>(flightMonth + 1))
{
if (months[flightMonth].greatestLanded > greatestPlanes)
greatestPlanes = months[flightMonth].greatestLanded;
}
cout << "Greatest number of planes landed on any one day: "<< greatestPlanes <<endl;
leastPlanes = months[January].leastLanded;
for (flightMonth = February; flightMonth <= December; static_cast<Month>(flightMonth + 1))
{
if (months[flightMonth].leastLanded < leastPlanes)
leastPlanes = months[flightMonth].leastLanded;
}
cout << "Least number of planes landed on any one day: "<< leastPlanes <<endl;
system("pause");
return 0;
}
void displayMonth (Month d)
{
switch (d)
{
case January : cout << "January";
break;
case February : cout << "February";
break;
case March : cout << "March";
break;
case April : cout << "April";
break;
case May : cout << "May";
break;
case June : cout << "June";
break;
case July : cout << "July";
break;
case August : cout << "August";
break;
case September : cout << "September";
break;
case October : cout << "October";
break;
case November : cout << "November";
break;
case December : cout << "December";
break;
}
}