other needed. Your pgm will use the following 20 Krone objects to be created in the exact order in your main to seed the tree: 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 • Also, create an output file to write program output as specified in one or more instructions below. • After seeding the data, perform your traversal operations in the specific sequence of breadth-first, in-order, pre-order, post-order, ensuring that output is written out to both screen and file concurrently. • Then provide interactivity for the user to add/search/delete nodes from the console after the data has been seeded into the application. • Perform adequate input data validation when reading data from the user into the tree - if any data item is invalid, ignore the data item and continue to next item but print a message to output (both screen and same output file) to indicate which data items were ignored. • Also, provide the user the option to print output of traversals or exit the program. Once the user selects the option to print data or exits the program, the data in the BST should be printed out to both screen and output file in all four traversal methods in the specific sequence of breadth-first, in-order, pre- order, post-order. • For submission - upload all code files necessary to make your program run (not just your BST, Krone and main code files) as well as screenshots of console window and your output files only. Any other questions or clarifications - ask on the forum first.

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
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) { }
};
• Declare and implement a BSTNode ADT with a data attribute and two pointer attributes, one for the left child and the other for the right child. Implement
the usual getters/setters for these attributes.
• Declare and implement a BST as a link-based ADT whose data will be Krone objects - the data will be inserted based on the actual money value of your
Krone objects as a combination of the whole value and fractional value attributes.
• For the BST, implement the four traversal methods as well as methods for the usual search, insert, delete, print, count, isEmpty, empty operations and any
other needed.
Your pgm will use the following 20 Krone objects to be created in the exact order in your main to seed the tree:
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
• Also, create an output file to write program output as specified in one or more instructions below.
• After seeding the data, perform your traversal operations in the specific sequence of breadth-first, in-order, pre-order, post-order, ensuring that output is
written out to both screen and file concurrently.
• Then provide interactivity for the user to add/search/delete nodes from the console after the data has been seeded into the application.
• Perform adequate input data validation when reading data from the user into the tree - if any data item is invalid, ignore the data item and continue to next
item but print a message to output (both screen and same output file) to indicate which data items were ignored.
• Also, provide the user the option to print output of traversals or exit the program. Once the user selects the option to print data or exits the program, the
data in the BST should be printed out to both screen and output file in all four traversal methods in the specific sequence of breadth-first, in-order, pre-
order, post-order.
• For submission - upload all code files necessary to make your program run (not just your BST, Krone and main code files) as well as screenshots of console
window and your output files only.
Any other questions or clarifications - ask on the forum first.
Transcribed Image Text:• Declare and implement a BSTNode ADT with a data attribute and two pointer attributes, one for the left child and the other for the right child. Implement the usual getters/setters for these attributes. • Declare and implement a BST as a link-based ADT whose data will be Krone objects - the data will be inserted based on the actual money value of your Krone objects as a combination of the whole value and fractional value attributes. • For the BST, implement the four traversal methods as well as methods for the usual search, insert, delete, print, count, isEmpty, empty operations and any other needed. Your pgm will use the following 20 Krone objects to be created in the exact order in your main to seed the tree: 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 • Also, create an output file to write program output as specified in one or more instructions below. • After seeding the data, perform your traversal operations in the specific sequence of breadth-first, in-order, pre-order, post-order, ensuring that output is written out to both screen and file concurrently. • Then provide interactivity for the user to add/search/delete nodes from the console after the data has been seeded into the application. • Perform adequate input data validation when reading data from the user into the tree - if any data item is invalid, ignore the data item and continue to next item but print a message to output (both screen and same output file) to indicate which data items were ignored. • Also, provide the user the option to print output of traversals or exit the program. Once the user selects the option to print data or exits the program, the data in the BST should be printed out to both screen and output file in all four traversal methods in the specific sequence of breadth-first, in-order, pre- order, post-order. • For submission - upload all code files necessary to make your program run (not just your BST, Krone and main code files) as well as screenshots of console window and your output files only. Any other questions or clarifications - ask on the forum first.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Binary Tree
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