Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Why do I keep getting a message stating that a function has not been declared in a class?

Hello,

I have produced some basic C++ code in which I have a class with declared functions. Below it I have defined those functions but yet when I run the code I get a message stating the the functions have not been delcated in the class. I cannot see any reason why the code should not work. Could you please have a look?

Thanks.
C--Users-u166946-C---Level-3-Chap1-BankA
0
f19l
Asked:
f19l
1 Solution
 
jkrCommented:
Well, C++ is case sensitive. While you have declöared some methods that start with lowercase letters, you are implementing them with uppercase names. Try

//preprocessor calls...
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

class BankAccount
{
      private:   //private attributes first...
         int accnumber;
         string accholder;
         float accbalance;
         
      public:  //followed by public methods
         BankAccount();   //the constructor
         
         void setAccNumber(int acnumin);
         int getAccNumber();
         
         void setAccHolder(string acholderin);
         string getAccHolder();
         
         void setDeposit(float depamnt);
         void setAccBalance(float acamountin);
         float getAccBalance();
         
         void setWithdrawal(float depamnt);
         float getWithdrawal(float witamnt);
};

BankAccount::BankAccount()   //constructor sets account balance to zero
                             //when an instance of BankAccount is created
{
         accbalance=0;
}
void BankAccount::setAccNumber(int acnumin)   //sets the account number
{
         accnumber=acnumin;
}
int BankAccount::getAccNumber()   //returns integer account number
{
         return accnumber;
}
void BankAccount::setAccHolder(string accholderin)   //sets account name
{
         accholder=accholderin;
}                                                          
string BankAccount::getAccHolder()   //returns name of account number
{
         return accholder;
}                                         
void BankAccount::setAccBalance(float acamountin)   //sets the initial account balance
{
         accbalance=acamountin;
}                
float BankAccount::getAccBalance()    //returns current account balance
{
      return accbalance;
}
void BankAccount::setDeposit(float depamnt)   //adds an amount to the account balance
{
         accbalance+=depamnt;
} 
void BankAccount::setWithdrawal(float witamnt)   //subtracts an amount from the account balance
{
         accbalance-=witamnt;
} 
       
int main()
{
    //instantiate three objects of bank accounts...
    BankAccount account1, account2, account3;
    
    //set the account details...
    //account1...
    account1.setAccNumber(110);
    account1.setAccHolder("Charles Darwin");
    account1.setAccBalance(1562.65);
    //account2...
    account2.setAccNumber(120);
    account2.setAccHolder("Michael Faraday");
    account2.setAccBalance(2753.48);
    //account3...
    account3.setAccNumber(130);
    account3.setAccHolder("Charles Babbage");
    account3.setAccBalance(3951.42);
    
    //display the account details...
    //account1...
    cout<<"\n Account Number 1: "
        <<account1.getAccNumber()<<endl;
    cout<<" Account Holder 1: "    
        <<account1.getAccHolder()<<endl;
    cout<<" Account Balance 1: "
        <<account1.getAccBalance()<<endl;

    //account2...
    cout<<"\n Account Number 2: "
        <<account2.getAccNumber()<<endl;
    cout<<" Account Holder 2: "    
        <<account2.getAccHolder()<<endl;
    cout<<" Account Balance 2: "
        <<account2.getAccBalance()<<endl; 
        
    //account3...
    cout<<"\n Account Number 3: "
        <<account3.getAccNumber()<<endl;
    cout<<" Account Holder 3: "    
        <<account3.getAccHolder()<<endl;
    cout<<" Account Balance 3: "
        <<account3.getAccBalance()<<endl;  
        
    cout<<"\n\t Press any key to close.\n";
    getch();
    return 0;
}                         

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now