Question

In: Computer Science

The requirements for this program are as follows: Create a header file named “Employee.h”. Inside this...

The requirements for this program are as follows:

  1. Create a header file named “Employee.h”. Inside this header file, declare an Employee class with the following features:
    • 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:

        • the employee’s first name
        • the employee’s last name
      • A constructor that takes three arguments, representing:

        • the employee’s first name
        • the employee’s last name
        • the employee’s identification number
      • A constructor that takes four arguments, representing:

        • the employee’s first name
        • the employee’s last name
        • the employee’s identification number
        • the employee’s city
      • A method named displayDetails() that takes no parameters, returns void, and is marked as const.

  1. Create a source code file named “Employee.cpp” that contains the implementations of the methods described above. Specifically:
    • 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.

    • For the two constructors that accept an argument for the identification number, do not use a constructor initializer to set the identification number. Instead, perform basic validity checking inside the body of the constructor as follows: if the passed-in value is less than 10000000, use the passed-in value to set the employee’s identification number. Otherwise, the identification number should be set to 0. (In other words, we will only allow identification numbers that are at most seven digits long).

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

Solutions

Expert Solution

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;

}


Related Solutions

Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the...
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the requirements for trap.cpp: Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class: Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has...
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program...
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program that performs the following:  Define a function called “Find_Min” that takes an array, and array size and return the minimum value on the array.  Define a function called “Find_Max” that takes an array, and array size and return the maximum value on the array.  Define a function called “Count_Mark” that takes an array, array size, and an integer value (mark) and...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain code and output screenshots. Please use Bubble Sort code provided. Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int readData( int *arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using Notepad) into a one-dimensional array and then analyzes the numbers as described below. Your program must use loops to read the numbers into the array and to analyze the contents of the array. The program’s main function should do the following:  Read eight floating-point numbers from the file named numbers.txt into a onedimensional array, displaying each number on the screen.  Pass the...
II. Big Numbers 1. Implement this program in a file named bigNums.py. 2. Create a numerical...
II. Big Numbers 1. Implement this program in a file named bigNums.py. 2. Create a numerical (integer) list, named numbers. Populate the list with 1,000,000 (one million) integer values with values from 0 to 999,999. Hint: Use the range() function. 3. Print the length of the list to the screen. Ensure you have 1,000,000 items in your list. Hint: Use the len() function. 4. Print the smallest item value in the list to the screen. Hint: use the min() function....
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork class. The features of an ArtWork are: Artist name (e.g. Vincent vanGogh or Stan Getz) Medium (e.g. oil painting or music composition) Name of piece (e.g. Starry Night or Late night blues) Year (e.g. 1837 or 1958)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT