Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Lab 2 HW requirment 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...

1 answer below »
Lab 2 HW requirment
Programming problem: Cu
ency Simulato
A. Create an abstract base class called Cu
ency 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 cu
ency note value) and fractional part
(or cu
ency coin value) such that 100 fractional parts equals 1 whole part.
B. Create one derived class - Money - with two additional non-public string attributes
which will contain the name of the cu
ency note (Dollar) and cu
ency coin (Cent)
espectively. DO NOT add these attributes to the base Cu
ency class.
C. In your base Cu
ency class, add public class (C++ students are allowed to use
friend methods as long as a co
esponding class method is defined as well) methods
for the following, where appropriate:
● Default Construction (i.e. no parameters passed)
● Construction based on parameters for all attributes - create logical objects
only, i.e. no negative value objects allowed
● 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 cu
ency
● Subtracting one object from another object of the same cu
ency - the result
should be logical, i.e. negative results are not allowed
● Comparing two objects of the same cu
ency for equality/inequality
● Comparing two objects of the same cu
ency to identify which object is large
or smalle
● Print method to print details of a cu
ency object
● 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 ane return
new objects.
D. In your derived Money class, add new methods or ove
ide inherited methods as
necessary, taking care that code should not be duplicated or duplication minimized.
Think modular and reusable code.
E. Remember -
● Do not define methods that take any decimal values as input in either the
ase or derived classes.
● Only the print method(s) in the classes should print anything to console.
● Throw String (or equivalent) exceptions from within the classes to ensure that
invalid objects cannot be created.
F. In your main:
● Declare a primitive a
ay of 5 Cu
ency references (for C++ programmers,
a
ay of 5 Cu
ency pointers).
● Ask the user for 5 decimal numbers to be input - for each of the inputs you
will create one Money object to be stored in the a
ay.
● Once the a
ay is filled, perform the following five operations:
○ Print the contents of the a
ay of objects created in long form, i.e. if
the user entered "2.85" for the first value, it should be printed as "2
Dollar 85 Cent".
○ Add the first Money object to the second and print the resulting
value in long form as above.
○ Subtract the first Money object from the third and print the resulting
value in long form as above.
○ Compare the first Money object to the fourth and print whether both
objects are equal or not using long form for object values.
○ Compare the first Money object to the fifth and print which object
value is greater than the other object value in long form.
● All operations in the main should be performed on Cu
ency objects
demonstrating polymorphism.
● Remember to handle exceptions appropriately.
● 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

Lab 3 HW Requirment
Programming problem: Cu
ency Simulato
A. Create an abstract base class called Cu
ency 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 cu
ency note value) and fractional part
(or cu
ency coin value) such that 100 fractional parts equals 1 whole part.
B. Create one derived class - Money - with two additional non-public string attributes
which will contain the name of the cu
ency note (Dollar) and cu
ency coin (Cent)
espectively. DO NOT add these attributes to the base Cu
ency class.
C. In your base Cu
ency class, add public class (C++ students are allowed to use
friend methods as long as a co
esponding class method is defined as well) methods
for the following, where appropriate:
● Default Construction (i.e. no parameters passed)
● Construction based on parameters for all attributes - create logical objects
only, i.e. no negative value objects allowed
● 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 cu
ency
● Subtracting one object from another object of the same cu
ency - the result
should be logical, i.e. negative results are not allowed
● Comparing two objects of the same cu
ency for equality/inequality
● Comparing two objects of the same cu
ency to identify which object is large
or smalle
● Print method to print details of a cu
ency object
● 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 ane return
new objects.
D. In your derived Money class, add new methods or ove
ide inherited methods as
necessary, taking care that code should not be duplicated or duplication minimized.
Think modular and reusable code.
E. Remember -
● Do not define methods that take any decimal values as input in either the
ase or derived classes.
● Only the print method(s) in the classes should print anything to console.
● Throw String (or equivalent) exceptions from within the classes to ensure that
invalid objects cannot be created.
F. In your main:
● Declare a primitive a
ay of 5 Cu
ency references (for C++ programmers,
a
ay of 5 Cu
ency pointers).
● Ask the user for 5 decimal numbers to be input - for each of the inputs you
will create one Money object to be stored in the a
ay.
● Once the a
ay is filled, perform the following five operations:
○ Print the contents of the a
ay of objects created in long form, i.e. if
the user entered "2.85" for the first value, it should be printed as "2
Dollar 85 Cent".
○ Add the first Money object to the second and print the resulting
value in long form as above.
○ Subtract the first Money object from the third and print the resulting
value in long form as above.
○ Compare the first Money object to the fourth and print whether both
objects are equal or not using long form for object values.
○ Compare the first Money object to the fifth and print which object
value is greater than the other object value in long form.
● All operations in the main should be performed on Cu
ency objects
demonstrating polymorphism.
● Remember to handle exceptions appropriately.
● 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

1.png
10.jpg
11.jpg
12.jpg
2.png
3.jpg
4.jpg
5.jpg
6.jpg
7.jpg
8.jpg
9.jpg
Cu
ency.py
"""
CIS 22C Summer Quarte
Professor: Manish Goel
Student: Tannaz Anvari
**********
Lab 2
Started date: 7/08/2021
Updated dates: 07/09/2021, 07/10/2021, 07/12/2021
Final submission date: 07/13/2021
"""
from abc import abstractmethod
class Cu
ency:
def __init__(self, note=0, coin=0):
"""Constructor of the class"""
XXXXXXXXXXif note < 0 or coin < 0:
XXXXXXXXXXraise TypeE
or("Invalid argument!!")
XXXXXXXXXXself._note = note + coin
100
XXXXXXXXXXself._coin = coin % 100
def getNote(self):
"""Getter for note"""
XXXXXXXXXXreturn self._note
def getCoin(self):
"""Getter for coin"""
XXXXXXXXXXreturn self._coin
def setNote(self, note):
"""Setter for note"""
XXXXXXXXXXif note < 0:
XXXXXXXXXXraise TypeE
or("Invalid argument!!")
XXXXXXXXXXself._note = note
def setCoin(self, coin):
"""Setter for coin"""
XXXXXXXXXXif coin < 0:
XXXXXXXXXXraise TypeE
or("Invalid argument!!")
XXXXXXXXXXself._note += coin
100
XXXXXXXXXXself._coin = coin % 100
@abstractmethod
def __str__(self):
XXXXXXXXXXpass
@abstractmethod
def __add__(self):
XXXXXXXXXXpass
@abstractmethod
def __sub__(self):
XXXXXXXXXXpass
def print(self):
"""Method to print details of cu
ency"""
XXXXXXXXXXprint(self.__str__())
def add(self, o):
"""Method to add cu
ency"""
XXXXXXXXXXres = self + o
XXXXXXXXXXself._note = res._note
XXXXXXXXXXself._coin = res._coin
def subtract(self, o):
"""Method to subtract cu
ency"""
XXXXXXXXXXsub = self - o
XXXXXXXXXXself._coin = sub._coin
XXXXXXXXXXself._note = sub._note
@abstractmethod
def __eq__(self, o):
XXXXXXXXXXpass
@abstractmethod
def __gt__(self, o):
XXXXXXXXXXpass
def __ne__(self, o):
XXXXXXXXXXreturn not (self == o)
def __lt__(self, o):
XXXXXXXXXXreturn not (self == o) and not (self > o)
def __le__(self, o):
XXXXXXXXXXreturn not self
Answered Same Day Jul 20, 2021

Solution

Pratap answered on Jul 20 2021
157 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here