This is a C++ programm , need help . Output EXAMPLE: Design a bank account class
ID: 3835348 • Letter: T
Question
This is a C++ programm , need help .
Output EXAMPLE:
Design a bank account class named Account that has the following private member variables: accountNumber of type int owner Name of type string balance of type double and the following public member functions: Account constructor with no arguments, that creates a bank account with a default account Number as 9999, a name of an empty string, and balance value of zero. An Account object is dynamically allocated Account (number name, bal) constructor with three parameters, that creates a bank account with a specified accountNumber, name and balance. An Account object is dynamically allocated function to withdraw a specified amount from the account. The function withdraw (amount) should first check if there is sufficient balance in the account. If the balance is sufficient, withdrawal is processed. Otherwise the withdrawal is not made. deposit (amount) function to deposit a specified amount of money to the account. The function should first check if the deposit amount is positive. If it is positive, deposit is processed. Otherwise the deposit is not made. getAccountNumber An accessor function that returns the account number. This function is later called by the displayAccount Info function getName An accessor function that returns the name on the account getBalance An accessor function that returns the account balance. This function is later called by the displayAccount Info function Demonstrate the class in a program.Explanation / Answer
Account.h
Account.cpp
main.h
int main(){
//Max Number of Back Accounts
const int MAX_NUM = 5;
//Bank Account array
Account*account[MAX_NUM];
//amount of accounts
int aAccounts = 0;
//set the amount of accounts to how much is read in from the file
aAccounts = read_accts(account, MAX_NUM);
//print out account information
Prinallacctsinfo(account, aAccounts);
//show start menu
startMenu();
//start program
BeginPrompt(account, MAX_NUM, aAccounts);
return 0;
}
//Main Menu Functions -------------------------------------------------------------------------------------------------
void startMenu(){
//Welcome Screen
cout << endl << "Welcome User!" << endl;
}
void BeginPrompt(BankAccount account[], int max_accounts, int num_accounts){
//Allow user to choose which transaction to make
string choice;
cout << endl <<"Type 'W' - Widthdrawl" << endl;
cout << "Type 'D' - Deposit" << endl;
cout << "Type 'N' - New Account" << endl;
cout << "Type 'B' - Balance" << endl;
cout << "Type 'I' - Account Info" << endl;
cout << "Type 'Q' - Quit" << endl;
cin >> choice;
if(choice == "W"){
withdrawl(account, num_accounts);
//Restart Transaction Prompt
BeginPrompt(account, max_accounts, num_accounts);
}else if(choice == "D"){
deposit(account, num_accounts);
//Restart Transaction Prompt
BeginPrompt(account, max_accounts, num_accounts);
}else if(choice == "N"){
num_accounts = newAccount(account, max_accounts, num_accounts);
print_accts(account, num_accounts);
//Restart Transaction Prompt
BeginPrompt(account, max_accounts, num_accounts);
}else if(choice == "B"){
balance(account, num_accounts);
//Restart Transaction Prompt
BeginPrompt(account, max_accounts, num_accounts);
}else if(choice == "I"){
accountInfo(account, num_accounts);
//Restart Transaction Prompt
BeginPrompt(account, max_accounts, num_accounts);
}else if(choice == "Q"){
quit();
}else{
cout << endl << choice << " is not a valid choice." << endl;
//Restart Transaction Prompt
BeginPrompt(account, max_accounts, num_accounts);
}
}
int accountNumPrompt(){
int accountnumber = 0;
cout << endl << "Please enter the account number" << endl;
cin >> accountnumber;
return accountnumber;
}
//This function is to allow for a standard way of showing there was an error.
void error(string msg){
//More noticible for users to see the Error message.
cout << endl << "---------------------------" << endl;
cout << endl << "ERROR: " << msg << endl;
cout << endl << "---------------------------" << endl;
}
//Account Functions --------------------------------------------------------------------------------------------------------
int read_accts(BankAccount account[], int max_accounts){
//start counter
int count = 0;
//temporary variables
string fname, lname, type;
int SSN;
double acctbalance;
//count how moany entries are in the file.
while(!File.eof() && count < max_accounts){
File >> name >> type >> acctbalance;
count++;
}
//loop back to top of file.
File.clear();
File.seekg(0, ios::beg);
//counter for our current account
int i = 0;
//create pointer for changing the values at the direct address in memory
BankAccount * b;
//loop trhough file and save and set values
while(!File.eof() && i < count){
//set our current account into our pointer variable
b = &account[i];
//define our file format
File >>name >> >> acctbalance;
//set all of our values
b->setaccountnumber(i);
b->setownerame(fname);
b->setbalance(acctbalance);
i++;
}
return count;
}
void info(BankAccount account[], int num_accts){
//create pointer variable
BankAccount * b;
for(int i=0; i<num_accts; i++){
//stores our current account
b = &account[i];
cout << "name: " << b->getownerame() << " " << endl;
cout << " Account Number: " << b->getAccountNumber() << endl;
cout << " Account Balance: " << b->getAccountBalance() << endl;
}
}
void withdrawl(BankAccount account[], int num_accts){
int accountnum = 0;
//prompt the user for an account number
accountnum = accountNumPrompt();
//validate that account number
accountnum = find_acct(account, num_accts, accountnum);
if(accountnum == -1){
//give error if its not found
string message = "We couldn't find an account by that number";
error(message);
withdrawl(account, num_accts);
}else{
//keep asking until you get a valid amount
BankAccount * b = &account[accountnum];
while(true){
double howmuch = 0.00;
cout << endl << "How much do you want to withdraw?" << endl;
cin >> howmuch;
if(b->withdraw(howmuch)){
cout << endl << howmuch << " has been withdrawn from account: " << b->getAccountNumber() << endl;
break;
}else{
cout << "Acount " << b->getAccountNumber() << " does not have sufficient funds." << endl;
}
}
}
}
void deposit(BankAccount account[], int num_accts){
int accountnum = 0;
accountnum = accountNumPrompt();
accountnum = find_acct(account, num_accts, accountnum);
if(accountnum == -1){
string message = "We couldn't find an account by that number";
error(message);
deposit(account, num_accts);
}else{
BankAccount * b = &account[accountnum];
double howmuch = 0.00;
cout << endl << "How much do you want to deposit?" << endl;
cin >> howmuch;
b->addAccountBalance(howmuch);
cout << endl << howmuch << " has been deposited int account: " << b->getAccountNumber() << endl;
}
}
int newAccount(BankAccount account[], int max_accounts, int num_accts){
BankAccount * b;
//make sure there is space left
if(num_accts+1 <= max_accounts){
b = &account[num_accts];
string fname, lname, type;
int SSN;
double acctbalance;
cout << endl << "Please enter name: ";
cin >> name;
cout << endl << "Please enter last name: ";
cin >> lname;
cout << endl << "Please enter Account starting Balance: ";
cin >> acctbalance;
b->setname(name);
);
//increment the account number
int greatest = 0;
BankAccount * g;
for(int i=0; i < num_accts; i++){
g = &account[i];
if(g->getAccountNumber() > greatest){
greatest = g->getAccountNumber();
}
}
greatest++;
b->setAccountNumber(greatest);
b->setAccountType(type);
b->setAccountBalance(acctbalance);
num_accts++;
return num_accts;
}
}
void balance(BankAccount account[], int num_accts){
int accountnum = 0;
accountnum = accountNumPrompt();
accountnum = find_acct(account, num_accts, accountnum);
if(accountnum == -1){
string message = "We couldn't find an account by that number";
error(message);
balance(account, num_accts);
}else{
double howmuch = 0.00;
cout << endl << "Here is your balance: $" << account[accountnum].getAccountBalance() << endl;
}
}
voiddisplayAccountInfo(BankAccount account[], int num_accts){
int accountnum = 0;
accountnum = accountNumPrompt();
accountnum = find_acct(account, num_accts, accountnum);
if(accountnum == -1){
string message = "We couldn't find an account by that number";
error(message);
accountInfo(account, num_accts);
}else{
cout << endl << "Here is your Account Info." << endl << endl;
cout << "name: " << account[accountnum].getownername() << " " << astName() << endl ;
cout << " Account Number: " << account[accountnum].getAccountNumber() << endl;
cout << " Account Balance: " << account[accountnum].getAccountBalance() << endl;
}
}
void quit(){
cout << endl << "Program is now ending!" << endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.