Please write the c++ program that meets all the requirements in the below instru
ID: 3734194 • Letter: P
Question
Please write the c++ program that meets all the requirements in the below instructions and get the same outputs as are in the screenshot. THANKS!!!
HW7 (Graded out of 100) Design a bank account class named Account that has the following private member variables: accountNumber of type int numOwners of type int // number of account co-owners (account can have more than one owner) ownerPtr of type Person //, ownerPtr points to an array of Person, where Person is a structure. The Person structure is defined below accountCounter of type static int // initialized at 1000, incremented at each account creation, used to automate account number assignmentExplanation / Answer
// File Name: Accounts.h
#include<string>
using namespace std;
// structure definition for Date
struct Date
{
// To store month, date, year
int month;
int day;
int year;
};// End of structure
// structure definition for Person
struct Person
{
// To store name, date of birth and address
string name;
Date DOB;
string address;
};// End of structure
// Class Accounts definition
class Accounts
{
// Data member to store account number, number of owners of the account, balance
// and Person information such as name, address and date of birth
int accountNumber;
int numOwners;
Person *ownerPtr;
double balance;
// Static counter for number of accounts
static int accountCounter;
public:
// Prototype of member functions
Accounts(int numOwners, double amount);
bool withdraw(double amount);
bool deposit(double amount);
void setOwner(int ind, Person p);
Person getOwner(int ind);
int getAccountNumber();
double getBalance();
int getNumOwners();
};// End of class
// Initializes static data member
int Accounts::accountCounter = 1000;
------------------------------------------------------------------------------------
// File Name: Accounts.cpp
#include "Accounts.h"
#include<iostream>
using namespace std;
// Parameterized constructor definition
Accounts::Accounts(int numOwners, double amount)
{
// Creates account number and increase the account counter by one
accountNumber = accountCounter++;
// Creates number of persons dynamically based on number of owners value
ownerPtr = new Person[numOwners];
// Assigns number of owners and balance to data member
this->numOwners = numOwners;
this->balance = amount;
}// End of parameterized constructor
// Function to withdraw amount
// Returns true if the amount is less than the balance, otherwise false
bool Accounts::withdraw(double amount)
{
// Checks if the balance is greater than the amount
if(balance >= amount)
{
// Update the balance by subtracts the amount from the balance
balance -= amount;
// Returns true
return true;
}// End of if condition
// Otherwise, amount is greater than the balance
else
{
// Display error message
cout<<" Insufficient Balance.";
// Returns false
return false;
}// End of else
}// End of function
// Function to deposit amount
// Returns true if the amount is not negative, otherwise false
bool Accounts::deposit(double amount)
{
// Checks if the amount is positive
if(amount > 0)
{
// Update the balance by adding amount to it
balance += amount;
// Returns true
return true;
}// End of if condition
// Otherwise, amount is negative
else
{
// Display error message
cout<<" Deposit amount cannot be zero or negative.";
// Returns false
return false;
}
}// End of function
// Function to set the owner of account information
void Accounts::setOwner(int ind, Person p)
{
// Assigns person object to the specified index position ind of ownerPtr array
ownerPtr[ind] = p;
}// End of function
// Function to return the person object based on the index position
Person Accounts::getOwner(int ind)
{
// Returns the Person object of ownerPtr ind index position
return ownerPtr[ind];
}// End of function
// Function to return the account number
int Accounts::getAccountNumber()
{
return accountNumber;
}// End of function
// Function to return the balance
double Accounts::getBalance()
{
return balance;
}// End of function
// Function to return number of owners
int Accounts::getNumOwners()
{
return numOwners;
}// End of function
---------------------------------------------------------------------------------------
// File Name: mainAccounts.cpp
#include"Accounts.cpp"
#include <stdlib.h>
#include<iostream>
#include<string>
#define MAX_NUM_ACCOUNTS 4
using namespace std;
// Function to display menu, accept user choice and return the choice value
int menu()
{
// To store choice entered by the user
int choice;
// Displays the menu
cout<<" Menu ";
cout<<"---------";
cout<<" 1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit ";
// Accepts user choice
cin>>choice;
// Returns user choice
return choice;
}// End of function
// Function to accept data for person and date of birth
void accept(double &amt, struct Person &p, struct Date &d)
{
cout<<" Enter owner's name: ";
cin>>p.name;
cout<<" Enter owner's DOB. month, day then year: ";
cin>>p.DOB.month>>p.DOB.day>>p.DOB.year;
cout<<" Enter owner's address: ";
cin>>p.address;
}// End of function
// Function to display account information
void displayAccountsInfo(Accounts *ac)
{
// Displays account number
cout<<" Account Number: "<<ac->getAccountNumber();
cout<<" -------------------------------------------";
// Loops till number of owners
for(int c = 0; c < ac->getNumOwners(); c++)
{
// Displays persons and date of birth information
cout<<" Name: "<<ac->getOwner(c).name;
cout<<" DOB: "<<ac->getOwner(c).DOB.month<<"/"<<ac->getOwner(c).DOB.day<<"/"<<ac->getOwner(c).DOB.year;
cout<<" Address: "<<ac->getOwner(c).address<<endl;
}// End of for loop
// Displays balance
cout<<" Balance: $"<<ac->getBalance();
}// End of function
// Function to search an account if found returns index position otherwise returns -1
int findAccount(Accounts *ac[], int accno, int no)
{
// Initially index position is -1 for not found
int index = -1;
// Loops till number of accounts
for(int d = 0; d < no; d++)
{
// Checks current account account number with the parameter account number
if(ac[d]->getAccountNumber() == accno)
{
// Set the current loop value as the found index position
index = d;
// Come out of the loop
break;
}// End of if condition
}// End of for loop
// Returns the index position
return index;
}// End of function
// main function definition
int main()
{
// To store number of owners, account number, found index position of account
int no, accNo, pos;
// To store the amount entered by the user
double amt;
// Declares person object
struct Person per;
// Declares Date object for date of birth
struct Date dat;
// Creates an array of pointers for MAX_NUM_ACCOUNTS value
Accounts * accountArray[MAX_NUM_ACCOUNTS];
// Loops till MAX_NUM_ACCOUNTS value
for(int c = 0; c < MAX_NUM_ACCOUNTS; c++)
// Initializes each to null
accountArray[c] = NULL;
// Initializes current account counter to zero
int counter = 0;
// Loops till user choice is not five
do
{
// Calls the function to receive user choice and calls appropriate function based on user choice
switch(menu())
{
case 1:
// Accepts number of owners for the account
cout<<" Enter number of owners: ";
cin>>no;
// Accounts the initial balance
cout<<" Enter amount: ";
cin>>amt;
// Creates an account using parameterized constructor and assigns it to array of account's counter index position
accountArray[counter] = new Accounts(no, amt);
// Loops till number of owners
for(int d = 0; d < no; d++)
{
// Accept data for each owner person
accept(amt, per, dat);
// Sets each owner data i.e., owner index position and owner information
accountArray[counter]->setOwner(d, per);
}// End of for loop
// Display the account number for the account
cout<<" Account #"<<accountArray[counter]->getAccountNumber()<<" created.";
// Increase the current account counter by one
counter++;
break;
case 2:
// Accepts a account number
cout<<" Enter the account number for deposit: ";
cin>>accNo;
// Calls the function to check whether the account is available or not
pos = findAccount(accountArray, accNo, counter);
// Checks if the position is -1 the account number not found
if(pos == -1)
cout<<" No such account found.";
// Otherwise, account found
else
{
// Accept the deposit amount
cout<<" Enter deposit amount: ";
cin>>amt;
// Calls the function to update the balance
accountArray[pos]->deposit(amt);
// Displays the current balance
cout<<" New balance is $"<<accountArray[pos]->getBalance();
}// End of else
break;
case 3:
// Accepts a account number
cout<<" Enter the account number for withdraw: ";
cin>>accNo;
// Calls the function to check whether the account is available or not
pos = findAccount(accountArray, accNo, counter);
// Checks if the position is -1 the account number not found
if(pos == -1)
cout<<" No such account found.";
// Otherwise, account found
else
{
// Accept the withdraw amount
cout<<" Enter withdraw amount: ";
cin>>amt;
// Calls the function to update the balance
accountArray[pos]->withdraw(amt);
// Displays the current balance
cout<<" New balance is $"<<accountArray[pos]->getBalance();
}// End of else
break;
case 4:
// Loops till number of accounts
for(int d = 0; d < counter; d++)
// Displays each account information
displayAccountsInfo(accountArray[d]);
break;
case 5:
exit(0);
default:
cout<<" Invalid option!";
}// End of switch case
}while(1); // End of do - while loop
return 0;
}// End of main function
Sample Output:
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
1
Enter number of owners: 1
Enter amount: 1000
Enter owner's name: Pyari
Enter owner's DOB. month, day then year: 21
2
1998
Enter owner's address: Berhampur
Account #1000 created.
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
1
Enter number of owners: 2
Enter amount: 2000
Enter owner's name: Sasmita
Enter owner's DOB. month, day then year: 12
2
1994
Enter owner's address: BBSR
Enter owner's name: Rasmita
Enter owner's DOB. month, day then year: 10
4
1995
Enter owner's address: BBSR
Account #1001 created.
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
4
Account Number: 1000
-------------------------------------------
Name: Pyari
DOB: 21/2/1998
Address: Berhampur
Balance: $1000
Account Number: 1001
-------------------------------------------
Name: Sasmita
DOB: 12/2/1994
Address: BBSR
Name: Rasmita
DOB: 10/4/1995
Address: BBSR
Balance: $2000
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
2
Enter the account number for deposit: 111
No such account found.
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
2
Enter the account number for deposit: 1000
Enter deposit amount: 100
New balance is $1100
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
2
Enter the account number for deposit: 1000
Enter deposit amount: -10
Deposit amount cannot be zero or negative.
New balance is $1100
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
3
Enter the account number for withdraw: 1001
Enter withdraw amount: 5000
Insufficient Balance.
New balance is $2000
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
3
Enter the account number for withdraw: 1001
Enter withdraw amount: 200
New balance is $1800
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
4
Account Number: 1000
-------------------------------------------
Name: Pyari
DOB: 21/2/1998
Address: Berhampur
Balance: $1100
Account Number: 1001
-------------------------------------------
Name: Sasmita
DOB: 12/2/1994
Address: BBSR
Name: Rasmita
DOB: 10/4/1995
Address: BBSR
Balance: $1800
Menu
---------
1 -> Create Account 2 -> Deposit 3 -> Withdraw 4 -> Display 5 -> Quit
5