Coding help...very basic

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Igorati

    #1

    Coding help...very basic

    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.

  • Diez B. Roggisch

    #2
    Re: Coding help...very basic

    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.

    --
    Regards,

    Diez B. Roggisch

    Comment

    • Dennis Lee Bieber

      #3
      Re: Coding help...very basic

      On Sun, 06 Mar 2005 12:47:27 -0500, "Igorati" <wade_stoddard@ yahoo.com>
      declaimed the following in comp.lang.pytho n:
      [color=blue]
      > 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:
      >[/color]
      Searchable by what? Only by your application, or via a text
      editor or GREP?
      [color=blue]
      >
      > 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.
      >[/color]
      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...
      [color=blue]
      > You are to use the object oriented properties of Python to accomplish this
      > task.[/color]

      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.


      --[color=blue]
      > =============== =============== =============== =============== == <
      > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
      > wulfraed@dm.net | Bestiaria Support Staff <
      > =============== =============== =============== =============== == <
      > Home Page: <http://www.dm.net/~wulfraed/> <
      > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

      Comment

      • Igorati

        #4
        Re: Coding help...very basic

        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.

        Comment

        • Igorati

          #5
          Re: Coding help...very basic

          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,a mt):
          self.balance = self.balance - amt
          def getbalance(self ):
          return self.balance

          import time
          time.asctime()

          import win32api
          source_filename = "log.txt"
          win32api.ShellE xecute (
          0
          "print"
          source_filename
          None
          "."
          0)


          Comment

          • Dennis Lee Bieber

            #6
            Re: Coding help...very basic

            On Sun, 06 Mar 2005 18:37:34 -0500, "Igorati" <wade_stoddard@ yahoo.com>
            declaimed the following in comp.lang.pytho n:
            [color=blue]
            > 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,a mt):
            > self.balance = self.balance - amt
            > def getbalance(self ):
            > return self.balance
            >[/color]
            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(Transac tion) {inherits from transaction}, which treats the
            amount as a positive value; Withdrawal(Tran saction), 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.
            --[color=blue]
            > =============== =============== =============== =============== == <
            > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
            > wulfraed@dm.net | Bestiaria Support Staff <
            > =============== =============== =============== =============== == <
            > Home Page: <http://www.dm.net/~wulfraed/> <
            > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

            Comment

            • Igorati

              #7
              Re: Coding help...very basic

              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(sel f,

              self.transactio n =
              import time
              time.asctime()
              raw_input("Is this a deposit or withdrawl?")
              if withdrawl:
              elif
              raw_input("Plea se enter amount here.")

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

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



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


              Comment

              Working...