Write a program that uses a structure to store the following
Solution
Here is the code for you:
#include <iostream>
using namespace std;
struct airport
{
int numOfPlanesLanded;
int numOfPlanesTookOff;
int greatestNumOfPlanesLanded;
int smallestNumOfPlanesLanded;
};
int numOfLandings(struct airport months[])
{
int sum = 0;
for(int i = 0; i < 12; i++)
sum += months[i].numOfPlanesLanded;
return sum;
}
int numOfTakeOffs(struct airport months[])
{
int sum = 0;
for(int i = 0; i < 12; i++)
sum += months[i].numOfPlanesTookOff;
return sum;
}
int maxIndex(struct airport months[])
{
int max = 0;
for(int i = 1; i < 12; i++)
if(months[i].greatestNumOfPlanesLanded > months[max].greatestNumOfPlanesLanded)
max = i;
return max;
}
int minIndex(struct airport months[])
{
int min = 0;
for(int i = 1; i < 12; i++)
if(months[i].greatestNumOfPlanesLanded < months[min].greatestNumOfPlanesLanded)
min = i;
return min;
}
int main()
{
struct airport months[12];
for(int i = 0; i < 12; i++)
{
printf(\"Enter the number of planes landed in month %i: \", i+1);
scanf(\"%i\", &months[i].numOfPlanesLanded);
printf(\"Enter the number of planes taken off in month %i: \", i+1);
scanf(\"%i\", &months[i].numOfPlanesTookOff);
printf(\"Enter the greatest number of planes landed in a day in month %i: \", i+1);
scanf(\"%i\", &months[i].greatestNumOfPlanesLanded);
printf(\"Enter the smallest number of planes landed in a day in month %i: \", i+1);
scanf(\"%i\", &months[i].smallestNumOfPlanesLanded);
}
printf(\"Number of landings in this year: %i\ \", numOfLandings(months));
printf(\"Number of taken off in this year: %i\ \", numOfTakeOffs(months));
printf(\"Average number of landings per month: %.2f\ \", numOfLandings(months)/12.0);
printf(\"Average number of takeoffs per month: %.2f\ \", numOfTakeOffs(months)/12.0);
printf(\"Largest number of planes landed in a single day is %i, and month this occured is: %i\ \", months[maxIndex(months)].greatestNumOfPlanesLanded, maxIndex(months)+1);
printf(\"Smallest number of planes landed in a single day is %i, and month this occured is: %i\ \", months[minIndex(months)].smallestNumOfPlanesLanded, minIndex(months)+1);
}

