Changes

Jump to: navigation, search

Project A3 20141 - OOP344

5,637 bytes removed, 10:22, 3 April 2014
m
no edit summary
{{OOP344 Index Extended | 20141}}
 
= Introduction =
Our third In this assignment , you will have you construct an integer holding linked list, adapt it into a templated linked list, then create an a '''bonus''' object editor utilizing the list. You will use  == Testing ==Use the testing package linked [httphttps://replacescs.senecac.on.ca/~hasan.kamal-al-deen/public_resources/oop344/a3test_apr032014.me zip here(Updated April 3 2014)] to test your assignment. The linked lists have automated tests; Please read the rest of the assignment has some automated tests and some visual testsnotes/comments in a3test.cpp. Please note the filename and test number conveniently  == Expectations ==Test numbers are provided in at the section headers for end of each required class/functionspec heading, as are file names.
; SANITY NOTE: You will be writing a number of classes and functions. [[Sanity_20141_-_OOP344 | Please remember to '''sanitize''' your code as you go along.; What is code sanity?: The idea behind code sanity is to keep the code clean and the logic strong '''at all times'''. This has 2 main advantages.# If your code is logically correct '''at all times''' then you can be sure that if there is a problem, it has been caused by the latest set of alterations.# It makes debugging '''much much easier''' both for yourself and for '''anyone helping you'''; So how do I keep my code sane?: By following these simple steps:# Keep the code nicely '''formatted''' at '''all times'''. This makes it easy to see the logical structure of your program at a glance and to follow the logic of it. Experienced programmers do '''NOT''' look for lines of code, they look for '''blocks''' denoted by '''indents'''. Train yourself to do the same.<br/>'''NOTE:''' If you are using an editor or environment that makes read this hard for you, '''start by getting a better environment!'''<br/>Windows and visual studio are an excellent combination and provided for free by Seneca. On Linux, your options are netbeans and sublime. The debugging experience is simpler on Windows for our assignments however.<br/>Also note, on visual studio, you can have the editor '''automatically''' format your code nicely by pressing the following combinations in sequence:<br/>'''CTRL-K, CTRL-D'''# Do not begin writing the next feature before the '''last feature''' is working! This is of '''paramount importance'''! By ensuring that your code is working ('''use the tests, specs, and your common sense!'''), you can save versions of your assignment at specific points in time and '''know''' that if a problem arises, '''it must be caused by your latest set of changes!'''# Use a '''consistent''' naming convention for all member variables and '''another''' convention for local variables.<br/>This makes it easy for you and for '''anyone helping you''' to tell at a glance (ie '''WITHOUT''' looking at your header) which variables are local, member, etc...<br/>Too often I see conventions either not used, not used consistently, or '''mixed'''. Of the three cases, '''the third is the worst'''.<br/>Aim to '''ALWAYS''' use consistent naming conventions, whatever they may beSANITY]].<br/>An easy set of conventions is as follows:#; Private/Protected Member Variable/Function: _underscoreCamelCase#; Public Member Variable/Function: regularCamelCase#; Local Variable/Function Parameter/Global Function: regularCamelCase#; Public #Define (ie should be used by external code): SCREAMING_CAPS#; Private #Define (ie should only be internally used): _UNDERSCORE_SCREAMING_CAPS
When you are finished the assignment, you will have created the following files:
* intlist.cpp
* list.h
 
* Will update with part 3 soon.
== Part 1: Integer Linked List ==
For this part, you will build Build the classes '''IntList''' and '''IntListNode''' . Place the headers in the files '''intlist.h''' and '''the implementation in intlist.cpp'''. These two classes compose a basic implementation of form an integer linked list. Please see the following sections on the exact specifications of these classes.
=== Class: IntListNode, Files: [intlist.h, intlist.cpp], TestNumber: 0 ===An IntListNode is an integer Integer linked list node, as such it holds an integer value and a pointer to an IntListNode that . Node is the next node considered last in the list. If the if its next link pointer is NULL then the current node is considered the '''last node in the list'''.<br/>Note that the next property of this class has a public getter and a protected setter; this is intentional as client code should not mess with the '''structure''' of our linked listsections below.<br/>While this class is only used by You may need to make IntList, it is expected to have a set friend of its own functionalitythis class.
It is expected that ==== Recommended Members ====* An integer member to hold the node'''class declaration''' for this class lie in '''intlists value.h''' and * A pointer to the definition code lie next node in '''intlist.cpp'''the list.
In most implementations, you will need ==== Public Functions ====; Constructor: Accepts two arguments::* Integer to make the class '''IntList''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 friend copy of this class to access the protected 'source's internal value. Sets this object's next setterpointer 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.
The exact specs follow; val:Val getter. Const function. Does not accept parameters. Returns internal value.; val: Val setter. Receives an int. Sets internal value to received int. Does not return anything.
==== Internal Variables ====Please note that ; next: Next getter. Const function. Does not accept parameters. Returns pointer to the names provided in all '''Internal Variables''' sections are suggested but '''not mandatory'''next node.
; int _val=== Class: Held integer valueIntList, Files [intlist.h, intlist.cpp], Test Number: 0 ===; Integer linked list. Uses IntListNode* _next: Pointer to the next as a node in the listclass.
==== Protected Functions Recommended Members ====; void next* Pointer to head node in list* Current size (IntListNode*number of nodes): Next setter. Sets the internally held next pointer to the incoming pointer.of list
==== Public Functions ====
; IntListNode(int v = int(), IntListNode* n = NULL)Constructor: Constructor. Note the default valuesDoes not accept parameters. Initializes the internally held value to v and the next pointer to n.; IntListNode(const IntListNode& src): Copy constructor. Should initialize the internally held value to src's internally held value. Should initialize '''next''' to '''NULL'''.; IntListNode& operator=(const IntListNode& src): Assignment operator. Should set the internally held value to src's internally held value. Should set '''next''' to '''NULL'''. Should do '''NOTHING''' in the case of '''self-assignment''' (ie IntListNode x; x = x;). Returns a reference list to the current object.; ~IntListNode(): Destructor. As this node does not allocate any memory, this function can remain safe emptystate.
; int val() constsize: Val Size getter. Returns the value internally heldConst function. Does not receive parameters. Should return number of nodes in list.; void val(int)head: Val setterHead getter. Sets the internally held value Const function. Returns pointer to the incoming valuehead node in list.
; IntListNode* next() constpush: Next getterAdds a new node to the '''end of the list'''. I'll say that again, '''END OF THE LIST'''. Receives an int parameter. The new node's value should be set to the received int.; pop: Destroys the '''last node in the list'''. Returns 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 internally held next pointerlist. Has no effect if the list is empty. Does not accept parameters. Does not return anything.
=== Class; Destructor: IntList, Files [intlist.h, intlist.cpp], Test: 0 ===An IntList is Should ensure that all memory allocated by the actual integer linked list class. It manages a sequence of IntListNodehas been deallocated. Because it needs You are encouraged to be able to set use the next pointer on IntListNode objects, this class '''may''' need functions available to be a friend of the IntListNode class (this depends on how you implement these classes).
The exact specs follow; 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 == Internal Variables ====; IntListNode* _head: The head of the list. Should be NULL when the list is empty.; int _size'''NOTE: The number of elements currently in the list''' Finish part 1 before working on this part.
==== Public Functions ====; IntList(): Default constructor. Should set size to 0 and head to NULL.; IntList(const IntList& src): Copy constructor. Should copy Build the templated linked list of nodes managed by '''src'''. This means that an entirely new list of nodes must be created, one node for each node managed by '''src''', class ListNode<T> and 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 templated linked list should be the same as the size of src.<br/>class List<br/T>'''TIP:''' After initializing the current object to a '''safe and empty state''', don't forget that you can call '''any member function''' that the current list has!; IntList& operator=(const IntList& src): Assignment operator. Should behave similarly to the copy constructor. '''ADDITIONALLY:''' Should do '''NOTHING''' in the case of '''self-assignment''' (ie IntList x; x = x;). If taking action, should clear the file list of all nodes before creating new ones ('''make sure that you do NOT leak memory!'''). Should return a reference to the current objecth.
; int size() const: Size getter. Returns the current value of the size member.; These two classes are almost identical to IntListNode* head() const: Head getter. Returns the current value of the head pointer.; void push(int v): Adds a new node to the '''end of the list''' holding the value v. Should increment size.; void pop(): Destroys the last node in the list. Should do '''NOTHING''' if the list is currently empty. Should decrement size if a node was destroyed. '''NOTE:''' If a node was destroyed, make sure that '''ANY POINTERS POINTING TO IT'''and IntList, except that your code has access to, they are set to NULL.; void clear(): Destroys all nodes 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 0templated.
== Part 2: Templated Linked List =='''NOTE: Do NOT start working on this part before finishing part 1 and making sure In the specs below, note the sections that it passes all tests!'''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.
For this part, you will build the classes '''List=== Class: ListNode<T>''' and '''ListNode''' in the file ''', Files: [list.h'''. These two classes compose a templated linked list], Test Number: 1 ===Templated ListNode class. A lot of the code for these classes is '''very similar''' Similar to the code you already wrote for the IntListNode and IntList classes, except that the code is now but 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 requiredhold any type.
'''NOTE:''' The function signature syntax for ListNode::ListNode, ListNode::val setter, and List:prototyping a templated class is:push are different from their IntListNode and IntList counterparts! template <typename T> SomeClass;
=== Class: ListNode<T>, Files: [list.h], Test: 1 = Recommended Members ====Templated ListNode class* Template type member to hold the value. Similar * Pointer to IntListNode but templated to hold any typenext node in list.
It is expected that '''class declaration''' and '''definition''' lie in '''list.h'''==== Public Functions ====These functions are similar to their IntListNode counterparts.
In most implementations, you will need ; Constructor: Accepts two arguments.:* <big><u><i>Important</i></u></big> const T reference to make the class initialize node'''List<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 friend copy of this class to access the protected 'source's internal value. Sets this object's next setterpointer 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.
'''TIP; val:''' The syntax for prototyping a templated class isVal getter. Const function. Does not accept parameters. Returns internal value.; val: template Val setter. <big><u><i>Important</i></u><typename /big> receives a const T> SomeClass;reference. Sets internal value to received reference. Does not return anything.
The exact specs follow and assume that the template; next:Next getter. Const function. Does not accept parameters. Returns pointer to next node.
==== Internal Variables =Class: List<T>, Files [list.h], Test Number: 1 ===; T _val: Held valueA templated linked list class. Similar to IntList.; Uses ListNode<T>* _next: Pointer to the next as a node in the listclass.
==== Protected Functions Recommended Members ====; void next* Pointer to head node in list* Current size (ListNode<T>*number of nodes): Next setter. Sets the internally held next pointer to the incoming pointer.of list
==== Public Functions ====
; ListNode(const T& v = T(), ListNode<T>* n = NULL)Constructor: Constructor. Note the default valuesDoes not accept parameters. Initializes the internally held value to v and the next pointer to n.; ListNode(const ListNode<T>& src): Copy constructor. Should initialize the internally held value to src's internally held value. Should initialize '''next''' to '''NULL'''.; ListNode& operator=(const ListNode<T>& src): Assignment operator. Should set the internally held value to src's internally held value. Should set '''next''' to '''NULL'''. Should do '''NOTHING''' in the case of '''self-assignment''' (ie ListNode<T> x; x = x;). Returns a reference list to the current object.; ~ListNode(): Destructor. As this node does not allocate any memory, this function can remain safe emptystate.
; T val() constsize: Val Size getter. Returns the value internally heldConst function. Does not receive parameters. Should return number of nodes in list.; void val(const T&)head: Val setterHead getter. Sets the internally held value Const function. Returns pointer to the incoming valuehead node in list.
; ListNodepush: 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><T/big>* next() receives a constT reference. The new node's value should be set to the received reference.; pop: Next getterDestroys the '''last node in the list'''. Returns 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 internally held next pointerlist. Has no effect if the list is empty. Does not accept parameters. Does not return anything.
=== Class; Destructor: List<T>, File [Should ensure that all memory allocated by the listhas been deallocated.h], Test: 1 ===A templated linked list class. Similar You are encouraged to IntList. Similarly to IntList, because it needs to be able to set use the next pointer on ListNode<T> objects, this class '''may''' need functions available to be a friend of the ListNode<T> class (this depends on how you implement these classes).
The exact specs follow; 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.
==== Internal Variables ==Submission ==; ListNode<T>* _head: The head of the list. Should be NULL when the list is empty.; int _size: The number of elements currently in the list. ==== Public Functions ====; List(): Default constructor. Should set size to 0 and head to NULL.; List(const List<T>& src): Copy constructor. Should copy the list of nodes managed by Please only submit '''srcONCE YOUR CODE SUCCESSFULLY PASSES ALL TESTS!'''. This means that an entirely new list of nodes must be created, one node for each node managed by '''src''', and the value held by each of those nodes must '''equal''' the value held by includes the corresponding node managed by '''srcCOMMON SENSE TEST'''. When this constructor which 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 test that you may call perform '''any member functionyourself''' on your own code to ensure that the current list has!; List<T>& operator=(const List<T>& src): Assignment operator. Should behave similarly to the copy constructor. '''ADDITIONALLY:''' Should do '''NOTHING''' it matches with what is required 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 objectspec.
; int size() constSection A, C: Size getter. Returns the current value of the size memberPlease submit via blackboard.; ListNode<T>* head() constSection B: Head getter. Returns the current value of the head pointer.; void push(const T& v): Adds a new node to the '''end of the list''' holding the value v. Should increment size.; void pop(): Destroys the last node in the list. Should do '''NOTHING''' if the list is currently empty. Should decrement size if a node was destroyed. '''NOTE:''' If a node was destroyed, make sure that Please see your instructor'''ANY POINTERS POINTING TO IT''', that your code has access to, are set to NULL.; void clear(): Destroys all nodes in the list. Has no effect if the list is currently empty. When this function is finished, head should point s specific instructions on how to NULL and size should be 0submit.

Navigation menu