please write code please than you so much and the followinf is the currency class of previous one.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
please write code please than you so much and the followinf is the currency class of previous one.
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;
    }

 

    /* This algorithm gets the whole part or fractional part of the currency
     Pre: whole, fraction - integer numbers
     Post:
     Return: whole or fraction
    */

 

    int get_whole() { return whole; }

 

    int get_fraction() { return fraction; }

 

    /* This algorithm adds an object to the same currency
       Pre: object (same currency)
       Post:
       Return:
     */

 

    void set_whole(int w) {
        if (w >= 0)
            whole = w;
    }

 

    void set_fraction(int f) {
        if (f >= 0 && f < 100)
            fraction = f;
    }

 

    /* This algorithm adds an object to the same currency

 

    Pre: object (same currency)
    Post:
    Return:

 

    */

 

    void add(const Currency* curr) {
        whole += curr->whole;
        fraction += curr->fraction;
        if (fraction > 100) {
            whole++;
            fraction %= 100;
        }
    }

 

 
    /* This algorithm subtracts an object to the same currency

 

    Pre: object (same currency)
    Post:
    Return:

 

    */



    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;
        }
    }

 

    /* This algorithm compares the an object of the same currency for equality or inequality

 

    Pre: object (same currency)
    Post:
    Return: whole/fraction

 

    */

 

    bool isEqual(const Currency& curr) {
        return curr.whole == whole && curr.fraction == fraction;
    }
   
    /* This algorithm compares the an object of the same currency to determine which is greater or smaller

 

    Pre: object (same currency)
    Post:
    Return: true/false

 

    */

 

    bool isGreater(const Currency& curr) {
        if (whole < curr.whole)
            return false;
        if (whole == curr.whole && fraction < curr.fraction)
            return false;
        return true;
    }
   
    /* This algorithm prints the name and value of the currency object

 

    Pre: value of whole, fraction, and the name
    Post: whole, fraction, get_name()
    Return:

 

    */

 

    void print() {
        std::cout << whole << "." << fraction << " " << get_name() << std::endl;
    }
};

 

class Krone : public Currency {
protected:

 

     /*
     This algorithm gets the name for the Currency.
     Pre: name - declared as string and initialized as �Krone�
     Post:
     Return: name
    */

 

    std::string name = "Krone";
    std::string get_name() {
        return name;
    }
public:
    Krone() : Currency() {  }
    Krone(double value) : Currency(value) { }
    Krone(Krone& curr) : Currency(curr) { }
};

 

class Soum : public Currency {
protected:

 

    /* This algorithm gets the name for the Currency.
       Pre: name - declared as string and initialized as �Soum�
       Post:
       Return: name
    */

 

    std::string name = "Soum";
    std::string get_name() {
        return name;
    }
public:
    Soum() : Currency() {  }
    Soum(double value) : Currency(value) { }
    Soum(Krone& curr) : Currency(curr) { }
};
1. A LinkNode structure or class which will have two attributes -
o a data attribute, and
o 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 -
o a count attribute,
o a LinkNode pointer/reference attribute named as and pointing to the start of the list and
o 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 -
o getters/setters/constructors/destructors, as needed, for the attributes of the class.
o createList method in addition to the constructor - this is optional for overloading purposes.
o destroyList method in place of or in addition to the destructor - this is optional for overloading purposes,
o addCurrency method which takes a Currency object and a node index value as parameters to add the Currency to the list at that index.
o 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.
o 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.
O find Currency method which takes a Currency object as parameter and returns the node index at which the Currency is found in the list.
o getCurrency method which takes an index values as a parameter and returns the Currency object.
o printList method which returns a string of all the Currency objects in the list in the order of index, tab spaced.
o isListEmpty method which returns if a list is empty or not.
o countCurrency method which returns a count of Currency nodes in the list.
o Any other methods you think would be useful in your program.
5. A Stack class derived from the SinglyLinked List but with no additional attributes and the usual stack methods -
o constructor and createStack (optional) methods,
o push which takes a Currency object as parameter and adds it to the top of the stack.
o pop which takes no parameter and removes and returns the Currency object from the top of the stack.
o peek which takes no parameter and returns a copy of the Currency object at the top of the stack.
o printStack method which returns a string signifying the contents of the stack from the top to bottom, tab spaced.
o 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 -
o constructor and createQueue (optional) methods,
o enqueue which takes a Currency object as parameter and adds it to the end of the queue.
o dequeue which takes no parameter and removes and returns the Currency object from the front of the queue.
o peekFront which takes no parameter and returns a copy of the Currency object at the front of the queue.
o peekRear which takes no parameter and returns a copy of the Currency object at the end of the queue.
o printQueue method which returns a string signifying the contents of the queue from front to end, tab spaced.
o 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.
Transcribed Image Text:1. A LinkNode structure or class which will have two attributes - o a data attribute, and o 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 - o a count attribute, o a LinkNode pointer/reference attribute named as and pointing to the start of the list and o 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 - o getters/setters/constructors/destructors, as needed, for the attributes of the class. o createList method in addition to the constructor - this is optional for overloading purposes. o destroyList method in place of or in addition to the destructor - this is optional for overloading purposes, o addCurrency method which takes a Currency object and a node index value as parameters to add the Currency to the list at that index. o 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. o 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. O find Currency method which takes a Currency object as parameter and returns the node index at which the Currency is found in the list. o getCurrency method which takes an index values as a parameter and returns the Currency object. o printList method which returns a string of all the Currency objects in the list in the order of index, tab spaced. o isListEmpty method which returns if a list is empty or not. o countCurrency method which returns a count of Currency nodes in the list. o Any other methods you think would be useful in your program. 5. A Stack class derived from the SinglyLinked List but with no additional attributes and the usual stack methods - o constructor and createStack (optional) methods, o push which takes a Currency object as parameter and adds it to the top of the stack. o pop which takes no parameter and removes and returns the Currency object from the top of the stack. o peek which takes no parameter and returns a copy of the Currency object at the top of the stack. o printStack method which returns a string signifying the contents of the stack from the top to bottom, tab spaced. o 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 - o constructor and createQueue (optional) methods, o enqueue which takes a Currency object as parameter and adds it to the end of the queue. o dequeue which takes no parameter and removes and returns the Currency object from the front of the queue. o peekFront which takes no parameter and returns a copy of the Currency object at the front of the queue. o peekRear which takes no parameter and returns a copy of the Currency object at the end of the queue. o printQueue method which returns a string signifying the contents of the queue from front to end, tab spaced. o 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.
8. Then write a main driver program that will demonstrate all the capabilities of your ADTs as follows -
o First, print a Welcome message for the demonstration of your ADTs - you can decide what the message says but it should include your full name(s).
. Second, create the following twenty (20) Krone objects in a Currency array to be used in the program.
1. Kr 57.12
2. Kr 23.44
3. Kr 87.43
4. Kr 68.99
5. Kr 111.22
6. Kr 44.55
7. Kr 77.77
8. Kr 18.36
9. Kr 543.21
10. Kr 20.21
11. Kr 345.67
12. Kr 36.18
13. Kr 48.48
14. Kr 101.00
15. Kr 11.00
16. Kr 21.00
17. Kr 51.00
18. Kr 1.00
19. Kr 251.00
20. Kr 151.00
o Then, create one each of SinglyLinked List, Stack and Queue objects.
• For the linked list, perform the following operations in order -
A. Add the first seven (7) objects from the array into the linked list in order such that they end up in the reverse order in the linked list, i.e. the
seventh element as first node and first element as seventh node. If it is easier, you are allowed to insert copies of the objects.
B. Search for Kr 87.43 followed by Kr 44.56 - print the results of each.
C. Remove the node containing Kr 111.22 followed by the node at index 2.
D. Print the contents of the list.
E. Then add the next four (4) objects (#9 thru 12) such that their index in the linked list is calculated as (index in array % 5).
F. Remove two (2) objects at indexes (countCurrency % 6) and (countCurrency / 7) in that order.
G. Print the contents of the list.
• For the stack, perform the following operations in order -
A. Push seven (7) objects starting from the array index 13 onwards to the stack.
B. Peek the top of the stack - print the result.
C. Perform three (3) pops in succession.
D. Print the contents of the stack.
E. Push five (5) more objects from the start of the objects array to the stack.
F. Pop twice in succession.
G. Print the contents of the stack.
• For the queue, perform the following operations in order -
A. Enqueue the seven (7) objects at odd indexes starting from index 5 in the array.
B. Peek the front and end of the queue - print the results.
C. Perform two (2) dequeues in succession.
D. Print the contents of the queue.
E. Enqueue five (5) more objects from the index 10 in the array.
F. Dequeue three times in succession.
G. Print the contents of the queue.
• End the program with a leaving message of your choice. Remember to clean up before the program ends.
• Restrict all your input/output to the main driver program only, except for the existing screen print inside the Currency print methods.
Transcribed Image Text:8. Then write a main driver program that will demonstrate all the capabilities of your ADTs as follows - o First, print a Welcome message for the demonstration of your ADTs - you can decide what the message says but it should include your full name(s). . Second, create the following twenty (20) Krone objects in a Currency array to be used in the program. 1. Kr 57.12 2. Kr 23.44 3. Kr 87.43 4. Kr 68.99 5. Kr 111.22 6. Kr 44.55 7. Kr 77.77 8. Kr 18.36 9. Kr 543.21 10. Kr 20.21 11. Kr 345.67 12. Kr 36.18 13. Kr 48.48 14. Kr 101.00 15. Kr 11.00 16. Kr 21.00 17. Kr 51.00 18. Kr 1.00 19. Kr 251.00 20. Kr 151.00 o Then, create one each of SinglyLinked List, Stack and Queue objects. • For the linked list, perform the following operations in order - A. Add the first seven (7) objects from the array into the linked list in order such that they end up in the reverse order in the linked list, i.e. the seventh element as first node and first element as seventh node. If it is easier, you are allowed to insert copies of the objects. B. Search for Kr 87.43 followed by Kr 44.56 - print the results of each. C. Remove the node containing Kr 111.22 followed by the node at index 2. D. Print the contents of the list. E. Then add the next four (4) objects (#9 thru 12) such that their index in the linked list is calculated as (index in array % 5). F. Remove two (2) objects at indexes (countCurrency % 6) and (countCurrency / 7) in that order. G. Print the contents of the list. • For the stack, perform the following operations in order - A. Push seven (7) objects starting from the array index 13 onwards to the stack. B. Peek the top of the stack - print the result. C. Perform three (3) pops in succession. D. Print the contents of the stack. E. Push five (5) more objects from the start of the objects array to the stack. F. Pop twice in succession. G. Print the contents of the stack. • For the queue, perform the following operations in order - A. Enqueue the seven (7) objects at odd indexes starting from index 5 in the array. B. Peek the front and end of the queue - print the results. C. Perform two (2) dequeues in succession. D. Print the contents of the queue. E. Enqueue five (5) more objects from the index 10 in the array. F. Dequeue three times in succession. G. Print the contents of the queue. • End the program with a leaving message of your choice. Remember to clean up before the program ends. • Restrict all your input/output to the main driver program only, except for the existing screen print inside the Currency print methods.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education