Working on a C++ banking program, need assistance in formulating following functions:
-function depositMoney, which receives three parameters (the index of the
account in the array, the amount to be deposited, and the array of accounts). The function will
update the balance and will save the transactions information (including the date and time) in the
file that has the same name as the account number.
-function withdrawMoney, which receives three parameters (the index of the
account in the array, the amount to be withdrawn, and the array of accounts). The function will
update the balance and will save the transactions information (including the date and time) in the
file that has the same name as the account number.
-function openAccount, which asks for the account owner’s information (e.g.
name and opening balance). The function will add a new record to the array of accounts and
accounts.txt as well as create a new file (with the same name as the account number) and update
the transactions information (including the date and time) with the opening balance.
Please find the code for the problem below. I have added comments extensively to make it understandable.
#include<bits/stdc++.h>
using namespace std;
/*
* allAccounts contains the list of active accounts
* numAccounts is the number of active accounts
* A new account is assigned the same number as numAccounts
* The transactions of an account are saved in a text file of the
form "Account_number.txt"
* "accounts.txt" contains the list of all accounts
*/
struct Account{
string name;
int acno;
int balance;
};
//total number of accounts
int numAccounts;
//Array of all accounts in the bank;
Account allAccounts[100];
//helper function to print a Transaction
void printTransaction(int acno, int deposit){
ofstream acc;
acc.open(to_string(acno)+".txt", ios::app);
time_t t = std::time(0); // get time now
acc<<ctime(&t)<<"Deposit of:
"<<deposit<<"\n";
acc.close();
}
//helper function to print Account details on the console
void printAccountDetails(Account a){
cout<<"Account name:
"<<a.name<<endl;
cout<<"Account num:
"<<a.acno<<endl;
cout<<"Current balance:
"<<a.balance<<endl;
}
//function for opening a new bank account
void openAccount(){
string name;
int balance, acno;
acno = numAccounts;
cout<<"Enter Account Name: ";
cin>>name;
cout<<"Enter opening balance: ";
cin>>balance;
//Adds the account to allAccounts Array
allAccounts[numAccounts].name = name;
allAccounts[numAccounts].acno = numAccounts;
allAccounts[numAccounts].balance = balance;
//updates the account in accounts.txt
ofstream accountInfoFile;
accountInfoFile.open("account.txt");
accountInfoFile<<"Account Name:
"<<name<<" "<<" Opening balance
"<<balance<<" Account num:
"<<numAccounts<<"\n";
accountInfoFile.close();
//prints the transactions corresponding to the opening
balance
printTransaction(acno, balance);
cout<<"Successfully created account:
"<<endl;
printAccountDetails(allAccounts[numAccounts]);
numAccounts++;
}
//function to deposit a given amount into an account
void depositMoney(int accountIndex, Account* allAccounts, int
dep){
//adding the money to the account
allAccounts[accountIndex].balance += dep;
//printing the transaction
printTransaction(accountIndex, dep);
}
//function to withdraw a given amount from an account
void withdrawMoney(int accountIndex, Account* allAccounts, int
with){
//If the withdrawn amount is greater than the current
balance throw error
if (allAccounts[accountIndex].balance <
with){
cout<<"Insufficient
Balance!!!!!\n";
}
else {
allAccounts[accountIndex].balance
-= with;
printTransaction(accountIndex,
-with);
}
}
int main(){
int choice;
do {
//Sample menu for performing the
specified operations
cout<<"******************************\nMENU\n";
cout<<"Press 1 to open an
account\n";
cout<<"Press 2 to make a
deposit in an account\n";
cout<<"Press 3 to withdraw
from an account\n";
cout<<"Press 4 to
exit\n";
cout<<"******************************\n";
cin>>choice;
int ac, dep;
switch(choice){
case 1:
openAccount();
break;
case 2:
cout<<"Enter account num to deposit money: ";
cin>>ac;
cout<<"Enter the amount
to be deposited: ";
cin>>dep;
depositMoney(ac, allAccounts,
dep);
break;
case 3:
cout<<"Enter account num to withdraw money: ";
cin>>ac;
cout<<"Enter the amount
to be withdrawn: ";
cin>>dep;
withdrawMoney(ac,
allAccounts, dep);
break;
case 4:
break;
default:
cout<<"Invalid Choice!!!!\nTry Again\n";
break;
}
}
while(choice != 4);
return 0;
}
Working on a C++ banking program, need assistance in formulating following functions: -function depositMoney, which receives...
write a code on .C file
Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...
C++ Read and do as instructed on please
(C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...
(C++) Write a program that declares a struct to store the data of a football player (player’s name, player’s position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards). Declare an array of 10 components to store the data of 10 football players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of...
Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...
Java coding help!
Write a program to simulate a bank which includes the following. Include a commented header section at the top of each class file which includes your name, and a brief description of the class and program. Create the following classes: Bank Customer Account At a minimum include the following data fields for each class: o Bank Routing number Customer First name Last name Account Account number Balance Minimum balance Overdraft fee At a minimum write the following...
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
Modify your program from Assignment # 7 part b (see below for code) by creating an interactive GUI application that displays the list of the orders read in from the file (create a data file using your CreateBankFile.java program which has a least 10 bank account records in it and include it with your submission) and the total number of bank accounts. When your program starts it will first read the records from the Bank Account file (AccountRecords.txt) and creates...
Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...
Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...
Banking System is developed in C++ to replaced manual System by a computerized system. This system allows to create a new account and Allows to deposit and withdrawal amount facilities. Account Holder ABS must record the detailed information of each account holder, such as Type of his account (see next slides for more info) Type of Credit card (see later slides for more info) First name, middle name, and last name CNIC number Address Telephone number Date of...