google.com, pub-3534375712831849, DIRECT, f08c47fec0942fa0 CS201 Assignment 3 Solution Fall 2021 Download in CPP
Latest Updates
Loading...

CS201 Assignment 3 Solution Fall 2021 Download in CPP



Problem Statement:

 

XYZ is an organization which requires privacy of its employees’ data. For this purpose, an Employee class will be written having following private attributes.

‘empId’ of type String         (Write your own student VU id in empId)

‘empName’ of type String   (Write your own name in empName)

‘joiningYear’ of type int      (This will be just the year like 2001,2002,….2022)

‘joiningDate’ of type int      (This will be just the day like 1,2,3….31 NOT the full date as 3/2/2022)

‘joiningMonth’ of type int   (This will be just the month like 1,2,3….12 )

 

For each attribute mentioned above, use setter method to set or update its value and getter method to return its value.

You also need to provide following functions inside the Employee class;

  1. Default Constructor   (To create an object of Employee class with default values)
  2. Parameterized Constructor  (To create object of Employee class with user’s own attributes values)
  3. setValues(Employee *emp2) (Take an object of Employee class and copy its data members’ values to data members of calling object by using setters)
  4. display(Employee emp)  (Print data member values of emp object using getters)

 


In the main function you have to create and initialize two objects of Employee class using following instructions;

1)      Create first object of Employee class using Default constructor which will initialize the object with some default values.

2)      Create second object of Employee class using Parameterized Constructor and initialize it with your own real values.

3)      Copy the employee 2 object’s data members values to employee 1 object’s data members using setValues(Employee *emp2) function.

4)      Call display() function to print each object’s values as per format shown in following screen shot.

 

A sample output is given in screenshot below.


Note: You will write your own student VU Id and name in attributes (empId and empName) respectively, otherwise you will not get any grades.

Solution:


#include<iostream>

using namespace std;

class Employee

{

private:

string empId;

string empName;

int joiningYear;

int joiningMonth;

int joiningDate;

public:

Employee()

{

empId = "<<EMPTY>>";

empName = "<<EMPTY>>";

joiningYear=0;

joiningMonth=0;

joiningDate=0;

}

Employee(string id, string name, int year, int month, int date)

{



empId = id;

empName = name;

joiningYear=year;

joiningMonth=month;

joiningDate=date;

}

void setValues(Employee *emp2)

{

empId = emp2->empId;

empName = emp2->empName;

joiningYear=emp2->joiningYear;

joiningMonth=emp2->joiningMonth;

joiningDate=emp2->joiningDate;

}

string getId()


{

return empId;

}

string getName()

{

return empName;

}

int getYear()

{

return joiningYear;

}

int getMonth()

{

return joiningMonth;

}

int getDate()

{

return joiningDate;

}

void display(Employee emp)

{

cout<<"ID: "<<emp.getId()<<endl;

cout<<"Name: "<<emp.getName()<<endl;

cout<<"Joining Year: "<<emp.getYear()<<endl;

cout<<"Joining Month: "<<emp.getMonth()<<endl;

cout<<"Joining Date: "<<emp.getDate()<<endl<<endl;

}

};

int main()

{

cout<<"\t\t CS201 Assignment 3 Solution"<<endl;

cout<<"\t\t Abdul Hadi E Services BC1234567 \n"<<endl;

Employee emp1;

Employee emp2("BC123456", "Abdul Hadi E Services", 2019,03,03); 

cout<<"Employee 1 Using default Constructor:"<<endl;

emp1.display(emp1);

cout<<"Employee 2 Using Parameterized constructor:"<<endl;

emp2.display(emp2);

cout<<"Employee 1 having Employee 2 copied data member values"<<endl;

emp1.setValues(&emp2);

emp1.display(emp1);

return 0;

}



Download File Now



Want more info, please press the below button




`

Post a Comment

0 Comments