Having Trouble with Container Class

This is a discussion on Having Trouble with Container Class within the C++ Programming forums, part of the General Programming Boards category; I have an assignment to make a gradebook. We've done the assignment a few times prior, using different methods; once ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Location
    Roanoke, Texas, United States
    Posts
    5

    Having Trouble with Container Class

    I have an assignment to make a gradebook. We've done the assignment a few times prior, using different methods; once in C with just arrays, once in C with structs, and now we are to do it in C++.

    I've written a class for the student, one for the course, and one for the enrollment. We are supposed to use container classes (which the professor once also referred to as a collection class, if that helps). The way I understand it is that they work kind of like an array of objects.

    Below you will find my class for a student, and my horrid attempt at a container class. I feel like we haven't covered this in the actual class I'm taking, so it's hard to wrap my head around it. I've tried quite a few things so far.

    I would appreciate any help to get me on the right track. All the websites I've went to seem to be doing something totally different, or doing something that doesn't seem applicable.

    Code:
    class student
    {
        public:
        long int studentID;
        int courseCounter;
        string firstName;
        string lastName;
    
    
        student();
        void addFirst(string);
        void addLast(string);
    
    
    };
    Code:
    class students
    {
        student studentsCOL[100];
    
    
        students();
        void addStudent(string, string, long int, int);
    
    
    };

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,778
    We are supposed to use container classes
    You're probably want to use something like std::vector instead of an array. Here is a link you may want to invistigate.


    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Location
    Roanoke, Texas, United States
    Posts
    5
    Quote Originally Posted by jimblumberg View Post
    You're probably want to use something like std::vector instead of an array. Here is a link you may want to invistigate.


    Jim
    From what I can see, this is used for dynamic allocation. For this assignment, we have a hardcoded limit (although the next assignment will have us modify this to add dynamic allocation). Would this be the best approach for it, given that we have a hardcoded limit?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,778
    Well standard array is a fixed size and also part of the container classes. But since you state the instructor told you to use a container I would suggest either std::array or std::vector. But since I don't know your actual assignement maybe you should be talking to your instructor to get clairification.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Packet Container Class
    By ChaoticXSinZ in forum C++ Programming
    Replies: 2
    Last Post: 11-01-2010, 12:07 AM
  2. Base container class question
    By Raigne in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2008, 03:56 PM
  3. help with STL container remove_if on a class
    By Syneris in forum C++ Programming
    Replies: 19
    Last Post: 01-31-2006, 12:56 AM
  4. Container/class question
    By 7smurfs in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2005, 01:15 PM
  5. map container class
    By StinkyRyan in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2004, 11:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21