Answer to Question #224830 in C++ for snr

Question #224830

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.


1
Expert's answer
2021-08-12T16:23:37-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS