You\'ve been given an assignment by your supervisor to program a small applicati
ID: 3622166 • Letter: Y
Question
You've been given an assignment by your supervisor to program a small application to monitor the current status of the cash account in the firm's petty cash fund (the amount of cash kept on hand in the office for incidental purchases). The requirements for the program are to allow users to input the amount of cash deposited, the amount of cash withdrawn and to get a report of the balance at any given time. You will need to also add the date of each deposit and the date of each withdrawal and provide a date with the balance returned upon a given query. The program should be able to provide a printed report and support a command line query.
You are to use the object oriented properties of Python to accomplish this task.
Here are some hints to get you started:
* First, define a class. The example below is just an example that defines a class named Account, you will need to enhance it to make it more realistic.
class Account:
def __init__(self, initial):
self.balance = initial
def deposit(self, amt):
self.balance = self.balance + amt
def withdraw(self,amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance
* Using a, the sample class above:
a = Account(1000.00)
a.deposit(550.23)
a.deposit(100)
a.withdraw(50)
print a.getbalance()
Write the a program to accomplish the above requirements. Of course you will need to add the features to accept input, print output, and so on as indicated. Run and debug the program.
Add all the Python files above to a zip file. Also add a one page discussion of your experiences to the zip file.
Once you have finished with this example, please enhance it further by adding the date of transaction information: date of deposit, date of withdrawals, date of balance query and so on. The idea is that for every request there should be the historical date when the deposit/withdrawal occurred and the query date. Also setup a loop so that you can continuously, if desired, accomplish additional transactions. Integrate this with the Petty Cash System program. Run and debug it.
Explanation / Answer
import shelveimport string
import datetime
class Transaction:
DateOfTransaction = datetime.datetime(1900,1,1).today();
TypeOfTransaction = "";
FinalBalance = "";
def __init__(self, TypeOfTransaction,FinalBalance):
self.TypeOfTransaction =TypeOfTransaction;
self.FinalBalance = FinalBalance;
def showTransaction(self):
print str(self.DateOfTransaction) + " "+self.TypeOfTransaction + " " +str(self.FinalBalance);
class Account:
balance = 0.0;
transactions = [];
def __init__(self, balance):
self.balance = balance;
def deposit(self, amt):
self.balance = self.balance + amt
t = Transaction("Deposit",self.balance);
self.transactions.append(t);
print "Balance:" + str(self.balance);
def withdraw(self,amt):
self.balance = self.balance - amt
t = Transaction("Withdraw",self.balance);
self.transactions.append(t);
print "Balance:" + str(self.balance);
def displayTransactions(self):
for key in self.transactions:
key.showTransaction();
def getbalance(self):
return self.balance
foo = Account(10000)
b = 1
print "Welcome to the Petty Cash System!"
print "Primary account balance for an account:10000"
while(b != 3):
print "Please make a selection by typing one of the following options."
print "1.Deposit balance #: 1"
print"2.Withdraw balance #: 2"
print "3.Show transactions #: 3"
print "4.exit the Database type the #: 4"
b = input(':')
if b == 1:
print "Enter the Deposit:"
n = raw_input(':')
foo.deposit(int(n));
if b == 2:
print "Enter the Withdraw:"
n = raw_input(':')
foo.withdraw(int(n));
if b == 3:
foo.displayTransactions();
if b == 4:
break;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.