C12-Class BankAccount

Hello everyone. I'm confused on how to create an interest rate and a saving/checking account into the code. Help will be greatly appreciated!

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


class BankAccount
{
private:
int accountnumber;
string name;
double balance;
string checkingaccount;
string savingaccount;

static int totalaccounts;
static double bankbalance;


public:
BankAccount();

BankAccount(string, int, double);

~BankAccount();

string getname() const;
double getBalance() const;
int getaccountnumber() const;
double getinterestrate() const;

void setinterestrate(double rate);
void setname(string);
void setaccountnumber(int);
void setBalance(double);
void withdraw(double);
void deposit(double);
void rate(double);

static void printBankAccountinfo();
};

string BankAccount::getinterestrate() const
{
return rate;
}

string BankAccount::getname() const
{
return name;
}

double BankAccount::getBalance() const
{
return balance;
}

int BankAccount::getaccountnumber() const
{
return accountnumber;
}

BankAccount::BankAccount()
{
accountnumber = 0;
balance = 0.0;
totalaccounts++;
}

BankAccount::BankAccount(string newName, int newAccountNumber, double newBalance)
{
name = newName;
accountnumber = newAccountNumber;
totalaccounts++;
balance = newBalance;
bankbalance += newBalance;
}

int BankAccount::totalaccounts = 0;
double BankAccount::bankbalance = 10000;

BankAccount::~BankAccount()
{
totalaccounts--;
bankbalance -= balance;
}


void BankAccount::setname(string newName)
{
name = newName;
}

void BankAccount::setaccountnumber(int newAccountNumber)
{
accountnumber = newAccountNumber;
}

void BankAccount::setBalance(double newBalance)
{
bankbalance -= balance;
balance = newBalance;
bankbalance += balance;
}

void BankAccount::withdraw(double withdraw)
{
balance -= withdraw;
bankbalance -= withdraw;
}

void BankAccount::deposit(double deposit)
{
balance += deposit;
bankbalance += deposit;
}


void BankAccount::printBankAccountinfo()
{
cout << "Number of Accounts: " << totalaccounts << endl;
cout << "Total Balance: " << bankbalance << endl;
}

int main ()
{
BankAccount::printBankAccountinfo();


system("pause");
}
Last edited on
It's not clear what you mean by "I'm confused on how to create ... a saving/checking account into the code."

But looking at your code, your BankAccount object has members:
1
2
string checkingaccount;
string savingaccount;


Further more, you appear to have:
1
2
static int totalaccounts;
static double bankbalance;
It's not clear what they mean.

Typically, a Checking Account is distinct from a Savings Account. I think you're expected to use Inheritance to implement these, as they can be thought of as specializations of a generic bank account. And your task as a designer is to define a generic bank account and the specialised savings and checking accounts.

You code looks very Java-esq, where everything is an object. But clearly, something like calculateInterest is a procedure, not an object, right?
Topic archived. No new replies allowed.