Use this header file to answer the question: class Employee { public: Employee(c
ID: 664573 • Letter: U
Question
Use this header file to answer the question:
class Employee
{
public:
Employee(const char n[]); // constructor
Employee(const Employee &x); // copy constructor
~ Employee(); // destructor
void AddEmployee(int id); // adds one Employee ID to the list
void Display() const; // prints out the Employee list info
private:
int * EmployeeList; // pointer to a dynamic array of Employee ID's
int size; // number of Employee IDs currently stored
char name[21]; // fixed storage for employee name (c-string)
};
An object of type Employee sotres an employee name as a c-string and a list of employee ID's(integers)
that the employee has. The list of employee ID's is to be allocated dynamically. The allocation for the list of course ID's should always be exactly what is needed for the current number of employee ID's in storage. Write the definitions for the functions above as they would appear in the student.cpp file.
Description of each function's job:
Constructor: Take in an employee name as a c-string. Initialize the member data so that this name is stored in the object (as a c-string), and initialize the list of employee ID's to represent an empty list. If the employee name is toolong for the available storage, then store as much of it as will fit.
Copy Constructor: Should make an appropriate copy of a Employee object (deep copy).
Destructor: Final cleanup of any dynamic allocation inside the object.
AddEmployee: Takes in one employee ID as a parameter. Store that value in the internal list of employee ID's, in the next available slot.
Display: This should print the employee name, and then the employee ID's as a comma-separated list, in the format shown below. If there are no ID's yet, print "no ID's" after the name instead.
Examples: John Doe: 454343, 857843, 5763883, 848473, 443
Name Johnson: no ID's
Explanation / Answer
#include<iostream.h>
#include<iomanip.h>
#include<fstream.h>
#include<string.h>
#include"employee.h"
class Employee
{
public:
Employee(const char n[] ); // constructor
Employee(const Employee &x); // copy constructor
~ Employee(); // destructor
void AddEmployee (int id); // adds one Employee ID to the list
void Display() const; // prints out the Employee list info
private:
int * EmployeeList; // pointer to a dynamic array of Employee ID's
int size; // number of Employee Ids currently stored
char name[21]; // fixed storage for employee name (c-string)
In.open("datafile.dat");
In >> NewName;
while(strcmp(NewName,"done")!=0)
{
cout<<" To Display employee name and employee ID's";
cout<<"To print employees name and employees ID's";
cout<<"Exit";
cin>>get;
switch(get)
{
case 'A' : result.Addemployee(); break;
case 'B' : result.Addemployee name(); break;
case 'C' : result.Addemployee ID's();
break;
}
In >> NewDepartment >> NewSalary;
Employee *NewEmployee = new Employee(NewName,NewDepartment,NewSalary);
List->Add(NewEmployee);
In>>NewName;
}
In.close();
}
"datafile.dat"
John Doe 454343
John Doe 857843
John Doe 5763883
John Doe 848473
John Doe 443
Johnson no ID's
done x 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.