//CheckingAccount.h
#ifndef checkingaccount_H
#define checkingaccount_H
#include <string>
usingnamespace std;
class CheckingAccount //Names the class
{
private: //variables found in main program
int transactionCount;
public: //Getter and setter functions.
CheckingAccount(int m, bool display);
~CheckingAccount(); //Destructor
void withdrawMoney(int m, bool display);
};
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//CheckingAccount.h
#include "CheckingAccount.h"
#include <iostream>
usingnamespace std;
//constructor
CheckingAccount::CheckingAccount(int m, bool display)
{
transactionCount = m;
}
//functions
void CheckingAccount::withdrawMoney(int m, bool display)
{
transactionCount=m;
}
CheckingAccount::~CheckingAccount() //Implementation of destructor from class.
{}
//SavingsAccount.h
#ifndef savingsaccount_H
#define savingsaccount_H
#include <iomanip>
usingnamespace std;
class SavingsAccount //Names the class
{
private: //variables found in main program
double newInterestRate;
int numberOfDays;
double earnedInterest;
public: //Getter and setter functions.
SavingsAccount(double i, int b, double c);
~SavingsAccount(); //Destructor
void setInterestRate(double i);
double getAccountBalance();
double getInterestEarned();
int getNumberOfDays();
};
#endif
1>------ Build started: Project: Wk3, Configuration: Debug Win32 ------
1>Build started 2/6/2013 12:20:55 AM.
1>InitializeBuildStatus:
1> Touching "Debug\Wk3.unsuccessfulbuild".
1>ClCompile:
1> SavingsAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(23): error C2065: 'balance' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(24): error C2065: 'balance' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(25): error C2065: 'balance' : undeclared identifier
1> BankAccountMain.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(26): error C2512: 'CheckingAccount' : no appropriate default constructor available
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(27): error C2512: 'SavingsAccount' : no appropriate default constructor available
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(31): error C2039: 'setAccountNumber' : is not a member of 'SavingsAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9) : see declaration of 'SavingsAccount'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(35): error C2039: 'getAccountNumber' : is not a member of 'SavingsAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9) : see declaration of 'SavingsAccount'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(41): error C2039: 'getAccountNumber' : is not a member of 'SavingsAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9) : see declaration of 'SavingsAccount'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(48): error C2039: 'depositMoney' : is not a member of 'SavingsAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9) : see declaration of 'SavingsAccount'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(49): error C2039: 'getAccountNumber' : is not a member of 'CheckingAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(8) : see declaration of 'CheckingAccount'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(57): error C2039: 'withdrawMoney' : is not a member of 'SavingsAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9) : see declaration of 'SavingsAccount'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(60): error C2039: 'getAccountNumber' : is not a member of 'SavingsAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9) : see declaration of 'SavingsAccount'
1> BankAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.cpp(31): error C2562: 'BankAccount::depositMoney' : 'void' function returning a value
1> f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.h(19) : see declaration of 'BankAccount::depositMoney'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.49
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
OK the default constructor I get, I did miss that. The others I'm not so sure on. How do I get the functions to become members of the class? I thought I did that.
As an example, lets look at the error concerning setAccountNumber(). The error says that it is not a member of SavingsAccount, and upon inspection I see that is the case; the members of SavingsAccount are those listed on lines 11-13 and 17-22 of SavingsAccount.hpp. There is no mention of the method setAccountNumber().
I have a strong suspicion of your intent, but see if my hint there helps you see the issue.
As an example, lets look at the error concerning setAccountNumber(). The error says that it is not a member of SavingsAccount, and upon inspection I see that is the case; the members of SavingsAccount are those listed on lines 11-13 and 17-22 of SavingsAccount.hpp. There is no mention of the method setAccountNumber().
I have a strong suspicion of your intent, but see if my hint there helps you see the issue
My setAccountNumber() function is in my BankAccount class, there is no mention of it in the Savings Account class. So now I'm really confused. Are you saying I need to link the classes together somehow?
//SavingsAccount.h
#ifndef savingsaccount_H
#define savingsaccount_H
#include <iomanip>
#include "BankAccount.h"
usingnamespace std;
class SavingsAccount //Names the class
class SavingsAccount: public BankAccount
{
private: //variables found in main program
double newInterestRate;
int numberOfDays;
double earnedInterest;
public: //Getter and setter functions.
SavingsAccount();
SavingsAccount(double i, int b, double c);
~SavingsAccount(); //Destructor
void setInterestRate(double i);
double getAccountBalance();
double getInterestEarned();
int getNumberOfDays();
};
#endif
//CheckingAccount.h
#ifndef checkingaccount_H
#define checkingaccount_H
#include <string>
#include "BankAccount.h"
usingnamespace std;
class CheckingAccount //Names the class
class CheckingAccount: public BankAccount
{
private: //variables found in main program
int transactionCount;
public: //Getter and setter functions.
CheckingAccount();
CheckingAccount(int m, bool display);
~CheckingAccount(); //Destructor
void withdrawMoney(int m, bool display);
};
#endif
1>------ Build started: Project: Wk3, Configuration: Debug Win32 ------
1>Build started 2/7/2013 2:50:21 AM.
1>InitializeBuildStatus:
1> Touching "Debug\Wk3.unsuccessfulbuild".
1>ClCompile:
1> SavingsAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C2236: unexpected 'class' 'CheckingAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C3381: 'CheckingAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C2236: unexpected 'class' 'SavingsAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C3381: 'SavingsAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(31): error C2065: 'balance' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(32): error C2065: 'balance' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(33): error C2065: 'balance' : undeclared identifier
1> CheckingAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C2236: unexpected 'class' 'CheckingAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C3381: 'CheckingAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C2236: unexpected 'class' 'SavingsAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C3381: 'SavingsAccount' : assembly access specifiers are only available in code compiled with a /clr option
1> BankAccountMain.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C2236: unexpected 'class' 'CheckingAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C3381: 'CheckingAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C2236: unexpected 'class' 'SavingsAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C3381: 'SavingsAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(57): warning C4305: 'argument' : truncation from 'double' to 'bool'
1> BankAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C2236: unexpected 'class' 'CheckingAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(9): error C3381: 'CheckingAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C2236: unexpected 'class' 'SavingsAccount'. Did you forget a ';'?
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C3381: 'SavingsAccount' : assembly access specifiers are only available in code compiled with a /clr option
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.cpp(39): error C2562: 'BankAccount::depositMoney' : 'void' function returning a value
1> f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.h(20) : see declaration of 'BankAccount::depositMoney'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.64
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
ok so if im reading ur output right, you forgot a semicolon on line 9 of checking account.cpp. you still havent declared balance. you forgot a semicolon for savings account and you set bankaccount::depositmoney() to void but you still have it returning a value
It's more than unnecessary, it's an error. If it had a semicolon, then it would just be unnecessary...
Start by removing those //Names the class lines and adding a member variable ('balance') to store a balance in the SavingsAccount class. Hint: be sure to initialize balance in the constructor.
OK so I think one of my issues was I had each class as its own base class and not as inherited classes of the base class which in this case is 'BankAccount'. I also found some issues with my functions as pointed out but some of you. Here are the changes that I made...
//CheckingAccount.h
#pragma once
#include <string>
usingnamespace std;
class CheckingAccount: public BankAccount //inherits base class
{
private: //variables found in main program
int transactionCount;
public: //Getter and setter functions.
CheckingAccount();
CheckingAccount(int m, bool display);
~CheckingAccount(); //Destructor
void withdrawMoney(int m, bool display);
};
I did the same treatment to the checking account and savings account classes. I know I still have the 'balance' not being defined so I am trying to figure out how to correct that. (Instructor gave me a UML to go by). Here is the output now.
1>------ Build started: Project: Wk3, Configuration: Debug Win32 ------
1>Build started 2/8/2013 2:37:46 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Wk3.unsuccessfulbuild".
1>ClCompile:
1> SavingsAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.h(9): error C2504: 'BankAccount' : base class undefined
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(31): error C2065: 'balance' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(32): error C2065: 'balance' : undeclared identifier
1>f:\my documents\visual studio 2010\projects\wk3\wk3\savingsaccount.cpp(33): error C2065: 'balance' : undeclared identifier
1> CheckingAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\checkingaccount.h(7): error C2504: 'BankAccount' : base class undefined
1> BankAccountMain.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccountmain.cpp(57): warning C4305: 'argument' : truncation from 'double' to 'bool'
1> BankAccount.cpp
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.cpp(34): error C2562: 'BankAccount::depositMoney' : 'void' function returning a value
1> f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.h(20) : see declaration of 'BankAccount::depositMoney'
1>f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.cpp(38): error C2511: 'bool BankAccount::withdrawMoney(double)' : overloaded member function not found in 'BankAccount'
1> f:\my documents\visual studio 2010\projects\wk3\wk3\bankaccount.h(8) : see declaration of 'BankAccount'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:06.12
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
OK just as a thread update. I finally was able to make the program compile. I fixed the undeclared identifier 'balance', by renaming 'AccountBalance' to 'balance'. I also added #include BankAccount to the derived classes to define it, and I changed void to double to allow the function to return a value.