In: Computer Science
The requirements for this program are as follows:
Private members
a std::string for the employee’s first name
a std::string for the employee’s last name
an unsigned int for the employee’s identification number
a std::string for the city in which the employee works
Public members
A constructor that takes no arguments
A constructor that takes two arguments, representing:
A constructor that takes three arguments, representing:
A constructor that takes four arguments, representing:
A method named displayDetails() that takes no parameters, returns void, and is marked as const.
The displayDetails() method should display to the screen all of the information contained in the employee’s private data members.
All constructors should use constructor initializers to set the employee’s string data members. If a particular string is unknown (i.e., it’s not being passed into that constructor), set it to “unknown”.
For the two constructors that do not accept an argument for the identification number, use constructor initializers to set the identification number to 0.
Finally, write a simple driver file with a main() function. (An example is provided below; you may use this code but I'd recommend creating your own, for the sake of practice.) Inside main(), create at least six Employee objects by invoking the four different constructors. These objects should invoke the four different constructors and test the validity-checking of the identification number (so there will be two objects that invoke the three-argument constructor -- one of them should pass an invalid identification number, and the other should pass a valid number... followed by the same procedure for the four-argument constructor). For each object, invoke the displayDetails() method to test your program.
Example driver and output from that driver:
//inside Source.cpp
#include <iostream>
#include "Employee.h"
using namespace std;
int main()
{
Employee a;
Employee b{ "Robert", "Childan" };
Employee c{ "Nobusuke", "Tagomi", 83179391 };
Employee d{ "Ed", "McCarthy", 1 };
Employee e{ "Frank", "Frink", 73641933, "San
Francisco" };
Employee f{ "Juliana", "Frink", 2, "Canon City" };
a.displayDetails();
b.displayDetails();
c.displayDetails();
d.displayDetails();
e.displayDetails();
f.displayDetails();
}
//output from above driver
Employee Details:
First name: unknown
Last name: unknown
ID: 0
Office location: unknown
Employee Details:
First name: Robert
Last name: Childan
ID: 0
Office location: unknown
Employee Details:
First name: Nobusuke
Last name: Tagomi
ID: 0
Office location: unknown
Employee Details:
First name: Ed
Last name: McCarthy
ID: 1
Office location: unknown
Employee Details:
First name: Frank
Last name: Frink
ID: 0
Office location: San Francisco
Employee Details:
First name: Juliana
Last name: Frink
ID: 2
Office location: Canon City
///////////////////////////
Language: C++
Please ask questions if inftructions are unclear
The relevant comments have been added
This is what the header file will look like:
//header file
//Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee
{
private:
string first_name;
string last_name;
unsigned int employee_id;
string loaction;
public :
//Default Constructor
Employee();
//Constructor with two arguments
Employee(const string firstName, const string lastName);
//Constructor with three arguments
Employee(const string firstName, const string lastName, unsigned int id);
//Constructor with four arguments
Employee(const string firstName, const string lastName, unsigned int id, const string city);
// Print a description of object
void displayDetails() const;
};
#endif
---------------------------------------------------------------------------
// Implementation File for the Employee class
#include <iostream>
#include "Employee.h"
using namespace std;
// Employee constructor
Employee::Employee()
{
first_name="unknown";
last_name="unknown";
employee_id=0;
location="unknown";
}
//Constructor with two arguments
Employee::Employee(string firstName,string lastName)
{
first_name=firstName;
last_name=lastName;
employee_id=0;
location="unknown";
}
//Constructor with three arguments
Employee::Employee(string firstName,string lastName, unsigned int id){
first_name=firstName;
last_name=lastName;
if(id<100000000)
employee_id=id;
else
employee_id=0;
//shorter format
// employee_id=(id<100000000)?id:0;
location="unknown";
}
//Constructor with four arguments
Employee::Employee(string firstName,string lastName, unsigned int id,string city){
first_name=firstName;
last_name=lastName;
if(id<100000000)
employee_id=id;
else
employee_id=0;
location=city;
}
// Employee member function
void Employee :: displayDetails() const
{
cout<<"Employee Details:"<<endl;
cout<<"First Name: "<<first_name<<endl;
cout<<"Last Name: "<<last_name<<endl;
cout<<"ID: "<<employee_id<<endl;
cout<<"Office location: "<<location<<endl;
}