views:

2057

answers:

1

Hi everyone. I've been working on my project about bank account transactions (withdraw, deposit, check cashed, and balance inquiry) using "account.txt". My TA said that I have to use temporary file. This temporary file will read line by line to find what the user is looking for. However, I did not understand this temporary OPEN file at all. Does anyone explain what that is, and if it's possible, would you attach example of it?

Here are the project instructions: This project is about writing a program to perform transactions on bank accounts. You will be given a file which contains all the accounts in the bank (the file is named “account.txt”). Your program is to provide an interactive menu for users to perform transactions on these accounts. Your program needs to update the account file after each transaction. The user may perform transactions on accounts that are not available. Your program needs print an error message on the screen and return to the menu. In addition, your program needs to print whether a transaction is successful. For unsuccessful transaction, your program will print out the reason for the failed transaction.

Your program needs to be able to handle the following transactions:

  • Deposit money into an account
  • Withdraw money from an account
  • Check cashed against an account
  • Balance inquiry of an account

There is a limit on how many checks can be cashed against a saving account. The limit is 2 checks per month. There is a $0.25 penalty for each check cashed over the limit. If there is enough fund to cash the check but not the penalty, the transaction should go through and the resulting balance would be zero.

Here is the format in the account file for one account (data fields are separated by exactly one space): Account type, S for saving, C for checking (1 character) Account number of 5 digits Last name of account holder (15 characters) First name of account holder (15 characters) Balance of the account in the form xxxxx.xxx An integer field indicating how many checks have been cahsed this month (three digit) An interest rate in the form of xx.xx (e.g. 10.01 = 10.01%) For names with fewer than 15 characters, the data will be padded to have width of 15 characters.

Here is an example of the account file: C 12345 Smith John 100.000 10 0.00 S 45834 Doe Jane 3462.340 0 0.30 C 58978 Bond Jones 13.320 5 0.00

*Creating temporary file There is a way in FORTRAN to create a temporary file. Use: OPEN(UNIT = , STATUS = "SCRATCH", ...) There is no need to provide (FILE = ””). By using a temporary file, you can copy the accounts from the account file to the temporary file. Then when you copy the data back from the temporary file to the account file, perform the necessary transactions. Your program should not copy accounts between these two files if a transaction is to be failed.

Please forgive my english, I'm Japanese.

Yuuka

+1  A: 

The are saying that a statement such as:

OPEN (7, ACCESS = 'DIRECT',STATUS = 'SCRATCH')

You can create a temporary file--one that will only live until you close it, and not be saved to disk. This file needs no name (it's never going to be referred to by name) just a unit number (in my example 7).

You can use this file to hold the account information temporarily during a transaction. You need this because, when you are inserting rows into the real file, and you don't want to overwrite subsequent data. So they are saying:

  • Copy everything to a temporary file
  • If the transaction succeeds, copy the data back to the main file but
    • Omit rows that are to be deleted
    • Add in the rows that are to be inserted

Does that help?

MarkusQ
Thank you for your answer. That helps me a lot. One thing, do I still have to open the "account.txt" file to do this?If so, do I need to use the same UNIT number that is used in temporary file?
Uka
Yes, you need to open "account.txt", but with a _different_ unit number.
MarkusQ