Create the class Employee with the following attributes: Emp ID, Name, Designation, Project ID and
Phone Number. Print the Current details of the employee. Add a behaviour to modify the projectID.
And display the updated employee details.
#include<iostream>
using namespace std;
class Employee{
private:
int Emp_ID;
string Name, Designation;
int Project_ID, PhoneNumber;
public:
Employee(int empId, string n, string des, int pd, int pn ){
Emp_ID = empId;
Name = n;
Designation = des;
Project_ID = pd;
PhoneNumber = pn;
}
void Print(){
cout<<"Emp ID: "<<Emp_ID<<endl;
cout<<"Employee Name: "<<Name<<endl;
cout<<"Designation: "<<Designation<<endl;
cout<<"Phone Number: "<<PhoneNumber<<endl;
cout<<"Project ID: "<<Project_ID<<endl;
}
//Behavior to change the Project_ID
void ChangeProjectID(int id){
cout<<"Emp ID: "<<Emp_ID<<endl;
cout<<"Employee Name: "<<Name<<endl;
cout<<"Designation: "<<Designation<<endl;
cout<<"Phone Number: "<<PhoneNumber<<endl;
cout<<"Project ID: "<<id<<endl;
}
};
int main()
{
int Emp_ID;
string Name, Designation;
int Project_ID, PhoneNumber;
cout<<"Enter the employee id \n";
cin>>Emp_ID;
cout<<"Enter the employee name\n";
cin>>Name;
cout<<"Enter the employee Designation\n";
cin>>Designation;
cout<<"Enter the Project ID\n";
cin>>Project_ID;
cout<<"Enter the employee Phone Number \n";
cin>>PhoneNumber;
Employee emp(Emp_ID,Name,Designation,Project_ID,PhoneNumber);
emp.Print();
int pd;
cout<<"Enter the new Project ID\n";
cin>>pd;
cout<<"The updated details are\n";
emp.ChangeProjectID(pd);
return 0;
}
Comments
Leave a comment