coders! I have been accomplishing my c++ homework, but got stuck with relating a method to a class called BankAccount. Main idea is to create a class called BankAccount with its own methods like deposit() or addInterest() with functions that match their name and constructors. I have declared all of my methods and wrote their code, however when it came to the methods called "void BankAccount::addInterest()" and "void BankAccout::deposit()" I get error messages like "incompitable". I will share my code here:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class BankAccount
{
public:
double getBalance();
void deposit(double);
void witdraw(double);
void addInterest();
BankAccount();
BankAccount(double, double, int, string);
double displayAccountSummary();
private:
double interestRate;
int accountNumber;
double deposit;
double accountWithdraw;
double balance;
string ownerName;
};
int main()
{
BankAccount myAccount(1000.50, 0.05, 1111, "John Williamas");
myAccount.deposit(500);
myAccount.witdraw(200);
myAccount.addInterest();
myAccount.displayAccountSummary();
return 0;
}
void BankAccount::deposit(double depozit)
{
balance = depozit + balance;
}
void BankAccount::addInterest(double rate)
{
balance = balance * (1 + rate);
}
BankAccount::BankAccount()
{
balance = 0;
interestRate = 0;
accountNumber = 0;
ownerName = "";
}
BankAccount::BankAccount(double money, double rate, int accountnumber, string name)
{
balance = money;
interestRate = rate;
accountNumber=accountnumber;
ownerName = name;
}
double BankAccount::getBalance()
{
return balance;
}
void BankAccount::witdraw(double wizdraw)
{
if (wizdraw < 0||wizdraw>balance)
{
cout << "Witdraw amount can not be less than 0 or greater than balance. Try again\n ";
cin >> wizdraw;
}
balance = balance - wizdraw;
}
double BankAccount::displayAccountSummary()
{
return balance;
return interestRate;
return accountNumber;
cout<< ownerName;
}