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

Create a class Account that represents a Bank account. Your Account class should

ID: 3568217 • Letter: C

Question

Create a class Account that represents a Bank account. Your Account class should have: - Three data members : name the name of the owner acct_no the acct number balance the current balance - A constructor that takes a String and a double and initializes name and balance with these. The constructor also increments a global variable called last_account (initialized globally to 0), and assigns acct_no the current value of last_account (so f.e. the first acct number created gets an acct no = 1, the second = 2, third = 3 etc. etc.) - The class Account should also have the following member functions: void deposit (double amount) that adds amount to the balance void withdrawal (double amount) that subtracts amount from the balance double get_balance ( ) that returns the current balance int get_number() that returns the account number void display() that prints the info about an account Next, create another class called Bank that represents a bank and in which we will keep a number of accounts in a vector of pointers to Accounts vector theAccts; // a vector of ptrs to the different Accounts - A constructor that clears the vector - Member functions: void add_acct (Account* x) // adds account x to the bank double total_balance ( ) // returns the sum of all balances of all accounts in the Bank void add_interest (double percent ) // adds an interest to each and every account void print_customers( ) // prints, for each account, the name, acctNo and balance.

int main (){

Account* a = new Account ("Jack", 50);

a->deposit(100);

Account* b = new Account ("Jill", 100);

b->withdraw(20);

Bank* CIBC = new Bank;

CIBC->add_acct(a);

CIBC->add_acct(b);

cout << "Total Balance for CIBC : " << CIBC->total_balance()<< endl;

CIBC->add_interest(5);

cout << "Total CIBC Balance after interest : " << CIBC->total_balance()<<endl;

CIBC->print_customers();

}

Explanation / Answer

#include <iostream>
#include<string>
#include<vector>
using namespace std;

int last_account = 0;

class Account
{
private:
  
string name;
int acct_no;
double balance;
  
public:
  
Account(string n, double b)
{
name = n;
balance = b;
acct_no = ++last_account;
}
  
void deposit(double amount)
{
balance += amount;
}
  
void withdraw(double amount)
{
balance -= amount;
}
  
double get_balance( )
{
return balance;
}
int get_number()
{
return acct_no;
}
void display()
{
  
cout<<" Account No.: "<<acct_no<<" ";
cout<<"Name: "<<name<<" ";
cout<<"Balance: "<<balance<<" ";
}
  
};

class Bank
{
vector <Account> theAccts;

public:
Bank()
{
theAccts.clear();
}

void add_acct (Account* x)
{
theAccts.push_back(*x);
}
double total_balance ( )
{
double sum=0.0;
for (int i=0; i<theAccts.size(); i++)
sum += theAccts[i].get_balance();
  
return sum;
}

void add_interest (double percent )
{
for (int i=0; i<theAccts.size(); i++)
theAccts[i].deposit((theAccts[i].get_balance()*percent)/100.0);
}

void print_customers( )
{
for (int i=0; i<theAccts.size(); i++)
theAccts[i].display();
}
  
};

int main (){

Account* a = new Account ("Jack", 50);

a->deposit(100);

Account* b = new Account ("Jill", 100);

b->withdraw(20);

Bank* CIBC = new Bank;

CIBC->add_acct(a);

CIBC->add_acct(b);

cout << "Total Balance for CIBC : " << CIBC->total_balance()<< endl;

CIBC->add_interest(5);

cout << "Total CIBC Balance after interest : " << CIBC->total_balance()<<endl;

CIBC->print_customers();

}

-----------------------------------

output

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote