I'm new to classes and i am having some errors
heres my codee
accountp.cpp
The main program
account.hCode:#include <cstdlib> #include <iostream> #include <string> #include "Account.h" using namespace std; int main() { Account account1; Account account2; cout <<"\n Current Balance for account1 is " << account1.getBalance(); cout <<"\n Current Balance for account2 is " << account2.getBalance(); int amount1, amount2; cin >> amount1 >> amount2; account1.credit(amount1); account2.credit(amount2); cout <<"\n Current Balance for account1 is " << account1.getBalance(); cout <<"\n Current Balance for account2 is " << account2.getBalance(); int amountw1, amountw2; account1.debit(amountw1); account1.debit(amountw2); cout <<"\n Current Balance for account1 is " << account1.getBalance(); cout <<"\n Current Balance for account2 is " << account2.getBalance(); return 0; }
Class definition and function prototypes
account.cppCode:#include <iostream> #include <cstdlib> #include <string> using namespace std; // class Account definition class Account { public: Account( int balance ); // constructor void credit( int add_amount ); // function that add an amount to the current balance void debit( int withdraw_amount ); // function that withdraw money from the Account int getBalance(); // function that returns the the current balance private: int account_balance; // stores the current balance };
Class member function definition
and when i Compile I get these errorsCode:#include <cstdlib> #include <iostream> #include <string> using namespace std; #include "Account.h" // include definition of class Account // constructor Account::Account( int balance ) { if ( balance >= 0 ) // if the balance is greater than or equals to 0 { balance = account_balance; } else { balance = 0; cout << "\n INITIAL BALANCE WAS INVALID" "\nBalance is set to 0"; } } void Account::credit( int add_amount ) { account_balance += add_amount; } void Account::debit( int withdraw_amount ) { if ( withdraw_amount < account_balance ) { account_balance -= withdraw_amount; } else { cout << "\nDebit amount exceeded account balance."; } } int Account::getBalance() { return account_balance; }
FILE: accountp.cpp LINE: 11 MESSAGE: error: no matching function for call to `Account::Account()'
FILE: Account.h LINE: 9 MESSAGE:note: candidates are: Account::Account(const Account&)
FILE: Account.h LINE: 11 MESSAGE:note: Account::Account(int)
FILE: accountp.cpp LINE: 12 MESSAGE: error: no matching function for call to `Account::Account()'
FILE: Account.h LINE: 9 MESSAGE: note: candidates are: Account::Account(const Account&)
FILE: Account.h LINE: 11 MESSAGE:note: Account::Account(int)



LinkBack URL
About LinkBacks



