I am trying to do another exercise from Deitel’s book. The program calculates monthly interest and prints new balances for each of the contributors. Since the exercise is part of the chapter related to dynamic memory, I use the “new” and “delete” operators. For some reason, I get these two errors:
LNK2019: Unresolved WinMain @ 16 external character specified in ___ tmainCRTStartup function
fatal error LNK1120: 1 unresolved external
Here is the class header file.
class SavingsAccount
{
public:
static double annualInterestRate;
SavingsAccount(double amount=0);
double getBalance() const;
double calculateMonthlyInterest();
static void modifyInterestRate(double interestRate):
~SavingsAccount();
private:
double *savingsBalance;
};
Cpp file with member function definitions
#include "SavingsAccount.h"
double SavingsAccount::annualInterestRate=0;
SavingsAccount::SavingsAccount(double amount)
:savingsBalance(new double(amount))
{
}
double SavingsAccount::getBalance()const
{
return *savingsBalance;
}
double SavingsAccount::calculateMonthlyInterest()
{
double monthlyInterest=((*savingsBalance)*annualInterestRate)/12;
*savingsBalance=*savingsBalance+monthlyInterest;
return monthlyInterest;
}
void SavingsAccount::modifyInterestRate(double interestRate)
{
annualInterestRate=interestRate;
}
SavingsAccount::~SavingsAccount()
{
delete savingsBalance;
}
End the end user driver program:
#include <iostream>
#include "SavingsAccount.h"
using namespace std;
int main()
{
SavingsAccount saver1(2000.0);
SavingsAccount saver2(3000.0);
SavingsAccount::modifyInterestRate(0.03);
cout<<"Saver1 monthly interest: "<<saver1.calculateMonthlyInterest()<<endl;
cout<<"Saver2 monthly interest: "<<saver2.calculateMonthlyInterest()<<endl;
cout<<"Saver1 balance: "<<saver2.getBalance()<<endl;
cout<<"Saver1 balance: "<<saver2.getBalance()<<endl;
return 0;
}
I spent an hour trying to figure it out without success.