172k views
0 votes
Write a class named Employee that has the following member variables:

a) name—a string that holds the employee’s name
b) idNumber—an int variable that holds the employee’s ID number
c) department—a string that holds the name of the department where the employee works
d) position—a string that holds the employee’s job title
The class should have the following constructors:
1. A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name, employee’s ID number, department, and position.

1 Answer

2 votes

Final answer:

To create the Employee class with member variables and constructors, define the class and its member variables using C++.

Step-by-step explanation:

One approach to creating the Employee class with the given member variables and constructors is to define the class and its member variables in C++:

class Employee {
private:
std::string name;
int idNumber;
std::string department;
std::string position;

public:
Employee(std::string empName, int empId, std::string empDept, std::string empPos) {
name = empName;
idNumber = empId;
department = empDept;
position = empPos;
}
};

This code creates a class named Employee and defines the private member variables: name, idNumber, department, and position. The class also includes a public constructor that accepts the values for each member variable and assigns them accordingly.

User Micahtan
by
6.9k points