Question: Create a USD currency class with two integer attributes and one string attribute, all of which are non-public (Python programmers - it is understood that

Create a USD currency class with two integer attributes and one string attribute, all of which are non-public (Python programmers - it is understood that there is nothing private in Python but try to not access the attributes directly from outside the classes). The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name.

B. Create a C2D derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar.

  • The value of the conversion factor can be defaulted in the class definition based on 1 USD = 1.36 C2D or 1 C2D = 0.74 USD.

C. In your two currency classes, add public methods for the following:

  • Default Construction (i.e. no parameters passed)
  • Construction based on parameters for all attributes
  • Copy Constructor and/or Assignment, as applicable to your programming language of choice
  • Destructor, as applicable to your programming language of choice
  • Setters and Getters for all attributes
  • Adding two objects of the same currency
  • Subtracting one object from another object of the same currency
  • Comparing two objects of the same currency for equality/inequality
  • Comparing two objects of the same currency to identify which object is larger or smaller
  • Print method to print details of a currency object
  • In your derived class only, methods to convert USD objects to C2D and vice versa

Above is further information but not needed to be solved

This question is the one bolded below:

D. Create a Wallet class with one attribute - an array of two USD references / pointers and the following methods to demonstrate polymorphism of the currencies:

  • A default Constructor which sets
    • the first element of the array to a zero value USD object
    • the second element of the array to a zero value C2D object
  • A Destructor, as applicable to your programming language of choice
  • Methods to add or subtract currency objects appropriately using USD references / pointers, i.e.
    • USD objects to/from the first element only and
    • C2D objects to/from the second element only
    • Do not write currency specific add/subtract methods as that would defeat the purpose of polymorphism.
  • Methods to compare if the value of either element is greater or smaller than an input value using USD references only. This method can be called upon in the subtract method above as needed.
  • A method to Print the values of the two elements in the Wallet

E. In your main:

  • Create a Wallet object
  • Provide the user a main menu to add/ subtract/ compare the USD and C2D values in the Wallet as well as print the contents of the Wallet
  • You can use a second level menu choice to allow the user to select currency type
  • Based on user choice, create either USD or C2D objects as needed to perform the desired operations.
  • The main menu should be run in a loop until the user selects the Exit option
  • There is no sample output - you are allowed to provide user interactivity as you see fit and programs will be graded for clarity of interaction

Dollar Class (USD to Dollar)

class Dollar { private: int noteValue; int centValue; string currencyName; public: Dollar(){}; Dollar(int note,int coin){ noteValue = note; centValue = coin; } ~Dollar(){ }; int getNoteValue(){ return noteValue; } void setNoteValue(int x){ noteValue = x; }

int getCoinValue(){ return coinValue; } void setUScoinValue(int x){ UScoinValue = x; }

Dollar operator +(Dollar obj){ Dollar obj2; obj2.noteValue = noteValue + obj.USnoteValue; obj2.coinValue = coinValue + obj.UScoinValue; return obj2; }

Dollar operator -(Dollar obj){ Dollar obj2; obj2.noteValue = this->noteValue - obj.noteValue; obj2.coinValue = this->coinValue - obj.coinValue; return obj2; } bool operator ==(Dollar obj){ if ((this->noteValue == obj.noteValue) && (this->coinValue == obj.coinValue)) return true; else return false; } double dollarToCsdollar(int note,int coin) { double amount = (note+coin*0.01); return amount*1.36; } double dollarAmount(int note,int coin) { cout<<"Dollars:"<<(note+coin*0.01); return (note+coin*0.01); } };

Language: C++

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!