Open main menu

CDOT Wiki β

Changes

Project A3 20141 - OOP344

1,338 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.
* An integer member to hold the node's value.
* A pointer to the next node in the list.
 
==== Protected Functions ====
; next: Setter for this node's next member. Accepts a pointer to a node. Does not return anything.
==== Public Functions ====
:* Integer to initialize node's value. Defaults to a default constructed int.
:* Pointer to next node in 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.
; 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.
==== Recommended members Members ====
* Pointer to head node in list
* Current size (number of nodes) of list
==== 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.
== Part 2: Templated Linked List ==
'''NOTE: Do NOT start ''' Finish part 1 before working on this part before finishing part 1 . Build the templated linked list node class ListNode<T> and making sure that it passes all tests!'''the templated linked list class List<T> in the file list.h.
For this part, you will build the classes '''List<T>''' and '''ListNode''' in the file '''list.h'''. These two classes compose a templated linked list. A lot of the code for these classes is '''very similar''' are almost identical to the code you already wrote for the IntListNode and IntList classes, except that the code is now they are templated. Therefore, it is suggested that you '''copy''' the code that you wrote for those classes and '''paste''' it into the list.h file, updating the references to IntListNode and IntList and generally adjusting the code as required.
'''NOTE:''' The function signature for ListNode::ListNodeIn the specs below, ListNode::val setter, and List::push note the sections that are different marked <big><u><i>Important</i></u></big>. Those sections will have more than just a template parameter change from their IntListNode and IntList counterparts!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.
It The syntax for prototyping a templated class is expected that '''class declaration''' and '''definition''' lie in '''list.h'''.: template <typename T> SomeClass;
In most implementations, you will need ==== Recommended Members ====* Template type member to make hold the class '''List<T>''' a friend of this class value.* Pointer to access the protected '''next setter'''node in list.
'''TIP:''' The syntax for prototyping a templated class is:==== Public Functions ==== template <typename T> SomeClass;These functions are similar to their IntListNode counterparts.
The exact specs follow and assume that ; Constructor: Accepts two arguments.:* <big><u><i>Important</i></u></big> const T reference to initialize node's value. Defaults to a default constructed T.:* Pointer to next node in the templatelist. 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.
==== Internal Variables ====; T _valval: Held Val getter. Const function. Does not accept parameters. Returns internal value.; ListNodeval: Val setter. <big><u><i>Important</i></u></big> receives a const T>* _next: Pointer reference. Sets internal value to the next node in the listreceived reference. Does not return anything.
==== Protected Functions ====; void next(ListNode<T>*): Next settergetter. Sets the internally held next Const function. Does not accept parameters. Returns pointer to the incoming pointernext node.
==== Public Functions ====; ListNode(const T& v = T(), ListNodeClass: List<T>* n = NULL): Constructor, Files [list. Note the default values. Initializes the internally held value to v and the next pointer to n.; ListNode(const ListNode<T>& src)h], Test Number: Copy constructor. Should initialize the internally held value to src's internally held value. Should initialize '''next''' to '''NULL'''.1 ===; ListNode& operator=(const ListNode<T>& src): Assignment operator. Should set the internally held value to src's internally held valueA templated linked list class. Should set '''next''' Similar to '''NULL'''IntList. Should do '''NOTHING''' in the case of '''self-assignment''' (ie Uses ListNode<T> x; x = x;). Returns as a reference to the current object.; ~ListNode(): Destructor. As this node does not allocate any memory, this function can remain emptyclass.
; T val() const: Val getter. Returns the value internally held.==== Recommended Members ====* Pointer to head node in list; void val* Current size (const T&number of nodes): Val setter. Sets the internally held value to the incoming value.of list
==== Public Functions ====; ListNode<T>* next() constConstructor: Next getterDoes not accept parameters. Returns the internally held next pointerInitializes list to safe empty state.
=== Class; size: List<T>, Files [Size getter. Const function. Does not receive parameters. Should return number of nodes in list.h], Test; head: 1 ===A templated linked list classHead getter. Similar to IntListConst function. Similarly to IntList, because it needs to be able to set the next Returns pointer on ListNode<T> objects, this class '''may''' need to be a friend of the ListNode<T> class (this depends on how you implement these classes)head node in list.
; push: Adds a new node to the '''end of the list'''. I'll say that again, '''END OF THE LIST'''. <big><u><i>Important</i></u></big> receives a const T reference. The exact specs follownew node's value should be set to the received reference.; pop: Destroys the '''last node in the list'''. I'll say that again, '''LAST NODE IN THE LIST'''. Does not receive any arguments. Does not return anything.; clear:Removes all nodes in the list. Has no effect if the list is empty. Does not accept parameters. Does not return anything.
==== Internal Variables ====; ListNode<T>* _headDestructor: The head of the list. Should be NULL when ensure that all memory allocated by the list is emptyhas been deallocated.; int _size: The number of elements currently in You are encouraged to use the listfunctions available to you.
==== Public Functions ====; List()Standard Assignment Operator: Default constructor. Should set size to 0 and head to NULL.; List(const List<T>& src): Copy constructor. Should copy the Clears this list of all nodes managed by '''src'''. This means that an entirely new Then, refills list with the same number of nodes must be created, one node for as in the source list. Value of each new node managed by '''src''', and should equal the value held by each of those nodes must '''equal''' the value held by the corresponding node managed by '''src'''. When this constructor is finished, the size of the current list should be the same as the size of src.<br/><br/>'''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 in source list has!; List<T>& operator=(const List<T>& src): Assignment operator. Should behave similarly to the copy constructor. '''ADDITIONALLY:''' Should do '''NOTHING''' not alter object in the case of '''self-assignment''' (ie List<int> x; x = x;). If taking action, should clear the list of all nodes before creating new ones ('''make sure that you do NOT leak memory!'''). 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.
; int size() const: Size getter. Returns the current value of the size member.; ListNode<T>* head() const: Head getter. Returns the current value of the head pointer.== Submission ==; void push(const T& v): Adds a new node to the Please only submit '''end of the listONCE YOUR CODE SUCCESSFULLY PASSES ALL TESTS!''' holding This includes the value v. Should increment size.; void pop(): Destroys the last node in the list. Should do '''NOTHINGCOMMON SENSE TEST''' if which is the list is currently empty. Should decrement size if a node was destroyed. '''NOTE:''' If a node was destroyed, make sure test that you perform '''ANY POINTERS POINTING TO ITyourself''', that on your own code has access to, are set to NULL.; void clear(): Destroys all nodes ensure that it matches with what is required in the list. Has no effect if the list is currently empty. When this function is finished, head should point to NULL and size should be 0spec.
== Submission ==; Section A, C: 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'''via blackboard. ; Section B: Please see your instructor's specific instructions on how to submit.