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??

I have that! I have #include SavingAccount.h" in the class definition of savingAccount.

oops I got it but still its giving me this error now ...." error C2664: 'SavingAccount::SavingAccount(const SavingAccount &)' : cannot convert parameter 1 from 'int' to 'const SavingAccount &'

SavingAccount account1(2100);

That is a constructor using an int. Unfortunately, you don't declare such a constructor, so the compiler is complaining. Unfortunately, the compiler thinks you are trying to use the copy constructor, so it's giving you a funny reason for complaining.

how can I fix it then?
thanks,

ok so I need to define like saving Account account1 = (120, 13) right?
gotcha!

last thing, why this program is not computing correct balance, after I set balance 120 and rate 13 and add credit 210 , it just adds up balance and credit but doesn't do anything wit the rate?
any idea???

thanks again.

In the code posted I don't see where you ever call calculateInterest(). I can only hope you've called it in the code you haven't posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.