Write a C++ program for employee wages calculation using class and objects.

Algorithm: 
1. Employee class contains name and wage variable and member function a putname(), putwage(),getwage() and getname(). 
2. Putname: Assign the valve for the character array name. 
3. Getname: Retrieves the value of Variable name. 
4. Putwage: Assign the valve for wage variable. 
5. Getwage: Retrieves the value of wage variable. 
6. In main() Put and display both name and wages.


Implementation of above program:
#include<iostream>
#include<string.h>
using namespace std;
class employee {
char name[80]; // private by default
public:
void putname(char *n); // these are public
void getname(char *n);
private:
double wage; // now, private again
public:
void putwage(double w); // back to public
double getwage();
};
void employee::putname(char *n)
{
strcpy(name, n);
}
void employee::getname(char *n)
{
strcpy(n, name);
}
void employee::putwage(double w)
{
wage = w;
}
double employee::getwage()
{
return wage;
}
int main()
{
employee ted;
char name[80];
ted.putname("Mukesh Rajput");
ted.putwage(7500);
ted.getname(name);
cout << name <<" makes $ ";
cout << ted.getwage() << " per year.";
return 0;
}

The program output is tested on www.jdoodle.com

Output:
Mukesh Rajput makes $ 7500 per year.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: