In lectures we have discussed the use of templates to provide the compiler with blueprints for
functions and classes. These are used by the compiler to produce code that implements functions and/or classes that are suitable for the type(s) to which you apply them in your program code.
Your task in this Assignment is to modify your Assignment 1 code in the following ways:
Replace the Node and Linkedlist classes by class templates. Therefore, when an
instance of Node is created, the syntax will be Node<EToll>. That allows for a more
generic code, eliminating the need for typedef.
Use an LStack class template as a wrapper class around LinkedList. LStack will use a
LinkedList instance as a member variable. When instances of EToll are added to
LStack, they will be stored in the member LinkedList using methods from
LinkedList. Note that the implementation of LStack must comply with the public
interface and logic of stacks (elements are added and removed from the top of the stack, and
internal nodes are not visible). Moreover, removing instances of EToll from the stack, and
printing it can only use methods from LStack (i.e. push(i), pop(), peek(),
isEmpty()). That is, if you want to remove an item from the stack, you can’t simply call
the method remove from LinkedList, as it would violate the logic of stacks. This
constraint will help students understand the dynamics of stacks, and the fact that only
the top (first) element is visible at any time.
For SENG1120 students who want to be challenged more, there is an extra requirement, worth
a bonus 2.0 marks:
Create a class TollStack that extends LStack via inheritance. TollStack will declare
and implement all the methods that are specific to the toll application, leaving all the native
functionality of a generic stack in LStack.
The only methods allowed in the LStack class are the ones that would not change if the data
type changed (push(i), pop(), peek(), isEmpty(), +=). All other methods that
require a specific implementation for the EToll application (remove(), count(),
totalIncome(), <<, -=) should be declared and implemented in the TollStack class.
EasyDue™ 支持PayPal, AliPay, WechatPay, Taobao等各种付款方式!
E-mail: email@example.com 微信:easydue