Checking Account Lab (Using Microsoft Visual C++ 2010 Express) Construct a C pro
ID: 3623620 • Letter: C
Question
Checking Account Lab (Using Microsoft Visual C++ 2010 Express)Construct a C program which reads the details of a monthly checking account and outputs a bank statement summarizing these transactions. An input file, account.txt, contains a list of transactions for the checking account for one month. Each line of the input file consists of a one character transaction code along with a float containing the amount of the transaction. Valid transaction codes are as follows:
• I – initial balance brought forth from previous month
• D - deposit
• C - check cashed
As each transaction is entered, you should output on a single line the type of transaction, the amount of the transaction (separate columns for deposits and checks cashed), and the balance after the transaction has been processed:
Transaction Deposit Check Cashed Balance
----------- ------ ------------ -------
Initial Balance 478.83
Deposit 127.45 606.28
Deposit 619.84 1226.12
Check Cashed 945.12 281.00
...
The banks service charges (which should be deducted from the balance at the end of the month) are as follows:
• $3.00 per month to maintain the account.
• $0.06 for each check cashed.
• $0.03 for each deposit made.
• $5.00 overdraft whenever a check cashed brings the balance below $0.00. (Note: Do not assess the service charge when the transaction is a deposit into an overdrawn account that does not bring the balance above zero.
The bank statement should also include the following information:
• total number of deposits
• total amount of deposits
• total number of checks cashed
• total amount of checks cashed
• total service charge
• opening balance
• closing balance
To access the account.txt input file, add the following declaration to your C program before main():
FILE *fp;
In main(), after your variable declarations, add the following statement:
fopen_s(&fp, "account.txt", "r");
Note: if you are using an older C compiler, the above statement would be written as:
fp = fopen(“account.txt”, “r”);
This loop reads each line of the input file into character variable code and float variable amount:
while (!feof(fp)) {
fscanf(fp, "%c %f ", &code, &amount);
The contents of account.txt are shown below:
I 478.83
D 127.45
D 619.84
C 945.12
C 4.76
D 32.81
C 1.06
D 184.32
C 495.18
C 141.81
C 255.10
D 250.00
D 123.88
D 245.05
D 873.25
C 981.12
D 317.84
C 812.73
D 606.12
Points to remember:
Make sure you are creating a C program and not a C++ program.
You should not be using any global variables in your program
Explanation / Answer
please rate - thanks
I don't know how do compile C on visual C++
ran this on DEV C++
message me if any problems
#include <stdio.h>
#include <conio.h>
int main()
{char type;
float amt,bal=0,initamt,tdep=0,tservice=0,totcashed=0,totservice=0,fees;
int dep=0,cashed=0;
FILE *input;
input = fopen("input.txt","r");
if(input == NULL)
{ printf("Error opening input file 1! ");
return 0;
}
printf("Transaction Deposit Check Cashed Balance ");
printf("-------------------------------------------------------- ");
while(fscanf(input,"%c",&type)>0)
{fscanf(input,"%f",&amt);
switch(type)
{case 'I': initamt=amt;
bal=amt;
printf("Initial Balance %7.2f ",bal);
break;
case 'D': tdep+=amt;
bal+=amt;
dep++;
printf("Deposit %.2f %7.2f ",amt,bal);
break;
case 'C': totcashed+=amt;
cashed++;
bal-=amt;
printf("Check Casked %7.2f %7.2f ",amt,bal);
if(bal<0)
{ tservice+=5;
bal-=5;
printf("Service Charge 5.00 %7.2f ",bal);
}
break;
}
}
tservice=tservice+3+.06*cashed+.03*dep;
printf("Total number of deposits: %d ",dep);
printf("Total amount of deposits: $%7.2f ",tdep);
printf("Total number of checks cashed: %d ",cashed);
printf("Total amount of checks cashed: $%7.2f ",totcashed);
printf("Total service charge: $%7.2f ",tservice);
printf("Opening balance: $%7.2f ",initamt);
printf("Closing balance: $%7.2f ",bal);
fclose(input);
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.