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

Solution

#include <stdio.h>


struct airportTraffic //structure
{
   int planesLanded;
   int planesDeparted;
   int greatestPlanes;
   int leastPlanes;

};
int main()
{
   struct airportTraffic months[12]; //array of structures
   int i,totalLanded,totalDeparted,greatest,least,monthg,monthl;
   totalLanded = totalDeparted =0;
   greatest = 0;
   least = 99999;
   for(i=0;i<12;i++)
   {
       printf(\"\ Enter total number of planes landed in month %d:\",i+1);
       scanf(\"%d\",&months[i].planesLanded);
       printf(\"\ Enter total number of planes departed in month %d:\",i+1);
       scanf(\"%d\",&months[i].planesDeparted);
       printf(\"\ Enter greatest number of planes landed in a given day in month %d:\",i+1);
       scanf(\"%d\",&months[i].greatestPlanes);
       printf(\"\ Enter least number of planes landed in a given day in month %d:\",i+1);
       scanf(\"%d\",&months[i].leastPlanes);
      
   }
  
   for(i=0;i<12;i++)
   {
       totalLanded = totalLanded + months[i].planesLanded;
       totalDeparted = totalDeparted + months[i].planesDeparted;
  
   }
   printf(\"\ The total number of planes landed in a year : %d\",totalLanded);
   printf(\"\ The total number of planes departed in a year : %d\",totalDeparted);
   printf(\"\ The average number of planes landed in a month : %d\",totalLanded/12);
   printf(\"\ The average number of planes departed in a month : %d\",totalDeparted/12);
     
   for(i=0;i<12;i++)
   {
      if(greatest < months[i].greatestPlanes) //find greatest planes landed among all months
      {
      greatest = months[i].greatestPlanes;
      monthg = i+1;
      }
      if(least > months[i].leastPlanes) //find lest planes lnded among ll months
      {
      least = months[i].leastPlanes;
      monthl = i+1;
      }
   }
   printf(\"\ The greatest number of planes landed is %d in any one day in month %d \",greatest,monthg);
   printf(\"\ The least number of planes departed is %d in any day in month %d \",least,monthl);
     
     
   return 0;
}

output

 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