Write a program that uses a structure to store the following information for a p
ID: 671214 • Letter: W
Question
Write a program that uses a structure to store the following information for a particular month at the local airport: • Total number of planes that landed
• Total number of planes that departed
• Greatest number of planes that landed in a given day that month • Least number of planes that landed in a given day that month
The program should have an array of twelve structures to hold travel information for the entire year. The program should prompt the user to enter data for each month . Once all data is entered, the program should calculate and output the average monthly number of landing planes, the average monthly number of departing plane, the total number of landing and departing planes for the year, and the greatest and least number of planes that landed on any one day and which month it occurred in.
Explanation / Answer
#include <iostream>
using namespace std;
struct airport
{
int landed, departed, GNP, LNP;
};
int getHighest();
int getLowest();
int month[12];
int main()
{
for (int count = 1; count < 12; count++)
{
cout << "How many planes landed in month " << month[count] << "?" << endl;
cin >> month[count].landed >> endl;
cout << "How many planes departed in month " << month[count] << "?" << endl;
cin >> month[count].departed >> endl;
cout << "Please enter the greatest number of planes landed on a given day " << endl;
cin >> month[count].GNP >> endl;
cout << "Please enter the least number of planes landed on a given day" << endl;
cin >> month[count].LNP >> endl;
}
cout << "Planes summary" << endl;
cout << endl;
for (int i = 1; i < 12; i++)
cout << month[i] << " had " << month[i].landed << endl;
return 0;
}
// function to get the highest amount of planes landed in a month
int getHighest()
{
int highest;
highest = month[1].landed;
for (int count = 1; count < 12; count++)
{
if (month[count].landed > highest)
highest = month[count].landed;
}
return highest;
}
// function to get the lowest amount of planes landed in a month
int getLowest()
{
int lowest;
lowest = month[1].landed;
for (int count = 1; count < 12; count++)
{
if (month[count].landed < lowest)
lowest = month[count].landed;
}
return lowest;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.