Hello I am fairly new to C++ and I am having a small issue with this project. The problem that I am having lies in the last part of the MAIN FUNCTION where I need to display the "greatest" and "least" planes landed in a single day out of a whole year. I have the correct number for the landings and the departures but I am struggling on getting what month of the year these two values occurred in. Here is the specifications for this part of the assignment.
• Largest number of planes that landed in a single day (in the entire year) and the month in which it occurred
• Smallest number of planes that landed in a single day (in the entire year) and the month in which it occurred
If anyone could lend some assistance that would be great.
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
//data structure to store all the information from the user
struct Airport
{
int totalLanded;
int totalTookOff;
int greatestLanded;
int leastLanded;
};
//enumerated list of all the months of the year to let the displayMonth function display the correct month
enum Month {January, Febuary, March, April, May, June, July, August, September, October, November, December};
//function prototype
void displayMonth(Month date);
int main()
{
//starting variables values for the equation for the end result
double totalLandedPerYear = 0.0;
double totalDepartedPerYear = 0.0;
double averageLanded = 0.0;
double averageDeparted = 0.0;
Airport *months;
months = new Airport[12];
Month flightMonth;
//for loop to get the data from the user
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
{
cout << "Please enter the number of planes that landed in ";
displayMonth(flightMonth);
cout << ": ";
cin >> months[flightMonth].totalLanded;
cout << "Please enter the number of planes that departed in ";
displayMonth(flightMonth);
cout << ": ";
cin >> months[flightMonth].totalTookOff;
cout << "Please enter the greatest number of planes that landed on a single day in ";
displayMonth(flightMonth);
cout << ": ";
cin >> months[flightMonth].greatestLanded;
cout << "Please enter the least number of planes that landed on a single day in ";
displayMonth(flightMonth);
cout << ": ";
cin >> months[flightMonth].leastLanded;
}
//for loop to add all the landings per month
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
{
totalLandedPerYear += months[flightMonth].totalLanded;
}
//for loop to add all the departures per month
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
{
totalDepartedPerYear += months[flightMonth].totalTookOff;
}
//equation to get the average landings per year
averageLanded = totalLandedPerYear / 12;
cout << "The average monthly landings for the year is " << averageLanded << endl;
//equation to get the average departures per year
averageDeparted = totalDepartedPerYear / 12;
cout << "The average monthly departures for the year is " << averageDeparted << endl;
cout << "The total landings for the year is " << totalLandedPerYear << endl;
cout << "The total departures for the year is " << totalDepartedPerYear << endl;
int greatestPlanes;
int leastPlanes;
//for loop to find the month with the most landings per year
greatestPlanes = months[January].greatestLanded;
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
{
if (months[flightMonth].greatestLanded > greatestPlanes)
{
greatestPlanes = months[flightMonth].greatestLanded;
}
}
cout << "The greatest number of planes that landed in a single day is " << greatestPlanes;
cout << " which occured in the month of " << endl;
//for loop to find the month with the most departures per year
leastPlanes = months[January].leastLanded;
for (flightMonth = January; flightMonth <= December; flightMonth = static_cast<Month>(flightMonth + 1))
{
if (months[flightMonth].leastLanded < leastPlanes)
{
leastPlanes = months[flightMonth].leastLanded;
}
}
cout << "The least number of planes that landed in a single day is " << leastPlanes;
cout << " which occured in the month of " << endl;
cin.get();
cin.ignore();
return 0;
}
//function to display the month for the user input phase of the program
void displayMonth(Month date)
{
switch (date)
{
case January: cout << "January";
break;
case Febuary: cout << "Febuary";
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;
}
}
#include <iomanip>
#include <iostream>
#include <string>
//data structure to store all the information from the user
struct Airport
{
int totalLanded;
int totalTookOff;
int greatestLanded;
int leastLanded;
};
// enumerated list of all the months of the year to let the displayMonth
// function display the correct month
enum Month {January, Febuary, March, April, May, June,
July, August, September, October, November, December};
//function prototype
constchar* displayMonth(Month date);
int main()
{
Airport months[12] {};
//for loop to get the data from the user
for ( Month flightMonth = January;
flightMonth <= December;
flightMonth = static_cast<Month>(flightMonth + 1) )
{
std::cout << "Please enter the number of planes that landed in "
<< displayMonth(flightMonth) << ": ";
std::cin >> months[flightMonth].totalLanded;
std::cout << "Please enter the number of planes that departed in "
<< displayMonth(flightMonth) << ": ";
std::cin >> months[flightMonth].totalTookOff;
std::cout << "Please enter the greatest number of planes that landed ""on a single day in " << displayMonth(flightMonth) << ": ";
std::cin >> months[flightMonth].greatestLanded;
std::cout << "Please enter the least number of planes that landed on ""a single day in " << displayMonth(flightMonth) << ": ";
std::cin >> months[flightMonth].leastLanded;
}
//for loop to add all the landings per month
double totalLandedPerYear = 0.0;
for ( Month flightMonth = January;
flightMonth <= December;
flightMonth = static_cast<Month>(flightMonth + 1) )
{
totalLandedPerYear += months[flightMonth].totalLanded;
}
//for loop to add all the departures per month
double totalDepartedPerYear = 0.0;
for ( Month flightMonth = January;
flightMonth <= December;
flightMonth = static_cast<Month>(flightMonth + 1) )
{
totalDepartedPerYear += months[flightMonth].totalTookOff;
}
//equation to get the average landings per year
double averageLanded = totalLandedPerYear / 12;
std::cout << "The average monthly landings for the year is "
<< averageLanded << '\n';
//equation to get the average departures per year
double averageDeparted = totalDepartedPerYear / 12;
std::cout << "The average monthly departures for the year is "
<< averageDeparted << '\n';
std::cout << "The total landings for the year is " << totalLandedPerYear << '\n';
std::cout << "The total departures for the year is " << totalDepartedPerYear << '\n';
//for loop to find the month with the most landings per year
int greatestPlanes = months[January].greatestLanded;
Month mostLanded = January;
for ( Month flightMonth = January;
flightMonth <= December;
flightMonth = static_cast<Month>(flightMonth + 1) )
{
if (months[flightMonth].greatestLanded > greatestPlanes)
{
greatestPlanes = months[flightMonth].greatestLanded;
mostLanded = flightMonth;
}
}
std::cout << "The greatest number of planes that landed in a single day is "
<< greatestPlanes << " which occured in the month of "
<< displayMonth(mostLanded) << '\n';
//for loop to find the month with the most departures per year
int leastPlanes = 9999; // you need a big number here
Month leastArrivals = January;
for ( Month flightMonth = January;
flightMonth <= December;
flightMonth = static_cast<Month>(flightMonth + 1) )
{
if (months[flightMonth].leastLanded < leastPlanes)
{
leastPlanes = months[flightMonth].leastLanded;
leastArrivals = flightMonth;
}
}
std::cout << "The least number of planes that landed in a single day is "
<< leastPlanes << " which occured in the month of "
<< displayMonth(leastArrivals) << '\n';
std::cin.get();
std::cin.ignore();
return 0;
}
//function to display the month for the user input phase of the program
constchar* displayMonth(Month date)
{
switch (date)
{
case January: return"January";
case Febuary: return"Febuary";
case March: return"March";
case April: return"April";
case May: return"May";
case June: return"June";
case July: return"July";
case August: return"August";
case September: return"September";
case October: return"October";
case November: return"November";
case December: return"December";
}
}