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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
// Main
#include<iostream>
#include "Employee.h"
using namespace std;
// Function prototype
void displayEmployee(Employee);
int main()
{
// Create three Employee objects.
Employee susan("Susan Meyers", 47899, "Accounting", "Vice President");
Employee mark("Mark Jones", 39119);
Employee joy;
//Display each employee's data.
cout << "Here is each employee's data:\n";
displayEmployee(susan);
displayEmployee(mark);
displayEmployee(joy);
// Using the mutator functions to update the mark and joy objects.
mark.setDepartment("IT");
mark.setPosition("Programmer");
joy.setName("Joy Rogers");
joy.idNumber(81774);
joy.setDepartment("Manufacturing");
joy.setPosition("Engineer");
// Display each employee's data again
cout << "\nEmployee data after updating:\n";
displayEmployee(susan);
displayEmployee(mark);
displayEmployee(joy);
system("pause");
return 0;
}
//employee.cpp
// Implementation file for the Employee class
#include"Employee.h"
using namespace std;
// This constructor accepts argument for the employee's name, ID number, department, and position.
Employee::Employee(string n, int id, string dept, string pos)
{
name = n;
idNumber = id;
department =dept;
position =pos;
}
// This constructor accepts arguments for the employee's name and ID number. The
// department and position member variables are assigned empty strings.
Employee::Employee(string n, int id)
{
name = n;
idNumber = id;
department = "";
position = "";
}
// The default constructor assigns empty strings to the name, department, and position
// member variables. The idNumber member variable is assigned 0.
Employee::Employee()
{
name = "";
idNumber=0 ;
department = "";
position = "";
}
// Mutator function for the name.
void Employee::setName(string n)
{
name = n;
}
// mutator function for the Id Number.
void Employee::setIdNumber(int id)
{
idNumber = id;
}
// mutator function for the department
void Employee::setDepartment(string dept)
{
department = dept;
}
// mutator function for the position
void Employee::setPosition(string pos)
{
position = pos;
}
// Accessor function for the name.
string Employee::getName() const
{
return name;
}
int Employee::getIdNumber() const
{
return idNumber;
}
// Accessor function for Department
string Employee::getDepartment() const
{
return department;
}
// Accessor function for Position
string Employee::getPosition() const
{
return position;
}
//Employee.h
// Employee project
// Written by Paul Michael
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include<string>
using namespace std;
class Employee
{
private:
string name; //The employee's name
int idNumber; //ID number of employee
string department; // Department name
string position; // Job title
public:
// Constructors
Employee(string, int, string, string);
Employee(string, int);
Employee();
// Mutators
void setName(string);
void setIdNumber(int);
void setDepartment(string);
void setPosition(string);
// Accessors
string getName() const;
int getIdNumber() const;
string getDepartment() const;
string getPosition() const;
};
#endif
|