I am working on this program and I am getting compilig error here is the code:-
#ifndef ACCOUNT_H
#define ACCOUNT_H
class Account
{
public:
Account(double = 0.0);
void credit( double);
bool debit (double);
void setBalance(double);
double getBalance();
private:
double balance;
};
#endif
# include <iostream>
using std::cout;
using namespace std;
#include "Account.h"
Account::Account(double bal)
{
balance = bal;
setBalance(bal);
}
void Account:: credit(double cr)
{
if(cr > 0)
{
balance+= cr;
}
}
bool Account:: debit(double db)
{
if( balance >= db)
{
balance = balance -db;
return true;
}
else
return false;
}
void Account :: setBalance(double bal)
{
if ( bal >= 0.0)
{
balance = bal;
}
else
{
cout <<"invalid amount"<<endl;
balance = 0.0;
}
}
double Account :: getBalance()
{
return balance;
}
#ifndef SAVING_H
#define SAVING_H
#include "Account.h"
class SavingAccount:public Account
{
public:
SavingAccount(double, double);
double calculateInterest(double, double);
void setInterestRate(double);
double getInterestRate();
private:
double interestRate;
};
#endif
# include <iostream>
using std::cout;
using namespace std;
#include "SavingAccount.h"
SavingAccount::SavingAccount(double rate , double balance)
:Account(balance)
{
setInterestRate(rate);
}
double calculateInterest(double balance, double interestRate)
{
return (balance= balance + (balance*interestRate));
}
void SavingAccount::setInterestRate(double rate)
{
interestRate = rate;
}
double SavingAccount:: getInterestRate()
{
return interestRate;
}
here is the driver:-
# include <iostream>
using std::cout;
using std::endl;
# include "Account.h"
int main()
{
Account account1(15);
account1.credit(100);
//account1.debit(13);
//cout<<
cout<<"balance is"<< account1.getBalance()<<endl;
//account1.debit(15);
cout<<"New balance is " <<account1.getBalance()<<endl;
SavingAccount account1(2100);
account1.setInterestRate(15);
cout<<"balance is " << account2.getBalance()<<endl;
}
when I compile it says "SavingAccount unideclared indetifier". If I remove savingAccount object and compile only Account object then program runs perfect..any help??