Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following c++ program. Write a program that does monitors landings and

ID: 3686840 • Letter: W

Question

Write the following c++ program.

Write a program that does monitors landings and takeoffs at a given airport. The program uses a structure, airport, that consists of the following elements: Number of planes that landed in a given month Number of planes that took of in a given month Greatest number of planes that landed in a single day within the month Smallest number of planes that landed in a single day within the month The program collects the landing and takeoff information for each of the 12 months from the user. Data is stored in an array of these structures. The program displays the following information. Total number of landings per year Total number of takeoffs per year Average number of landings per month Average number of takeoffs per year 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

Explanation / Answer

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);
}