Bank Account

I am trying to understand what I am doing wrong. I have been able to eliminate some errors by reading topics. The not a class or struct does not make any sense to me.

I am getting the following errors:

31 IntelliSense: not a class or struct name c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 5 24 Inheritance
33 IntelliSense: expected a ')' c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 15 57 Inheritance
32 IntelliSense: "BankAccount" is not a nonstatic data member or base class of class "SavingAccount" c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 15 41 Inheritance
Error 10 error C2614: 'SavingAccount' : illegal member initialization: 'BankAccount' is not a base or member c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 16 1 Inheritance
Error 2 error C2614: 'CheckingAccount' : illegal member initialization: 'BankAccount' is not a base or member c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 18 1 Inheritance
Error 1 error C2504: 'BankAccount' : base class undefined c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 6 1 Inheritance
Error 9 error C2504: 'BankAccount' : base class undefined c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 6 1 Inheritance
Error 23 error C2228: left of '.withDrawAmount' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 59 1 Inheritance
Error 29 error C2228: left of '.withDrawAmount' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 108 1 Inheritance
Error 24 error C2228: left of '.showAccountInfo' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 66 1 Inheritance
Error 30 error C2228: left of '.showAccountInfo' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 113 1 Inheritance
Error 22 error C2228: left of '.depositAmount' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 52 1 Inheritance
Error 28 error C2228: left of '.depositAmount' must have class/struct/union c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 101 1 Inheritance
Error 25 error C2079: 'sObj' uses undefined class 'SavingAccount' c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 88 1 Inheritance
Error 19 error C2079: 'obj' uses undefined class 'CheckingAccount' c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 36 1 Inheritance
Error 20 error C2078: too many initializers c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 36 1 Inheritance
Error 26 error C2078: too many initializers c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\mainfunction.cpp 88 1 Inheritance
Error 4 error C2065: 'endl' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 69 1 Inheritance
Error 6 error C2065: 'endl' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 83 1 Inheritance
Error 8 error C2065: 'endl' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 85 1 Inheritance
Error 12 error C2065: 'endl' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 33 1 Inheritance
Error 14 error C2065: 'endl' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 52 1 Inheritance
Error 16 error C2065: 'endl' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 53 1 Inheritance
Error 3 error C2065: 'cout' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 69 1 Inheritance
Error 5 error C2065: 'cout' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 83 1 Inheritance
Error 7 error C2065: 'cout' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 85 1 Inheritance
Error 11 error C2065: 'cout' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 33 1 Inheritance
Error 13 error C2065: 'cout' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 52 1 Inheritance
Error 15 error C2065: 'cout' : undeclared identifier c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 53 1 Inheritance

Last edited on
MainFunction.cpp

#include <cmath>
#include <iomanip>
#include <iostream>
#include "CheckingAccount.h"
#include "SavingsAccount.h"
#include "BankAccount.h"

using namespace std;
int main()

{
//Declaring local variables
double amount;
int choice;
//Displaying menu choices
do
{
cout<<"Create an Account"<<endl;
cout<<"1 Checking Account"<<endl;
cout<<"2 Saving Account"<<endl;
cout<<"3 Exit"<<endl;
//reading choice
cin>>choice;
//if checking account
if(choice==1)
{
cout<<"enter account number";
int ano;

cin>>ano;
cout<<endl<<"enter opening balance";
double obal;
cin>>obal;
double irate;
cout<<endl<<"enter interest rate";
cin>>irate;
CheckingAccount obj (ano,obal,irate);
int ch;

do
{
//ask choice of operations
cout<<"1 Deposit"<<endl<<"2 WithDraw"<<endl<<
"3 Account Info"<<endl<<"4 Exit"<<endl;
cin>>ch;
//Perform selected operation
switch(ch)
{
case 1:
cout<<"Enter amount";
cin>>amount;
double damount;
damount=obj.depositAmount(amount);
cout<<"Available balance: "<<damount<<endl;
break;
case 2:
cout<<"Enter amount";
cin>>amount;
double wamount;
wamount=obj.withDrawAmount(amount);
cout<<"Available balance: "<<wamount<<endl;

break;

case 3:

obj.showAccountInfo();

break;
}//End of switch

}while(ch!=4);
}//end of if

//If choice is savings account
else if(choice==2)
{
//reading needed information
cout<<"enter account number";
int ano;
cin>> ano;
cout<<endl<<"enter opening balance";
double obal;
cin>> obal;
double irate;
cout<<endl<<"enter interest rate";
cin>> irate;
//Creating object for savings account
SavingAccount sObj( ano, obal);
int ch;
do
{
cout<<"1 Deposit"<<endl<<"2 WithDraw"<<endl<<
"3 Account Info"<<"4 Exit"<<endl;
cin>> ch;
switch( ch)
{
case 1:
cout<<"Enter amount";
cin>>amount;
double damount;
damount=sObj.depositAmount(amount);
cout<<"Available balance: "<< damount;
break;
case 2:
cout<<"Enter amount";
cin>>amount;
double wamount;
wamount=sObj.withDrawAmount(amount);
cout<<"Available balance: "<< wamount;
break;

case 3:
sObj.showAccountInfo();
break;
case 4:break;
default:cout<<"invalid choice";break;
}//End of switch

}while( ch!=4);
}//End of else
}while(choice!=3);
}
[CheckingAccount.h]

#include <iostream>
#include <iomanip>
#include <cmath>

class CheckingAccount: BankAccount
{
//Data members
double balance;
double interest;
double minBal;
double serviceCharge;
double accountNumber;

public://Constructore


CheckingAccount(int ano,double amount,double interest):BankAccount( ano, amount)
{
interest= interest;
minBal=500;//By default
}
//To set interest rate
void setInterestRate(double irate)
{
interest=irate;
}
//to get interest rate
double retrieveInterestRate()
{
return(interest);
}
//to set minimum balance
void setMinBal(double mbal)
{
minBal=mbal;
}
//To get minimum balance
double retrieveMinBal()
{
return(minBal);
}
//To set service charge
void setServiceCharge(double scharge)
{
serviceCharge=scharge;
}
//To get service charge
double retrieveServiceCharge()
{
return(serviceCharge);
}
//To perform deposit
//overriding base class function
double depositAmount(double damount)

{
balance=balance+damount;
return(balance);
}

//to perform withdraw
//overriding base class function
double withDrawAmount(double wamount)
{
//Checking for account have sufficient balance or not
if(check())
balance=balance-wamount;
else
cout<<"You have in sufficient balance"<<endl;
return(balance);
}
//Check function for verifying balance
bool check()
{
if(balance<minBal)
return(false);
else
return(true);
}
//To display account information
void showAccountInfo()
{
cout<<"Account Number :"<<accountNumber<<endl;

cout<<"Account Balance:"<<balance<<endl;
}
};

[BankAccount.h]


//Data members
public:
int accountNumber;
double balance;
public:
//Constructor
BankAccount(int ano,double bal)
{
accountNumber=ano;
balance=bal;
}
BankAccount() { }
public:
//Accessor methods for getting balance
double getBalance()
{
return(balance);
}
//Accessor methods for getting account number
int getAccountNumber()
{
return(accountNumber);
}
//Mutuator method to set balance
void setBalance(double amount)
{
balance=amount;
}
//Setting account number
void setAccountNumber(int ano)
{
accountNumber=ano;
}

//show account information
void showAccountInfo()
{
cout<<"Account Number :"<<accountNumber<<endl;
cout<<"Account Balance:"<<balance<<endl;
}

//function to perform deposit
double depositAmount(double damount)
{

balance=balance+damount;
return(balance);
}

//withdrawl amount
double withDrawAmount(double wamount)
{
balance=balance-wamount;
return(balance);
}
};

[SavingsAccount.h]

#include <iomanip>
#include <iostream>
#include <cmath>

class SavingAccount : BankAccount
{
//data member
double minBal;
double balance;
double accountNumber;

public:
//Constructor

SavingAccount(int ano , double amount):BankAccount(ano , amount)
{
minBal=500;
}
//to perform deposit
//overriding base class function
double depositAmount(double damount)
{
balance=balance+damount;
return(balance);
}
//to perform withdraw
//overriding base class function
double withDrawAmount(double wamount)
{
if(check())
balance=balance-wamount;
else
cout<<"you have in sufficient balance"<<endl;
return(balance);
}
//Setting minimum balance
void setMinBal(double mbal)
{
minBal=mbal;
}
//Checking for account sufficiency
bool check()
{
if(balance<minBal)
return(false);
else
return(true);
}
//Showing account information
void showAccountInfo()
{
cout<<"Account Number :"<<accountNumber<<endl;
cout<<"Account Balance:"<<balance<<endl;
}
};
closed account (N36fSL3A)
Take a good look
c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\checkingaccount.h 5 24 Inheritance
33 IntelliSense: expected a ')' c:\users\terry\documents\visual studio
I think this may be at least part of the problem:
1
2
3
4
5
6
#include <iomanip>
#include <iostream>
#include <cmath>

class SavingAccount : BankAccount
{

The corresponding errors:
Error 1 error C2504: 'BankAccount' : base class undefined c:\[...]\checkingaccount.h 6 1 Inheritance
Error 9 error C2504: 'BankAccount' : base class undefined c:\[...]\savingsaccount.h 6 1 Inheritance

The compiler's not finding the BankAccount class, because you never #include d BankAccount.h.

Just because it's in your project doesn't mean that the compiler can "magically" see it. You have to #include it yourself.
I am use to cnc programming, where you name it once in the main and it is done. I am still learning c++. I will give it a try. That helped a lot.
Error 3 error C2614: 'SavingAccount' : illegal member initialization: 'BankAccount' is not a base or member c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 18 1 Inheritance
Error 2 error C2504: 'BankAccount' : base class undefined c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\savingsaccount.h 7 1 Inheritance
Error 1 error C2011: 'BankAccount' : 'class' type redefinition c:\users\terry\documents\visual studio 2010\projects\inheritance\inheritance\bankaccount.h 8 1 Inheritance
I am going to see if I can figure this out before anyone can reply. But feel free to look it over, please. Thanks for your help.
Hmm...I would guard your headers:
1
2
3
4
5
6
7
8
9
10
// BankAccount.h
#ifndef BANKACCOUNT_H // Or pick some other unique identifier
#define BANKACCOUNT_H

class BankAccount
{
    // etc.
};

#endif 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// CheckingAccount.h
#ifndef CHECKINGACCOUNT_H // Or pick a different name, doesn't really matter
#define CHECKINGACCOUNT_H

#include <iostream>
#include <iomanip>
#include <cmath>
#include "BankAccount.h" // Need this so the compiler can see BankAccount

class CheckingAccount: BankAccount
{
    // etc.
};

#endif 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// SavingsAccount.h
#ifndef SAVINGSACCOUNT_H // Once again, you don't have to use this name...
#define SAVINGSACCOUNT_H

#include <iomanip>
#include <iostream>
#include <cmath>
#include "BankAccount.h" // So the compiler can see BankAccount

class SavingAccount : BankAccount
{
    // etc.
};

#endif 

Since you're using the Microsoft compiler, it'll also work if you just put #pragma once at the top of your header files instead, but be warned that this is a non-standard extension, so it won't necessarily work on all compilers.
Guarding the headers worked. Thank you so much, I can feel the tension lifting already.
Topic archived. No new replies allowed.