Question: Implement and test the Rational Number Program (slides 9 and 10). Then, implement the Operation __add__, __sub__, __mul__, __truediv__ for the Rational Operators (based on
Implement and test the Rational Number Program (slides 9 and 10). Then, implement the Operation __add__, __sub__, __mul__, __truediv__ for the Rational Operators (based on examples in slides 11 and 12)
slides are attached below
Please provide the code and output screenshot thank you




Using pickle for Permanent Storage of Objects Add function save to the class bank def save (self, fileName = None): import pickle #Save account data to file. if fileName != None: self. fileName = fileName elif self. fileName == None: return fileObj = open(self._fileName, "wb") for account in self._accounts.values(): pickle.dump (account, fileObj) fileObj.close() from bank import Bank, Savings Account Save data to a file on hard disk. b = Bank() b.add(Savings Account ("Wilma", "1001", 4000)) b.add(Savings Account ("Fred", "1002", 1000)) Using pickle to load data from file = Add an overall function init to the class bank def init (self, fileName = None): import pickle self. accounts self. fileName = fileName if fileName != None: fileObj = open(fileName, 'rb') while True: try: account = pickle.load(fileObj) self.add (account) except EOFError: fileObj.close() break Load data from file >>> from bank import Bank, SavingsAccount >>> b = Bank ("bankdata.dat") >>> print (b) Name: Fred PIN: 1002 Balance: 1000 Inheritance and Polymorphism Object-based programming techniques: Data Encapsulation: Restricting the manipulation of an objects state by external users to a set of method calls. Inheritance:Allowing a class to automatically reuse and extend the code Polymorphism:Allowing several different classes to use the same general method names. o O Physical object Living thing Inanimate object Mammal Insect Stone Asteroid Cat Ant [FIGURE 8.3] A simplified hierarchy of objects in the natural world A Restricted Savings Account Assume that the bank provide customer with restricted saving account similar to the ordinary saving account, but allow up to 3 withdrawals. >>> account = RestrictedSavings Account("Ken", "1001", 500.00) >>> print (account) Name: Ken PIN: 1001 Balance: 500.0 >>> account.getBalance() 500.0 >>> for count in range (3): account.withdraw(100) >>> account.withdraw(50) 'No more withdrawals this month' >>> account.resetCounter() >>> account.withdraw(50) The RestrictedSavingsAccount class can inherit from the SavingsAccount class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
