Open main menu

CDOT Wiki β

Changes

Project A3 20141 - OOP344

396 bytes removed, 10:22, 3 April 2014
m
no edit summary
{{OOP344 Index Extended | 20141}}
 
= Introduction =
In this assignment, you will construct an integer linked list, adapt it into a templated linked list, then create a '''bonus''' object editor.
== Testing ==
Use the testing package linked [https://scs.senecac.on.ca/~hasan.kamal-al-deen/public_resources/oop344/a3test_mar262014a3test_apr032014.zip here(Updated March 26 April 3 2014)] to test your assignment. Please read the notes/comments in a3test.cpp.
== Expectations ==
Build the classes IntList and IntListNode. Place the headers in intlist.h and the implementation in intlist.cpp. These classes form an integer linked list.
=== Class: IntListNode, Files: [intlist.h, intlist.cpp], TestNumber: 0 ===
Integer linked list node. Node is considered last in the list if its next pointer is NULL. Note the public and protected sections below. You may need to make IntList a friend of this class.
; next: Next getter. Const function. Does not accept parameters. Returns pointer to the next node.
=== Class: IntList, Files [intlist.h, intlist.cpp], TestNumber: 0 ===
Integer linked list. Uses IntListNode as a node class.
==== Public Functions ====
; Constructor: Does not accept parameters. Initializes list to safe empty state.
 
; size: Size getter. Const function. Does not receive parameters. Should return number of nodes in list.
; head: Head getter. Const function. Returns pointer to head node in list.
; clear: Removes all nodes in the list. Has no effect if the list is empty. Does not accept parameters. Does not return anything.
; Destructor: Should ensure that all memory allocated by the list has been deallocated. You are encouraged to use the functions available to you.
; Constructor: Does not accept parameters. Initializes list to safe empty state.
; Standard Assignment Operator: Clears this list of all nodes. Then, refills list with the same number of nodes as in the source list. Value of each new node should equal the value of corresponding node in source list. Should not alter object in the case of self-assignment. Should return a reference to the current object.
; Copy Constructor: Initializes object to safe state then copies source list into current list. Similar to assignment operator.
These two classes are almost identical to IntListNode and IntList, except that they are templated.
In the specs below, note the sections that are marked '''<big><u><i>Important'''</i></u></big>. Those sections will have more than just a template parameter change from the int version of the list.
=== Class: ListNode<T>, Files: [list.h], TestNumber: 1 ===
Templated ListNode class. Similar to IntListNode but templated to hold any type.
; Constructor: Accepts two arguments.
;:* '''<big><u><i>Important'''. Const </i></u></big> const T reference to initialize node's value. Defaults to a default constructed T.;:* Pointer to next node in the list. Defaults to NULL.
; Copy Constructor: Initializes internal value as a copy of the source's internal value. Sets this object's next pointer to NULL.
; Standard Assignment Operator: Assigns source's internal value to the current object's internal value. Sets this object's next pointer to NULL. Does not alter the object in the case of self-assignment. Returns a reference to the current object.
; val: Val getter. Const function. Does not accept parameters. Returns internal value.
; val: Val setter. '''<big><u><i>Important'''. Receives </i></u></big> receives a const T reference. Sets internal value to received reference. Does not return anything.
; next: Next getter. Const function. Does not accept parameters. Returns pointer to next node.
=== Class: List<T>, Files [list.h], TestNumber: 1 ===A templated linked list class. Similar to IntList. Similarly to IntList, because it needs to be able to set the next pointer on Uses ListNode<T> objects, this class '''may''' need to be as a friend of the ListNode<T> node class (this depends on how you implement these classes).
The exact specs follow:==== Recommended Members ====* Pointer to head node in list* Current size (number of nodes) of list
==== Internal Variables Public Functions ====; ListNode<T>* _headConstructor: The head of the listDoes not accept parameters. Should be NULL when the Initializes list is to safe empty.; int _size: The number of elements currently in the liststate.
==== Public Functions ====; List()size: Default constructorSize getter. Const function. Does not receive parameters. Should set size to 0 and head to NULLreturn number of nodes in list.; List(const List<T>& src)head: Copy constructorHead getter. Should copy the Const function. Returns pointer to head node in list of nodes managed by '''src'''. This means that an entirely  ; push: Adds a new list of nodes must be created, one node for each node managed by to the '''src''', and end of the value held by each of those nodes must list'''equal. I'll say that again, '' the value held by the corresponding node managed by '''srcEND OF THE LIST'''. When this constructor is finished, the size of the current list should be the same as the size of src.<brbig><u><i>Important</i><br/u>'''TIP:''' After initializing the current object to a '''safe and empty state''', don't forget that you may call '''any member function''' that the current list has!; List<T/big>& operator=(receives a const List<T>& src): Assignment operatorreference. Should behave similarly The new node's value should be set to the copy constructorreceived reference. '''ADDITIONALLY; pop:Destroys the ''' Should do last node in the list'''NOTHING. I'll say that again, '' in the case of 'LAST NODE IN THE LIST''self-assignment''' (ie List<int> x. Does not receive any arguments. Does not return anything.; x = x;)clear: Removes all nodes in the list. If taking action, should clear Has no effect if the list of is empty. Does not accept parameters. Does not return anything. ; Destructor: Should ensure that all nodes before creating new ones ('''make sure that you do NOT leak memory!''')allocated by the list has been deallocated. Should return a reference You are encouraged to use the current objectfunctions available to you.
; int size() constStandard Assignment Operator: Size getterClears this list of all nodes. Returns Then, refills list with the current value same number of nodes as in the size member.; ListNode<T>* head() const: Head gettersource list. Returns the current value Value of the head pointer.; void push(const T& v): Adds a each new node to should equal the '''end value of the list''' holding the value v. Should increment size.; void pop(): Destroys the last corresponding node in the source list. Should do '''NOTHING''' if not alter object in the list is currently emptycase of self-assignment. Should decrement size if a node was destroyed. '''NOTE:''' If return a node was destroyed, make sure that '''ANY POINTERS POINTING TO IT''', that your code has access reference to, are set to NULLthe current object.; void clear()Copy Constructor: Destroys all nodes in the Initializes object to safe state then copies source list. Has no effect if the into current list is currently empty. When this function is finished, head should point Similar to NULL and size should be 0assignment operator.
== Submission ==
Please only submit '''ONCE YOUR CODE SUCCESSFULLY PASSES ALL TESTS!''' This includes the '''COMMON SENSE TEST''' which is the test that you perform '''yourself''' on your own code to ensure that it matches with what is required '''in the spec'''.  ; Section A, C: Please submit via blackboard.; Section B: Please see your instructor's specific instructions on how to submit.