Write a program that uses a structure to store the following

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 monthly 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 planes, the total number of landing and departures for the greatest and least number of planes that landed on any one day (and which month it occurred in).

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

 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
 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site