1. Display the following menu to the user: Bank Account Manager 1. Make a deposi
ID: 3536415 • Letter: 1
Question
1. Display the following menu to the user:
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6):
2. The menu should be looped until the user chooses to exit the program, and the program should perform one of the 6 choices based on the user%u2019s input at the menu screen. Once the user finishes with a choice, the menu should be redisplayed prompting the user to make another choice.
INTPUT VALIDATION: The input to the menu should be validated to make sure that the user enters a number 1 %u2013 6. If the user enters any other number, an error message should be displayed and the menu should be redisplayed.
3. OPTION 1: Make a deposit:
a) If the user chooses 1 on the menu screen, then you should prompt the user to enter a deposit into the account.
b) The deposit should be added to the balance in the bank account
c) All deposits should be stored in an output file called "transaction_list.txt" as a positive number.
4. OPTION 2: Make a withdrawal:
a) If the user chooses 2 on the menu screen, then you should prompt the user to enter an amount to withdraw from the account.
b) The withdrawal amount should be subtracted from the balance in the bank account.
c) All withdrawals should be stored in an output file called "transaction_list.txt" as a negative number.
NOTE: The transactions should appear in the output file in the exact order that the user makes the transaction. Please see the sample file.
5. OPTION 3: Show current balance:
a) If the user chooses 3 on the menu screen, then you should display the current balance that is in the account.
6. OPTION 4: Display account report:
a) If the user chooses 4 on the menu screen, then you should display a report about the account which contains the following information. The report should be displayed on the console.
b) the current balance in the account.
c) the number of deposits to the account.
d) the total amount of the deposits to the account.
e) the average deposit amount.
d) the number of withdrawals from the account.
f) the total amount of withdrawals from the account.
g) the average withdrawal from the account.
7. OPTION 5: Print account report:
a) If the user chooses 5 on the menu screen, then you should store all of the information from OPTION 4 in a file called "bank_account_report.txt";
8. OPTION 6: Exit program:
a) If the user chooses 6 on the menu screen then the program should exit
Sample Program Run (Note this is one execution of the program)
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 7
Incorrect menu choice!
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 1
Enter the deposit amount: 200
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 2
Enter the withdrawal amount: 40
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 2
Enter the withdrawal amount: 100
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 1
Enter the deposit amount: 25
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 1
Enter the deposit amount: 35
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 3
Current Balance: $620
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 4
Current Balance: $620
Number of Deposits: 3
Total Deposit Amount: $260
Average Deposit Amount: $86.6667
Number of Withdrawals: 2
Total Withdrawal Amount: $140
Average Withdrawal Amount: $70
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 5
Report sent to file!
Bank Account Manager
1. Make a deposit
2. Make a withdrawal
3. Show current balance
4. Display account report
5. Print account report
6. Exit program.
Enter a choice (1-6): 6
Program will now exit!
Press any key to continue ....
transaction_list.txt Would contain
200
-40
-100
25
35
bank_account_report.txt Would contain
Current Balance: $620
Number of Deposits: 3
Total Deposit Amount: $260
Average Deposit Amount: $86.6667
Number of Withdrawals: 2
Total Withdrawal Amount: $140
Average Withdrawal Amount: $70
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE *fp;
char ch1;
fp=fopen("bank_account_report.txt","w");
int ch;
float init_bal = 500.0; // initial balance
float amn;
float total=0;
int dep,wit;
float dep_amn=0.0,wit_amn=0.0,avg_dep=0.0,avg_wit=0.0;
printf(%u201CEnter ur choice 1. Make Deposit 2. Make Withdrawl 3. Show Current Balance 4. Display account report 5. Print account report 6. Exit %u201C;
scanf(%u201C%d,&ch);
void choice()
{
while(ch!=6){ // until user exits
switch(ch)
{
case 1: deposit();
break;
case 2: withdraw();
break;
case 3: show_curr();
break;
case 4: disp_acc();
break;
case 5: print_acc();
break;
default: exit();
}
}}
getch();
}
void deposit()
{dep=0; // count deposits
printf(%u201Center amount to be deposited%u201D);
scanf(%u201C%f%u201D,&amn);
total += init_bal + amn; //balance update
dep++;
dep_amn+=amn; // tracks total deposited amount
printf(%u201CTotal Amount= %f%u201D,total);
choice(); // displays list again
}
void withdraw()
{
wit=0;
printf(%u201Center amount to be withdrawn%u201D);
scanf((%u201C%f%u201D,&amn);
if(amn<=total) // condition check
{
total-=amn; // balance deducted
wit++;
wit_amn+=amn;
}
else
{
printf(%u201Cinvalid amount..enter again%u201D);
withdraw();
}
choice(); // displays list again
}
void show_curr()
{
printf(%u201CTotal Amount= %f%u201D,total);
choice(); // displays list again
}
void disp_acc()
{
avg_dep= dep_amn/ dep;
avg_wit= wit_amn/ wit;
printf(%u201CCurrent Amount: %f%u201D,total);
printf(%u201CTotal Deposits: %d%u201D, dep);
printf(%u201CTotal Deposit Amount: %f%u201D, dep_amn);
printf(%u201CAverage Deposit Amount: %f%u201D, avg_dep);
printf(%u201CTotal Withdraws: %d, wit);
printf(%u201CTotal Withdrawn Amount: %f%u201D, wit_amn);
printf(%u201CAverage Withdrawn Amount: %f, avg_wit);
choice(); // displays list again
}
void print_acc()
{
putc((%u201CCurrent Amount: %f%u201D,total) ,fp);
putc((%u201CTotal Deposits: %d%u201D, dep),fp);
putc((%u201CTotal Deposit Amount: %f%u201D, dep_amn) ,fp);
putc((%u201CAverage Deposit Amount: %f%u201D, avg_dep) ,fp);
putc((%u201CTotal Withdraws: %d, wit) ,fp);
putc((%u201CTotal Withdrawn Amount: %f%u201D, wit_amn),fp);
putc((%u201CAverage Withdrawn Amount: %f, avg_wit),fp);
choice(); // displays list again
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.