Homework # 2 (Due Date: Friday November 8, 2013)

Submit your homework via E-learning

Select your 3 code files (main.cpp, List.cpp, and List.h) and compress them into a file named StudentID_LastName_Section#.zip
Note: use Winrar to compress your files.

List Class
Write your own code to implement a List class. A list is a linear collection of finite elements. It's represented using an array of elements and a variable that holds count of how many elements are in the list.

		#ifndef LIST_H
		#define LIST_H

		const int size = 10;

		class List
			// functions prototypes

			int count;
			int elements[size];

  1. [1 point]
    List (); // default constructor

    Constructor initializes count to 0.

    Remember that constructors are automatically called when new objects are created. So, when creating a new List object (e.g. List MyList), MyList is initially empty.
  2. [1 point]
    bool IsEmpty () const;

    IsEmpty returns true if list is empty i.e. count == 0, otherwise it returns false.
  3. [1 point]
    bool IsFull () const;

    IsFull returns true if list is full (no more elements can be inserted into the list) i.e. count == size, otherwise it returns false.
  4. [1 point]
    int GetCount () const;

    Returns how many elements are already inserted into the list.
  5. [1 point]
    void Insert (int value);

    If list if full, this operation can not be proceeded, otherwise

    Inserts a new value at the end of the list (variable count used as index that indicates the end of the list), and increases count by 1.
  6. [1 point]
    void InsertAtPosition (int value, int pos);

    If list if full, this operation can not be proceeded, otherwise

    If pos < 0 or pos > count, this operation can not be proceeded, otherwise

    Moves elements at positions (pos, pos + 1, ..., count) one position forward, then inserts value at position pos and increases count by 1.
  7. [1 point]
    void Print () const;

    Prints all elements that are in the list
  8. [3 points]
    In main.cpp, create a List object and test all the functionalities if List class.