Write a program to create a class called employee, the class
has members , name , ID, and salary, a constructor to enter values
from users, and member function to display the result of the
following equation:
𝑀 =
𝑆𝑎𝑙𝑎𝑟𝑦
---------∗ 15
100
SOLUTION CODE
#include <iostream>
using namespace std;
class employee
{
private:
string name;
string idNumber;
int salary;
public:
employee(string n, string idNum, int s)
{
name = n;
idNumber = idNum;
salary = s;
}
void display()
{
cout<<"\nEmployee name: "<<name<<endl;
cout<<"Employee Id number: "<<idNumber<<endl;
cout<<"Employee Salary: "<<salary<<endl;
}
};
int main()
{
//Now propt the user for values
cout<<"\nEnter the employee name: ";
string employee_name;
cin>>employee_name;
cout<<"\nEnter the employee ID number: ";
string employee_id_number;
cin>>employee_id_number;
cout<<"\nEnter the employee salary: ";
int employee_salary;
cin>>employee_salary;
employee my_0bject = employee(employee_name,employee_id_number, employee_salary);
my_0bject.display();
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment