1. A LinkNode structure or class which will have two attributes - • a data attribute, and • a pointer attribute to the next node. • The data attribute of the LinkNode should be a reference/pointer of the Currency class of Lab 2. • Do not make it an inner class or member structure to the SinglyLinkedList class of #2 below. 2. A SinglyLinked List class which will be composed of three attributes - • a count attribute, • a LinkNode pointer/reference attribute named as and pointing to the start of the list and • a LinkNode pointer/reference attribute named as and pointing to the end of the list. • Since this is a class, make sure all these attributes are private. 3. The class and attribute names for the node and linked list are the words in bold in #1 and #2. 4. For the Linked List, implement the following linked-list behaviors as explained in class - • getters/setters/constructors/destructors, as needed, for the attributes of the class. • createList method in addition to the constructor - this is optional for overloading purposes. • destroyList method in place of or in addition to the destructor - this is optional for overloading purposes, • addCurrency method which takes a Currency object and a node index value as parameters to add the Currency to the list at that index. • removeCurrency method which takes a Currency object as parameter and removes that Currency object from the list and may return a copy of the Currency. • removeCurrency overload method which takes a node index as parameter and removes the Currency object at that index and may return a copy of the Currency. • findCurrency method which takes a Currency object as parameter and returns the node index at which the Currency is found in the list. • getCurrency method which takes an index values as a parameter and returns the Currency object. • printList method which returns a string of all the Currency objects in the list in the order of index, tab spaced. isListEmpty method which returns if a list is empty or not. • countCurrency method which returns a count of Currency nodes in the list. • Any other methods you think would be useful in your program. 5. A Stack class derived from the SinglyLinkedList but with no additional attributes and the usual stack methods - • constructor and createStack (optional) methods, • push which takes a Currency object as parameter and adds it to the top of the stack. • pop which takes no parameter and removes and returns the Currency object from the top of the stack. • peek which takes no parameter and returns a copy of the Currency object at the top of the stack. • printStack method which returns a string signifying the contents of the stack from the top to bottom, tab spaced. • destructor and/or destroyStack (optional) methods. • Ensure that the Stack objects do not allow Linked List functions to be used on them. 6. A Queue class derived from the SinglyLinkedList but with no additional attributes and the usual queue methods - constructor and createQueue (optional) methods, • enqueue which takes a Currency object as parameter and adds it to the end of the queue. 0 • dequeue which takes no parameter and removes and returns the Currency object from the front of the queue. • peekFront which takes no parameter and returns a copy of the Currency object at the front of the queue. • peekRear which takes no parameter and returns a copy of the Currency object at the end of the queue. • printQueue method which returns a string signifying the contents of the queue from front to end, tab spaced. • destructor and/or destroyQueue (optional) methods. • Ensure that the Queue objects do not allow Linked List functions to be used on them. 7. Ensure that all your classes are mimimal and cohesive with adequate walls around them. Make sure to reuse and not duplicate any code. ITI ADT
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
pretty please. Dont show me the same answer form other questions. I have been asking many questions and still doesn't have answer for this.This is the currency class from lab 2 that mention in the instructions
class Currency {
protected:
int whole;
int fraction;
virtual std::string get_name() = 0;
public:
Currency() {
whole = 0;
fraction = 0;
}
Currency(double value) {
if (value < 0)
throw "Invalid value";
whole = int(value);
fraction = std::round(100 * (value - whole));
}
Currency(const Currency& curr) {
whole = curr.whole;
fraction = curr.fraction;
}
int get_whole() { return whole; }
int get_fraction() { return fraction; }
void set_whole(int w) {
if (w >= 0)
whole = w;
}
void set_fraction(int f) {
if (f >= 0 && f < 100)
fraction = f;
}
void add(const Currency* curr) {
whole += curr->whole;
fraction += curr->fraction;
if (fraction > 100) {
whole++;
fraction %= 100;
}
}
void subtract(const Currency* curr) {
if (!isGreater(*curr))
throw "Invalid Subtraction";
whole -= curr->whole;
if (fraction < curr->fraction) {
fraction = fraction + 100 - curr->fraction;
whole--;
}
else {
fraction -= curr->fraction;
}
}
bool isEqual(const Currency& curr) {
return curr.whole == whole && curr.fraction == fraction;
}
bool isGreater(const Currency& curr) {
if (whole < curr.whole)
return false;
if (whole == curr.whole && fraction < curr.fraction)
return false;
return true;
}
void print() {
std::cout << whole << "." << fraction << " " << get_name() << std::endl;
}
};
Trending now
This is a popular solution!
Step by step
Solved in 7 steps