Coding help...very basic

I

Igorati

I need some ideas of how to accomplish this task.
I was told that I just need to save the input in a file and make the file
searchable, nothing fancy like tying into SQL or Oracle. THis is a basic
program and help is greatly appreciated:


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.
 
D

Diez B. Roggisch

Hi,

people here usually tend not to be too helpful when asked to do an obvious
homework task. So if you really want help, provide some code you've already
written and that has actual problems. Then we're glad to help. But don't
expect others to do your work.
 
D

Dennis Lee Bieber

I need some ideas of how to accomplish this task.
I was told that I just need to save the input in a file and make the file
searchable, nothing fancy like tying into SQL or Oracle. THis is a basic
program and help is greatly appreciated:
Searchable by what? Only by your application, or via a text
editor or GREP?
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.
Sounds like a check-book register... I'd probably use a simple,
fixed width, record oriented text file with columns of:

date activity amount {optional balance}

For quick current balance retrieval I'd probably use the first
record for the current balance only (file will need "r+" access, fixed
width means you can correctly index through it by just "record # *
width"). You could even store the count of data records in the date
field, as the "current balance" will either be the date/time of the
query, or can be obtained from the last transaction record.

Problem with the "optional balance" field is that, if entries
are made in one order, and the data is subsequently sorted, the running
balance field is out of order...
You are to use the object oriented properties of Python to accomplish this
task.

This sounds like a homework assignment, possibly asking for one
to use pickle to store "deposit" and "withdrawal" objects. I don't think
I'd bother with a "current balance" object, though it does mean having
to scan the entire data set to compute.


--
 
I

Igorati

Thank both for the help. I understand that I should provide code, I am
still trying to understand what to do, I don't want the work done, just
some ideas of where to go, a general layout perhaps. Thank you.
 
I

Igorati

This is just a basic of what I have so far. The time , a class I will need
and the print function.

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

import time
time.asctime()

import win32api
source_filename = "log.txt"
win32api.ShellExecute (
0
"print"
source_filename
None
"."
0)
 
D

Dennis Lee Bieber

This is just a basic of what I have so far. The time , a class I will need
and the print function.

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
Probably too high a level... Recall: your requirements suggest
you need to maintain the date of each deposit/withdrawal. This would
imply that you can't just keep a running total. How else could you
create a report?...

If you want a sort of hierarchy, you could have Transaction (a
base class, has date and amount fields, and maybe identifier of who
performed the transaction, but does not handle debit/credit direction);
Deposit(Transaction) {inherits from transaction}, which treats the
amount as a positive value; Withdrawal(Transaction), which treats the
amount as a negative value; Account, which has an account owner, and a
list of Transactions... getBalance() would return the result of summing
the Transactions.

The file processing could be done by recursively pickling an
account object, and all the transactions it contains.


Shifting focus for a moment... One of the starting points in
many OO-related courses is...

Look at your problem description... Find the nouns... These are
candidates for the objects (classes) you need; some may be removed as
irrelevant later.

Look for the verbs... These may indicate the candidates for
object methods.
--
 
I

Igorati

Hello all, I am still needing some help on this code, I have gone a bit
further on it. Thank you for the help. I am trying to understand how to
make the file searchable and how I am to make the deposit and withdrawl
interact with the transaction class.

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

class Transactoin:
def transaction(self,

self.transaction =
import time
time.asctime()
raw_input("Is this a deposit or withdrawl?")
if withdrawl:
elif
raw_input("Please enter amount here.")

class Deposit(Transaction):
def deposit(self, amt):
self.balance = self.balance + amt
def getbalance(self):
return self.balance

class Withdrawl(Trasaction):
def withdrawl(self, amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance
import pickle
pickle.dump ((withdrawl), file ('account.pickle', 'w'))
pickle.dump ((deposit), file ('account.pickle', 'w'))



print "Your current account total is.", self.balance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top