Defining functions outside the class

Asked By 20 points N/A Posted on -
qa-featured

Hi all

I want to develop a program in c++ that will take input from the user about the employee record. And will print the record as well. But the issue is this that I want to define the functions outside the class. Whenever I try to define function outside the class, many errors appears. Can any one help me to find out the solution?

I am waiting.

SHARE
Best Answer by Fahar
Answered By 10 points N/A #91628

Defining functions outside the class

qa-featured

Its very simple dear….. All you have to do is just define the required functions inside the class as public function. Then outside the class write these functions with complete code. After that, call them in main function. That’s it.

Answered By 20 points N/A #91629

Defining functions outside the class

qa-featured

I am defining the function inside the class and writing complete function outside and also calling from main function. But error is that when we write code outside it shows error on the function name. I don’t know the problem can you help me?

For example function name is void input(void);

Then what we have to do when we are writing code outside the class?

Answered By 10 points N/A #91630

Defining functions outside the class

qa-featured

The code you are writing inside is correct. I think the issue is with outside declaration. Write the code on declaration as:

 

Void classname::input(void)

{

            function working code here

}

Answered By 20 points N/A #91631

Defining functions outside the class

qa-featured

Still error, I want to write a program that will calculate Basic Pay, House rent, Medical Allowance and Net pay. Help me

House Rent=60% of basic pay

Medical allowance=20% of basic pay

Net = Basic Pay + House Rent + Medical Allowance

Best Answer
Best Answer
Answered By 10 points N/A #91632

Defining functions outside the class

qa-featured

#include
#include
class employee
{
private:
char name[15];
float bPay, hRent,mAllowance, nPay;

Public:
Void input(void);
Void allow(void);
Void display(void);
};
Void Main()
{
employee a1;
clrscr();
a1.input();
a1.allow();
a1.display();
}
void employee::input(void)
{
cout<<”Enter Name”; cin>>name;
Cout<<”Enter Basic Pay”; Cin>>bpay;
}
void employee::allow(void)
{
hRent=bPay*60/100.0;
mAllowance=bpay*20/100.0;
nPay=bpay+hRent+ mAllowance;
}
void employee::display(void)
{
clrscr();
cout<<”Employee Name = “ <

Answered By 20 points N/A #91633

Defining functions outside the class

qa-featured

Thanks a lot….it really helps me….once again thanks

Login/Register to Answer

Related Questions