Question #52687

1. Define the class bankAccount to store a bank customer’s account number (int) and balance (double).
2. Your class should, at least, provide the following operations:
a. set the account number,
b. retrieve the account number,
c. retrieve the balance,
d. deposit money,
e. withdraw money,
f. print account information
3. Add a constructor with default parameters.

Expert's answer

Answer on Question #52687 – Programming – C++

1. Define the class bankAccount to store a bank customer’s account number (int) and balance (double).

2. Your class should, at least, provide the following operations:

a. set the account number,

b. retrieve the account number,

c. retrieve the balance,

d. deposit money,

e. withdraw money,

f. print account information

3. Add a constructor with default parameters.

Answer:


#include <iostream>//Using for PrintAccountInformation
class BankAccount
{
//1. Define the class bankAccount to store a bank customer’s account number(int) and balance(double).
int account_number;
double balance;
public:
//3. Add a constructor with default parameters.
BankAccount(int account_number=0, double balance = 0.0)
{
this->account_number=account_number;
this->balance = balance;
}
//if you want create array of BankAccount or something else
BankAccount(const BankAccount* obj)
{
this->account_number = obj->account_number;
this->balance = obj->account_number;
}
//a. set the account number,
void SetAccountNumber(int account_number)
{
this->account_number = account_number;
}
//d. deposit money,
void Deposit(double money)
{
this->balance += money;
}
//e. withdraw money,
double Withdraw(double money)
{
if (this->balance >= money) {
this->balance -= money;
return money;
}
else {
return 0.0;
std::cout << "not enough money on account";
}
}
//b. retrieve the account number,
int RetrieveAccountNumber(void) const
{
return this->account_number;
}
//c. retrieve the balance,
double RetrieveBalance(void) const
{
return this->balance;
}
//f. print account information
void PrintAccountInformation(void) const
{
std::cout << "AccountNumber: "<< this->account_number;
std::cout << "Balance: " << this->balance<<std::endl;
}
}


https://www.AssignmentExpert.com

LATEST TUTORIALS
APPROVED BY CLIENTS