Question: class Currency { protected: int whole; int fraction; virtual std::string get_name() = 0; public: Currency() { whole = 0; fraction = 0; } Currency(double value)

class Currency {

protected:

int whole;

int fraction;

virtual std::string get_name() = 0;

public:

Currency() {

whole = 0;

fraction = 0;

}

Currency(double value) {

if (value

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

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

return false;

if (whole == curr.whole && 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

}

};

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 Currency { protected: int whole; int fraction; virtual std::string get_name() =

- 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. Kr57.12 2. Kr23.44 3. Kr87.43 4. Kr68.99 5. Kr111.22 6. Kr44.55 7. Kr77.77 8. Kr18.36 9. Kr543.21 10. Kr20.21 11. Kr345.67 12. Kr36.18 13. Kr48.48 14. Kr101.00 15. Kr 11.00 16. Kr21.00 17. Kr51.00 18. Kr1.00 19. Kr251.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, preorder, 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!