0% found this document useful (0 votes)
3 views

Week Employee Class

The document is a C++ program that defines an Employee class with attributes such as name, ID number, department, and position. It includes multiple constructors for initializing Employee objects and methods for setting and getting the values of the attributes. The main function creates three Employee objects and displays their information in a formatted manner.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Week Employee Class

The document is a C++ program that defines an Employee class with attributes such as name, ID number, department, and position. It includes multiple constructors for initializing Employee objects and methods for setting and getting the values of the attributes. The main function creates three Employee objects and displays their information in a formatted manner.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <string>
using namespace std;

class Employee
{
private:
string name; // Holds the employee's name
int idNumber; // Holds the employee's ID number
string department; // Holds the department where the employee works
string position; // Holds the employee's job title

public:
// This constructor initializes all fields (name, ID, department, position).
Employee(string empName, int empId, string empDept, string empPos)
{
name = empName;
idNumber = empId;
department = empDept;
position = empPos;
}

// This constructor initializes only the name and ID, leaving department and position empty.
Employee(string empName, int empId)
{
name = empName;
idNumber = empId;
department = "";
position = "";
}

// This default constructor sets all fields to default values.


Employee()
{
name = "";
idNumber = 0;
department = "";
position = "";
}

// These functions let you change the value of each field.


void setName(string empName) { name = empName; }
void setIdNumber(int empId) { idNumber = empId; }
void setDepartment(string empDept) { department = empDept; }
void setPosition(string empPos) { position = empPos; }

// These functions let you retrieve the value of each field.


string getName() const { return name; }
int getIdNumber() const { return idNumber; }
string getDepartment() const { return department; }
string getPosition() const { return position; }
};

int main()
{
// Create three Employee objects with the required data.
Employee emp1("Susan Meyers", 47899, "Accounting", "Vice President");
Employee emp2("Mark Jones", 39119, "IT", "Programmer");
Employee emp3("Joy Rogers", 81774, "Manufacturing", "Engineer");

// Display each Employee's information on the screen.


cout << "Name\t\tID Number\tDepartment\t\tPosition\n";
cout << emp1.getName() << "\t" << emp1.getIdNumber() << "\t\t"
<< emp1.getDepartment() << "\t" << emp1.getPosition() << endl;

cout << emp2.getName() << "\t" << emp2.getIdNumber() << "\t\t"


<< emp2.getDepartment() << "\t\t" << emp2.getPosition() << endl;

cout << emp3.getName() << "\t" << emp3.getIdNumber() << "\t\t"


<< emp3.getDepartment() << "\t" << emp3.getPosition() << endl;

return 0;
}

You might also like