So a little info about what is going on, below is the problem I am writing the code for.
The exercise for this week is to write a class that simulates managing a simple bank account. The account is created with an initial balance. It is possible to deposit and withdraw funds, to add interest, and to find out the current balance. This should be implemented in class named Account that includes:
A default constructor that sets the initial balance to zero.
A constructor that accepts the initial balance as a parameter.
A function getBalance that returns the current balance.
A method deposit for depositing a specified amount.
A method withdraw for withdrawing a specified amount.
A method addInterest for adding interest to the account.
This is the following code I have so far.
Account.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef ACCOUNT_H
#define ACCOUNT_H
class Account
{
private:
double balance = 0;
public:
Account();
Account(double startingBal);/// you forgot to define this one
double getBalance() const;
void deposit(double amount);
void withdraw(double amount);
void addInterest(double interestRate);
};
#endif //ACCOUNT_H
|
Account.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include "Account.h" //Account class Implementation
using namespace std;
Account::Account() : balance(0)
{
}
Account::Account(double startingBal) : balance(startingBal) {}
Account Account::getBalance() const
{
return balance;
}
void Account::deposit(double amount)
{
balance += amount;
}
void Account::withdraw(double amount)
{
balance -= amount;
}
void Account::addInterest(double interestRate)
{
balance = balance*(1 + interestRate);
}
|
and Lab7.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include<iostream>
using namespace std;
#include "Account.h"
int main()
{
Account a1;
Account a2(500);
a1.deposit(200);
a2.withdraw(50);
a1.addInterest(0.2);
cout << a1.getBalance();
cout << "\n";
cout << a2.getBalance();
system("pause");
return 0;
}
|
The error I am getting are
Error C2371: 'Account::getBalance' : redefinition; different basic types
Error C2556: 'Account Account::getBalance(void) const': overloaded function differs only by return type from 'double Account::getBalance(void) const;
IntelliSense: declariation is incompatible with "double Account::getBalance()const" declared at like 12 of Account.h