Posted by MindBreaker at 9:31 PM
Read our previous post
Object
Create an employee class, basing it on Exercise 4 of Chapter 4. The member data should
comprise an int for storing the employee number and a float for storing the employee’s
compensation. Member functions should allow the user to enter this data and display it.
Source Codecomprise an int for storing the employee number and a float for storing the employee’s
compensation. Member functions should allow the user to enter this data and display it.
#include <iostream>
using namespace std;
class employee
{
private:
int noemployee;
float income;
public:
employee()
{}
void calculate(int number,float money)
{
noemployee=number;
income=money;
}
void showdata()
{
cout<<"Employee number"<<noemployee<<endl;
cout<<"employee income"<<income<<endl;
}
};
void main()
{
int no;
float money;
employee em1,em2,em3;
cout<<"Enter Employee 1 : Number"<<endl;
cin>>no;
cout<<"Enter Employee 1 : income"<<endl;
cin>>money;
em1.calculate(no,money);
cout<<"Enter Employee 2 : Number"<<endl;
cin>>no;
cout<<"Enter Employee 2 : Number"<<endl;
cin>>money;
em2.calculate(no,money);
cout<<"Enter Employee 3 : Number"<<endl;
cin>>no;
cout<<"Enter Employee 3 : Number"<<endl;
cin>>money;
em3.calculate(no,money);
em1.showdata();
em2.showdata();
em3.showdata();
}
Output
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.