Answer to Question #180562 in C++ for Vishal Pandey

Question #180562

“Smartdata pvt. ltd” company is storing the information of their employees( Name, Department DOB,Gender, address, email and Mob) in different entity according to department of employee. Now, one employee will be shifted from “programing team” to testing team. Write a code to copy all the details of that employee from one object to another object. Note: Display the above concept with the help of classes and copy constructors.


1
Expert's answer
2021-04-12T13:27:21-0400
#include <iostream>
using namespace std;
class employees
{

  private:
    string name,department,dob,gender,address,email,mob;
  public:
    employees(string n,string d,string DOB,string g,string add,string em,string m)
    {
      name=n;
      department=d;
      dob=DOB;
      gender=g;
      address=add;
      email=em;
      mob=m;
    }
    employees(employees &con)
    {
      name=con.name;
      department=con.department;
      dob=con.dob;
      gender=con.gender;
      address=con.address;
      email=con.email;
      mob=con.mob;
    }
    void display()
    {
      cout<<"Name: "<<name<<"\n";
      cout<<"Department: "<<department<<"\n";
      cout<<"Date of birth: "<<dob<<"\n";
      cout<<"Gender:"<<gender<<"\n";
      cout<<"Address:"<<address<<"\n";
      cout<<"Email:"<<email<<"\n";
      cout<<"Mobile No:"<<mob;
    }
};
int main() 
{
  string name,department,dob,gender,address,email,mob;
  cout<<"Enter Name : ";
  cin>>name;
  
  cout<<"Enter department : ";
  cin>>department;
  
  cout<<"Enter date of birth : ";
  cin>>dob;

  cout<<"Enter gender : ";
  cin>>gender;
  
  cout<<"Enter address : ";
  cin>>address;
  
  cout<<"Enter email : ";
  cin>>email;
  
  cout<<"Enter mobile number : ";
  cin>>mob;
  
  employees con(name,department,dob,gender,address,email,mob);
  employees copycon=con;
  cout<<"\nNormal Constructor : \n ";
  con.display();
  cout<<"\nCopy Constructor : \n";
  copycon.display();
  

}

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