PLEASE WRITE THE CODE USING THE TEMPLATE GIVEN BELOW. // Chapter 13, Programming
ID: 3837211 • Letter: P
Question
PLEASE WRITE THE CODE USING THE TEMPLATE GIVEN BELOW.
// Chapter 13, Programming Challenge 2: Employee Class
#include <iostream>
#include <string>
using namespace std;
// Employee Class Declaration
class Employee
{
private:
string name; // Employee's name
int idNumber; // ID number
string department; // Department name
string position; // Employee's position
public:
// TODO: Constructors
// TODO: Accessors
// TODO: Mutators
};
// Constructor #1
Employee::Employee(string n, int i, string d, string p)
{
// TODO
}
// Constructor #2
Employee::Employee(string n, int i)
{
// TODO
}
// Constructor #3, default constructor
Employee::Employee()
{
// TODO
}
// Function prototype
void displayEmployee(Employee);
// Driver program to demonstrate the class
int main()
{
// TODO: Create an Employee object to test constructor obj #1.
// TODO: Create an Employee object to test constructor obj #2.
// TODO: Create an Employee object to test constructor obj #3.
// Display each employee's data.
displayEmployee(/** TODO: obj #1 */);
displayEmployee(/** TODO: obj #2 */);
displayEmployee(/** TODO: obj #2 */);
return 0;
}
//**************************************************
// The displayEmployee function displays the data *
// in the Employee object passed as an argument. *
//**************************************************
void displayEmployee(Employee e)
{
// TODO
}
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
// Employee Class Declaration
class Employee
{
private:
string name; // Employee's name
int idNumber; // ID number
string department; // Department name
string position; // Employee's position
public:
// TODO: Constructors
Employee();
Employee(string n, int i, string d, string p);
Employee(string n, int i);
// TODO: Accessors
int getIdNumber() {
return idNumber;
}
string getName(){
return name;
}
string getDepartment() {
return department;
}
string getPosition(){
return position;
}// TODO: Mutators
void setIdNumber(int id){
idNumber = id;
}
void setName(string n) {
name = n;
}
void setDepartment(string d) {
department = d;
}
void setPosition(string p) {
position = p;
}
};
// Constructor #1
Employee::Employee(string n, int i, string d, string p)
{
// TODO
name = n;
idNumber = i;
department = d;
position = p;
}
// Constructor #2
Employee::Employee(string n, int i)
{
// TODO
name = n;
idNumber = i;
}
// Constructor #3, default constructor
Employee::Employee()
{
// TODO
}
// Function prototype
void displayEmployee(Employee);
// Driver program to demonstrate the class
int main()
{
// TODO: Create an Employee object to test constructor obj #1.
Employee e1("Susam Meyers",47899, "Accounting", "Vice Precident");
// TODO: Create an Employee object to test constructor obj #2.
Employee e2("Mark Jones",39119);
e2.setDepartment("IT");
e2.setPosition("Programmer");
// TODO: Create an Employee object to test constructor obj #3.
Employee e3;
e3.setName("Joy Rogers");
e3.setIdNumber(81774);
e3.setDepartment("Manufacturing");
e3.setPosition("Enginner");
// Display each employee's data.
displayEmployee(e1);
displayEmployee(e2);
displayEmployee(e3);
return 0;
}
//**************************************************
// The displayEmployee function displays the data *
// in the Employee object passed as an argument. *
//**************************************************
void displayEmployee(Employee e)
{
// TODO
cout<<e.getName()<<" "<<e.getIdNumber()<<" "<<e.getDepartment()<<" "<<e.getPosition()<<endl;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Susam Meyers 47899 Accounting Vice Precident
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Enginner
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.