Project 9b Write a program that uses a structure to store the following informat
ID: 3770709 • Letter: P
Question
Project 9b
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 planes, 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).
(30 PTS)
Solution to this please(: I'm in comp science 1 so i imagine the code shouldnt be very dfficult
Thanks!
Explanation / Answer
Program:
#include <iostream>
using namespace std;
//Structure to store plane landing details
struct airport
{
int planes_landed,palnes_departed,greatest_planes,least_planes;
};
int main() {
//An array of strutures airport of length 12
airport statistics[12];
//variables
int total_landings=0,total_departures=0,greatest=-1,least;
int max_month,min_month;
double average_landed,average_departed;
//Loop to accept details of landings in each month
for(int i=0;i<12;i++)
{
cout<<"Enter the details of month :"<<(i+1)<<endl;
cout<<"Total landing in the month : "<<endl;
cin>>statistics[i].planes_landed;
cout<<"Total departures in the month: "<<endl;
cin>>statistics[i].palnes_departed;
cout<<"Greatest number of planes that landed : "<<endl;
cin>>statistics[i].greatest_planes;
cout<<"Least number of planes that landed : "<<endl;
cin>>statistics[i].least_planes;
}
//Initiliaze least value to first value of least_planes in the array.
least=statistics[0].least_planes;
for(int i=0;i<12;i++)
{
total_landings=total_landings+statistics[i].planes_landed;
total_departures=total_departures+statistics[i].palnes_departed;
//find maximum landings
if(greatest<statistics[i].greatest_planes)
{
greatest=statistics[i].greatest_planes;
//Store month number in max_month
max_month=i;
}
//find minimum landings
if(least>statistics[i].least_planes)
{
least=statistics[i].least_planes;
//Store month number in min_month
min_month=i;
}
}
//Divide with 12.0 to get average values in double
average_landed=total_landings/12.0;
average_departed=total_departures/12.0;
//Output the results
cout<<"Total planes landed in the year : "<<total_landings<<endl;
cout<<"Total planes departed in the year : "<<total_departures<<endl;
cout<<"Average montly landing"<<average_landed<<endl;
cout<<"Average montly departed"<<average_departed<<endl;
cout<<"greatest of planes that landed on any one day "<<greatest<<" occured in "<<(max_month+1)<<" month"<<endl;
cout<<"least of planes that landed on any one day "<<least<<" occured in "<<(min_month+1)<<" month"<<endl;;
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.