Write a class named Employee that has the following member variables:
• name. A string that holds the employee’s name.
• idNumber. An int variable that holds the employee’s ID number.
• department. A string that holds the name of the department where the employee works.
• position. A string that holds the employee’s job title.
The class should have the following constructors:
• 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.
• A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name and ID number. The department and position fields should be assigned an empty string (“ “);
• A default constructor that assigns empty strings (“ “) to the name, department, and position member variables, and 0 to the idNumber member variable.
Write appropriate mutator functions that store values in these member variables and accessor functions that return the values in these member variables. Once you have written the class, create a three Employee objects (3 separate instances), in your main function, to hold the following data.
Name ID Number Department Position
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
// class declaration
class employee
{
private:
string name;
int idNumber;
string department;
string position;
public:
void setName(string value) { name = value;}
void setidNumber(int value) { idNumber = value;}
void setDepartment(string value) { department = value;}
void setPosition(char);
string getName()const;
string getidNumber()const;
string getDepartment()const;
string getPosition()const;
};
employee emp1();
employee emp2();
employee emp3();
int main()
{
employee emp1( "Susan Meyers", 47899, "Accountng", "Vice President" );
employee emp2( "Mark Jones", 39119, "IT", "Programmer" );
employee emp3( "Joy Rogers", 81774, "Manufacturing", "Engineer" );
return 0;
}
|