// CheckingAccount.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "CheckingAccount.h"
CheckingAccount::CheckingAccount(double initialBalance, double transactionFee)
:Account(transactionFee)
void credit(double money)
{
Account::setBalance(Account::getBalance() + money);
chargeFee();
}
void debit(double money)
{
if (Account::debit(money))
Account::setBalance(Account::getBalence() - money);
chargeFee();
elsebreak;
}
void chargeFee()
{
Account::setBalance(Account::getBalance - transactionFee);
cout<<"\n"<<" Charged a fee of "<<transactionFee;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Lab 1: Account.h
// Definition of Account class.
#ifndef ACCOUNT_H
#define ACCOUNT_H
class Account
{
public:
Account( double ); // constructor initializes balance
void credit( double ); // add an amount to the account balance
bool debit( double ); // subtract an amount from the account balance
void setBalance( double ); // sets the account balance
double getBalance(); // return the account balance
private:
double balance; // data member that stores the balance
}; // end class Account
#endif
// Lab 1: Account.cpp
// Member-function definitions for class Account.
#include <iostream>
using std::cout;
using std::endl;
#include "Account.h" // include definition of class Account
// Account constructor initializes data member balance
Account::Account( double initialBalance )
{
// if initialBalance is greater than or equal to 0.0, set this value
// as the balance of the Account
if ( initialBalance >= 0.0 )
balance = initialBalance;
else // otherwise, output message and set balance to 0.0
{
cout << "Error: Initial balance cannot be negative." << endl;
balance = 0.0;
} // end if...else
} // end Account constructor
// credit (add) an amount to the account balance
void Account::credit( double amount )
{
balance = balance + amount; // add amount to balance
} // end function credit
// debit (subtract) an amount from the account balance
// return bool indicating whether money was debited
bool Account::debit( double amount )
{
if ( amount > balance ) // debit amount exceeds balance
{
cout << "Debit amount exceeded account balance." << endl;
returnfalse;
} // end if
else // debit amount does not exceed balance
{
balance = balance - amount;
returntrue;
} // end else
} // end function debit
// set the account balance
void Account::setBalance( double newBalance )
{
balance = newBalance;
} // end function setBalance
// return the account balance
double Account::getBalance()
{
return balance;
}
Ok
1] Sorry for the very long code...
2] I found this website on goodle, the tutorials are great and im trying out the forums because i have a problem
3] The problem. I just finished this code for a hw assigment [inheritance] and i am getting stuck b/c on the derived class definitions files, i get errors [at bottom] such as reached end of file unexpected error and something w/ local function definitions. anyways i got stuck because im not sure what to do. ive read the chapter over again, and i feel im missing either something very obvious and stupid or something complicated... but anyways, any help is greatly appreciated!!
Thanks for reading :]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
1
1>Compiling...
1>account.cpp
1>bankAccounts.cpp
1>CheckingAccount.cpp
1>c:\documents and settings\alex\desktop\chapter12\chapter12\checkingaccount.cpp(13) : error C2612: trailing 'type' illegal in base/member initializer list
1>c:\documents and settings\alex\desktop\chapter12\chapter12\checkingaccount.cpp(14) : error C2601: 'credit' : local function definitions are illegal
1>c:\documents and settings\alex\desktop\chapter12\chapter12\checkingaccount.cpp(21) : error C2601: 'debit' : local function definitions are illegal
1>c:\documents and settings\alex\desktop\chapter12\chapter12\checkingaccount.cpp(29) : error C2601: 'chargeFee' : local function definitions are illegal
1>c:\documents and settings\alex\desktop\chapter12\chapter12\checkingaccount.cpp(33) : fatal error C1004: unexpected end-of-file found
1>SavingsAccount.cpp
1>c:\documents and settings\alex\desktop\chapter12\chapter12\savingsaccount.cpp(8) : error C2612: trailing 'type' illegal in base/member initializer list
1>c:\documents and settings\alex\desktop\chapter12\chapter12\savingsaccount.cpp(9) : error C2601: 'SavingsAccount::calculateInterest' : local function definitions are illegal
1>c:\documents and settings\alex\desktop\chapter12\chapter12\savingsaccount.cpp(12) : fatal error C1004: unexpected end-of-file found
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\alex\Desktop\chapter12\chapter12\Debug\BuildLog.htm"
1>chapter12 - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========