Thread: Need Help Finishing a Program Using Array of Structures

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    3

    Need Help Finishing a Program Using Array of Structures

    I am needing to finish this program that has an array of twelve structures to hold the travel information for the whole year. I need to prompt the user to enter data for each month. Once all the data is entered, I need to calculate and output the monthly number of landing planes, the average number of departing plans, the total of landing and departing planes for the year, and the greatest and least number of planes landed on any one day (and which month it occurred in).

    I need help finishing the program to type in the missing code that I need to make it work. Any help will be greatly appreciated!


    Code:
    #include <iostream>
    
    
    using namespace std;
    
    
    struct MthlyInfo {
        int totNumLand;
        int totNumDep;
        int greNumLand;
        int leaNumLand;
    };
    
    
    MthlyInfo yearinfo[12];
    
    
    int main()
    {
        int mthlyPlnLand;
        int mthlyPlnDep;
        int grtNumPlnLand;
        int lowNumPlnLand;
    
    
        for (index = 0; index < yearinfo[index]; index++) {
            cout << "How many planes have landed this month? " << endl;
            cin >> yearinfo[index].mthlyPlnLand;
    
    
            cout << "How many planes have departed this month? " << endl;
            cin >> mthlyPlnDep[index].mthlyPlnDept;
        }
    
    
        cout << "The greatest number of plans that landed in a given day  that month are: "
    
    
    
    
    
    
        return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,243
    Personally, I think your preoccupation with trying to abbreviate the names is unhealthy. Yes, it is good to choose concise names, and we do use abbreviations, but unusual abbreviations tend to make it harder to read and possibly harder to type (although autocomplete can help... but then it can help with slightly longer but non-abbreviated names too). So, I would suggest:
    Code:
    struct MonthlyInfo {
        int numLand;
        int numDepart;
        int maxNumLand;
        int minNumLand;
    };
    You should declare yearinfo as a variable local to the main function, and then get rid of those four local variables in main that aren't useful as the information you want would already be stored in yearinfo.

    Quote Originally Posted by radskater
    the greatest and least number of planes landed on any one day (and which month it occurred in)
    It seems to me that you don't have enough information for this: you're collecting data on a monthly basis, so you cannot know how many planes landed of any given day. You can only compute say, the mean number of planes that landed per day on any given month, but that isn't going to give you "the greatest and least number", unless you're trying to find out which month had the greatest number of planes land per day on average, and which month had the least number of planes land per day on average, in which case you don't need these as member variables of the struct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Personally, I think your preoccupation with trying to abbreviate the names is unhealthy. Yes, it is good to choose concise names, and we do use abbreviations, but unusual abbreviations tend to make it harder to read and possibly harder to type (although autocomplete can help... but then it can help with slightly longer but non-abbreviated names too). So, I would suggest:
    Code:
    struct MonthlyInfo {
        int numLand;
        int numDepart;
        int maxNumLand;
        int minNumLand;
    };
    You should declare yearinfo as a variable local to the main function, and then get rid of those four local variables in main that aren't useful as the information you want would already be stored in yearinfo.


    It seems to me that you don't have enough information for this: you're collecting data on a monthly basis, so you cannot know how many planes landed of any given day. You can only compute say, the mean number of planes that landed per day on any given month, but that isn't going to give you "the greatest and least number", unless you're trying to find out which month had the greatest number of planes land per day on average, and which month had the least number of planes land per day on average, in which case you don't need these as member variables of the struct.
    Thank you @laserlight !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finishing Off My Program
    By Steveqb14 in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2014, 10:10 AM
  2. C Program, Need help with finishing touches.
    By bgarner151 in forum C Programming
    Replies: 5
    Last Post: 12-10-2012, 06:30 PM
  3. help finishing this program
    By j.ward91 in forum C Programming
    Replies: 16
    Last Post: 04-26-2012, 10:44 AM
  4. Finishing up Mastermind game program
    By Charak in forum C Programming
    Replies: 5
    Last Post: 02-17-2011, 02:49 AM
  5. finishing up the sorting program
    By jk in forum C Programming
    Replies: 2
    Last Post: 03-19-2002, 07:43 PM

Tags for this Thread