Question
------------c++ only----------- Please follow all the instructions on Lab - General Submission Instructions as well as given here. Instructions given here override in case they
------------c++ only-----------
-
- Please follow all the instructions on Lab - General Submission Instructions as well as given here.
- Instructions given here override in case they conflict with anything on the Lab - General Submission Instructions.
- Also, take care to follow code styling instructions on Code Styling Guidelines.
- Remember - write your code with a reusability philosophy as some or all of this code may be integrated into one or more future labs.
- For clarifications, feel free to post Qs on the discussion board - describe your problem in English without any code. Similarly, other students are welcome to answer in plain English to help your fellow students out.
- Do not send me email or canvas messages unless there is something personal in the Q or only if I ask you to show me any code. Remember - I will not be giving you your-code-specific answers.
YOU ARE ALLOWED TO WORK IN GROUPS OF UP TO 2 PEOPLE - IF YOU WORKED IN A TEAM FOR LAB 1, YOU CAN CONTINUE IN THE SAME TEAM OR MAKE CHANGES. IN EITHER CASE YOU WILL NEED TO BE PART OF A NEW 'LAB 2 TEAM'.
-
YOU WILL NEED TO SELF SELECT YOUR GROUP UNDER THE "LAB 2 TEAMS". IF YOU CHOOSE TO WORK SOLO, YOU STILL NEED TO BE IN ONE OF THE 'LAB 2 TEAMS', BUT PLEASE UNDERSTAND THAT WORKING WITH A PARTNER IS BETTER FOR YOU.
- ALSO, ONCE SET, THE TEAMS SHOULD BE MAINTAINED FOR THE REST OF THE QUARTER AS CODE CREATED HERE WILL BE REUSED IN FUTURE LABS.
-
Programming problem: Currency Simulator
A. Create an abstract base class called Currency with two integer attributes, both 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.
B. Create two derived classes - Dollar and Pound - with one additional non-public string attribute which will contain the name of the currency (Dollar or Pound) respectively. DO NOT add this attribute to the base Currency class.
C. In your base Currency class, add public methods for the following, where appropriate (C++ students are allowed to use friend methods as overloads only, i.e. the corresponding class method needs to be defined first):
- Default Construction (i.e. no parameters passed).
- Construction based on one single input of type double - create logical objects only, i.e. no negative value objects allowed.
- Copy Constructor and/or Assignment (i.e. the input is an object of the same class), as applicable to your programming language of choice.
- Destructor, as applicable to your programming language of choice.
- Setters and Getters for all attributes, as may be necessary.
- A method called add for adding an input object of the same currency.
- A method called subtract for subtracting an input object of the same currency - the result should be logical, i.e. negative results are not allowed.
- A method called isEqual for comparing an input object of the same currency for equality/inequality.
- A method called isGreater for comparing an input object of the same currency to identify which object is larger or smaller.
- A method called print to print the name and value of a currency object in the form "xx.yy" followed by the derived currency name, e.g. 1.23 Dollar or 2.46 Pound.
- All of the above should be instance methods and not static.
- The add and subtract as specified should manipulate the object on which they are invoked. It is allowed to have overloaded methods that create and return new objects .
D. In your derived Dollar and Pound classes, add new methods or override inherited methods as necessary, taking care that code should not be duplicated or duplication minimized. Think modular and reusable code.
E. Remember -
- Only the print method(s) in the classes should print anything to console, besides the main below.
- Throw String (or equivalent) exceptions from within the classes to ensure that invalid objects cannot be created.
- In all methods, ensure that you are not mixing objects of different currencies.
F. In your main:
- Declare a primitive array of 2 Currency references (for C++ programmers, array of 2 Currency pointers).
- Set the first reference in the array to a Pound object and the second reference to a Dollar object, both of zero value.
- Then perform the sequence of operations as in the sample input/output below, understanding that your program will be tested with a different sequence of operations using the same patterns.
- All operations in the main should be performed on Currency objects demonstrating polymorphism.
- Remember to handle exceptions appropriately.
- Sample input / output for your main - remember my test program will follow the same pattern but not the same sequence:
Event Sequence Sample Input Sample Output Program Starts 0.00 Pound 0.00 Dollar Add a pound object a p 1.11 pound 1.11 Pound 0.00 Dollar Add a dollar object a d 12.12 dollar 1.11 Pound 12.12 Dollar Add a pound object a d 3.45 pound Invalid addition
1.11 Pound 12.12 Dollar
Add a dollar object a d 0.13 dollar 1.11 Pound 12.25 Dollar Subtract a dollar object s d 10 dollar 1.11 Pound 2.25 Dollar Subtract a dollar object s d 2.5 dollar Invalid subtraction
1.11 Pound 2.25 Dollar
Subtract a pound object s p 0.11 pound 1.00 Pound 2.25 Dollar End the program q
------------c++ only-----------
------------c++ only-----------
------------c++ only-----------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started