Asked By
Sonia
20 points
N/A
Posted on - 07/18/2011
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.
Answered By
Fahar
10 points
N/A
#91628
Defining functions outside the class
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
Sonia
20 points
N/A
#91629
Defining functions outside the class
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
Fahar
10 points
N/A
#91630
Defining functions outside the class
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
Sonia
20 points
N/A
#91631
Defining functions outside the class
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
Answered By
Fahar
10 points
N/A
#91632
Defining functions outside the class
#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
Sonia
20 points
N/A
#91633
Defining functions outside the class
Thanks a lot….it really helps me….once again thanks