Problem 1: A bank maintains its account records in a sequential text file named
ID: 3594654 • Letter: P
Question
Problem 1: A bank maintains its account records in a sequential text file named accounts.txt. The record for each account contains the following: account number, account holder’s name, street address, city, state, zip, account type, and current balance. Design the logic, in pseudocode, for a program that
a. Reads each record in the accounts.txt file
b. Calculates interest for the account based on the following rules:
i. If the account type is “checking” and the current balance is at least $1,000, the interest rate is 1%, otherwise, it is 0.5%
i. If the account type is “savings” the interest rate is 2%
c. Calculates the balance after adding interest
d. Writes the account data with the updated account balance to another file named processed_accounts.txt
e. In another file named statements.txt, writes the account data in the proper format for a bank statement that has
i. the account holder’s name and address as required by the post office
ii. the account number
iii. the balance before interest was added
iv. the interest amount in dollars
v. the balance after adding interest
Explanation / Answer
begin
inputFile = 'accounts.txt'
outputFile = 'processed_accounts.txt'
bankStatementFile = 'statements.txt'
// open the accounts.txt file for reading data line by line
open inputFile in read mode
// create processed_accounts.txt and statements.txt for writing output
create new files outputFile and bankStatementFile in write mode
// read the file till we reach its end
while end of inputFile has not been reached
// assume each line contains account number, account holder’s name, street address, city, state, zip, account type, and current balance separated by space i.e one record
read one line from inputFile into the variables accountNumber , accountHolderName, streetAddress, city, state, zip, accountType, currentBalance
//calculation of interest
interest = 0
if accountType = "checking" then
if currentBalance >=1000 then
interest = (1*currentBalance)/100
else
interest = (0.5*currentBalance)/100
else if accountType = "savings" then
interest = (2*currentBalance)/100
// update the balance
updated_balance = currentBalance + interest
write accountNumber , accountHolderName, streetAddress, city, state, zip, accountType,updated_balance to outputFile
// streetAddress,city,state,zip - address of accountHolderName currentBalance - balance before interest was added and updated_balance - balance after adding interest
write accountHolderName, streetAddress, city, state, zip, accountNumber, currentBalance , interest , updated_balance to bankStatementFile
move to next line in inputFile // move to the next line to read the next record
end while
close inputFile,outputFile,bankStatementFile // close all the files
end