Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write a c++ program that meet all the requirements in the instructions an

ID: 3732675 • Letter: P

Question

Please write a c++ program that meet all the requirements in the 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 assignment

Explanation / Answer

Please find the code below with detailed inline comments.

Account.h

***********************

using namespace std;

struct Date {
int month, day, year;
};

struct Person {
string name, address;
Date DOB;
};

class Account {
private:
int accountNumber;
int numOwners;
Person* ownerPtr;
double balance;
static int accountCounter;

public:
Account(int numberOwners, 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();
};

Account.cpp

***********************

#include <iostream>
#include "Account.h"

using namespace std;

int Account::accountCounter = 1000;
Account::Account(int numberOwners, double amount){
numOwners = numberOwners;
balance = amount;
accountNumber = accountCounter++;
ownerPtr = new Person[numOwners];
}

bool Account::withdraw(double amount) {
if(amount > balance) {
cout << "Your account has insufficient balance...." << endl;
return false;
}
balance -= amount;
return true;
}

bool Account::deposit(double amount) {
if(amount <= 0) {
cout << "The deposit amount must be greater than 0..." << endl;
return false;
}
balance += amount;
return true;
}

void Account::setOwner(int ind, Person p) {
ownerPtr[ind] = p;
}

Person Account::getOwner(int ind) {
return ownerPtr[ind];
}

int Account::getAccountNumber() {
return accountNumber;
}

double Account::getBalance() {
return balance;
}

int Account::getNumOwners() {
return numOwners;
}

Main.cpp

***********************

#include <iostream>
#include "Account.cpp"
#define MAX_NUM_ACCOUNTS 4

using namespace std;

Account* accountArray[MAX_NUM_ACCOUNTS];

void displayAccountInfo(Account* acc) {
cout << "Account number: " << acc->getAccountNumber();
cout << " List of owners: " << endl;
for(int i=0; i<acc->getNumOwners(); i++){
cout << "Name : " << acc->getOwner(i).name << endl;
cout << "DOB: " << acc->getOwner(i).DOB.day << "/" << acc->getOwner(i).DOB.month << "/" << acc->getOwner(i).DOB.year << endl;
cout << "Address: "<< acc->getOwner(i).address << endl;
cout << endl;
}

cout << "Balance: " << acc->getBalance();
cout << endl << endl;
}
int main() {

for(int i = 0; i < MAX_NUM_ACCOUNTS; i ++) {
accountArray[i] = nullptr;
}

int numberOwners;
double amount;
string ownerName;
int d, m, y;
string address;
int num = 0;

while(1) {
cout << "Menu -------" << endl;
cout << "1->Create Account 2->Deposit 3->Withdraw 4->Display 5->Quit" << endl;
int choice;
cin >> choice;
switch(choice) {
case 1:{

if(num == MAX_NUM_ACCOUNTS) {
cout << "Maximum number of accouts reached...." << endl;
break;
}
cout << "Enter number of owners: ";
cin >> numberOwners;
cout << "Enter amount: ";
cin >> amount;
Account acc(numberOwners, amount);
for(int i=0; i<numberOwners; i++) {
cout << "Enter owner's name: ";
cin >> ownerName;
cout << "Enter owner's DOB (month, day, year): ";
cin >> m >> d >> y;
cout << "Enter Owners's address: ";
cin >> address;
Date date;
date.month = m;
date.day = d;
date.year = y;
Person p;
p.name = ownerName;
p.address = address;
p.DOB = date;
acc.setOwner(i, p);
}
cout << "Account #" << acc.getAccountNumber() << " created." << endl;
accountArray[num ++] = &acc;
break;
}
case 2: {
int accno;
cout << "Enter the account number: ";
cin >> accno;
int accFound = 0;
for(int i=0; i < MAX_NUM_ACCOUNTS; i++) {
if(accountArray[i]->getAccountNumber() == accno) {
accFound = 1;
Account* a = accountArray[i];
cout << "Enter amount : ";
cin >> amount;
bool deposited = a->deposit(amount);
if(deposited == true){
cout << "New balance is " << a->getBalance() << endl;
} else {
cout << "Deposit failed..." << endl;
}
break;
}
}
if(accFound == 0)
cout << "No such account" << endl;
break;
}
case 3:
{

int accno;
cout << "Enter the account number: ";
cin >> accno;
int accFound = 0;
for(int i=0; i < MAX_NUM_ACCOUNTS; i++) {
if(accountArray[i]->getAccountNumber() == accno) {
accFound = 1;
Account* a = accountArray[i];
cout << "Enter amount : ";
cin >> amount;
bool deposited = a->withdraw(amount);
if(deposited == true){
cout << "New balance is " << a->getBalance() << endl;
} else {
cout << "Withdraw failed..." << endl;
}
break;
}
}
if(accFound == 0)
cout << "No such account" << endl;
break;
}
case 4:
{
for(int i=0; i<MAX_NUM_ACCOUNTS; i++) {
displayAccountInfo(accountArray[i]);
}
break;
}
case 5:{
cout << "Exiting...";
return 0;

}
default:{
cout << "Not a valid option ";
break;
}
}
}
}