Homework 5 Csc309.
Due Monday May 1, 2006 by 11:59pm.
No required assignment this week, just extra credit.
The next required assignment will be given next week. It will follow from what I do the first half of next Tuesday's class.
Extra Credit
(4 percent) Graded out of 50 points.
To receive full credit you must demonstrate your methods. Work incrementally, that is after you write a method test it.
Add the following methods to IntList worked out in class.
- Make the copy constructor public and write the definition for it.
- Overload the assignment operator
IntList & operator= (const IntList & rhs);
Write a method that will add an integer to the front of the list NOT replace the front element. You will first have to
make sure there is enough room in the array, then shuffle everything down one slot. Don't forget about the size.
void push_front(int number);
Write a method that will return a reference to the last element in the list.
int & back();
Write a method that will return a reference to the first element in the list.
int & front();
Write a method that will insert an integer at a specified index. You cannot assume the index is valid. If the index is out of range print an error message and return. Again make sure there is enough room. Don't forget about the size.
void insert(int index, int number);
Write a method to delete the integer at a specified index. You cannot assume the index is in bounds. You cannot leave a hole, you have to shuffle the elements to the right
down a slot. Don't forget about the size.
void erase(int index);
Write a method to remove the last integer in the list.
void pop_back();
Write a method to remove the first integer in the list. You may want to use the erase method.
void pop_front();
Write a method that will swap two IntLists.
void swap(IntList & rhs);
Example
Let list1 and list2 be two IntList objects. After the call to swap
list1.swap(list2);
list1 will contain the elements that were in list2 and list2 will contain the elements that were in list1.
Upload to COL