Question

Write a C++ program Write a class named Employee that has the following member variables: name...

Write a C++ program

Write a class named Employee that has the following member variables:

  • name A string that holds the employee name
  • idNumber An int to hold employee id number
  • department A string to hold the name of the department
  • position A string to hold the job position

The class will have three constructors:

1. A constructor that accepts all the internal data such as:

Employee susan("Susan Meyers", 47899, "Accounting", "Vice President");

2. A constructor that accepts some of the information and assigns an empty string to the missing data such as:

Employee mark("Mark Jones", 39119);

Then the missing data will be filled in by mutator member functions.

3. A constructor that accepts no information ( the default constructor ) such as:

      Employee joy;

Then the missing data will be filled in by mutator member functions.

Write the appropriate mutator and accessor functions for all the data of the Employee class. See below for the names to use for these functions. Examples would be setPosition and getPosition etc…

Write a member function of the Employee class to display all the information in the class called displayEmployee

Then use the following driver program to test your class:

// Driver program to demonstrate the class

int main()

{

   // Create an Employee object to test constructor #1.

   Employee susan("Susan Meyers", 47899, "Accounting", "Vice President");

  

   // Create an Employee object to test constructor #2.

   Employee mark("Mark Jones", 39119);

   mark.setDepartment("IT");

   mark.setPosition("Programmer");

   // Create an Employee object to test constructor #3.

   Employee joy;

   joy.setName("Joy Rogers");

   joy.setIdNumber(81774);

   joy.setDepartment("Manufacturing");

   joy.setPosition("Engineer");

  

   // Display each employee's data.

   displayEmployee(susan);

   displayEmployee(mark);

   displayEmployee(joy);

   system(“pause”);

   return 0;

}//end main

Sample output:

Name: Susan Meyers

ID Number: 47899

Department: Accounting

Position: Vice President

Name: Mark Jones

ID Number: 39119

Department: IT

Position: Programmer

Name: Joy Rogers

ID Number: 81774

Department: Manufacturing

Position: Engineer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

#include <iostream>
#include <string>

using namespace std;

//Class definition
class Employee
{
private:
//Data members
string name;
int idNumber;
string department;
string position;
public:

//Constructors
Employee(string n, int id, string dept, string pos);
Employee(string n, int id);
Employee();

//Getter methods
string getName();
int getIdNumber();
string getDepartment();
string getPosition();

//Setter methods
void setName(string);
void setIdNumber(int);
void setDepartment(string);
void setPosition(string);
};

//Setter Methods
void Employee::setPosition(string p)
{
position = p;
}

void Employee::setDepartment(string d)
{
department = d;
}

void Employee::setIdNumber(int id)
{
idNumber = id;
}

void Employee::setName(string n)
{
name = n;
}


string Employee::getPosition()
{
return position;
}

string Employee::getDepartment()
{
return department;
}

int Employee::getIdNumber()
{
return idNumber;
}

string Employee::getName()
{
return name;
}

//Default Constructor
Employee::Employee()
{
name = "";
idNumber = 0;
department = "";
position = "";
}

//Arg-Constructor
Employee::Employee(string n, int id)
{
name = n;
idNumber = id;
department = "";
position = "";
}

//Arg-Constructor
Employee::Employee(string n, int id, string dept, string pos)
{
name = n;
idNumber = id;
department = dept;
position = pos;
}

//Display function
void displayEmployee(Employee e)
{
cout << "\n\nName: " << e.getName();
cout << "\nID Number: " << e.getIdNumber();
cout << "\nDepartment: " << e.getDepartment();
cout << "\nPosition: " << e.getPosition();
}

// Driver program to demonstrate the class
int main()
{
// Create an Employee object to test constructor #1.
Employee susan("Susan Meyers", 47899, "Accounting", "Vice President");

// Create an Employee object to test constructor #2.
Employee mark("Mark Jones", 39119);
mark.setDepartment("IT");
mark.setPosition("Programmer");
// Create an Employee object to test constructor #3.
Employee joy;
joy.setName("Joy Rogers");
joy.setIdNumber(81774);
joy.setDepartment("Manufacturing");
joy.setPosition("Engineer");

// Display each employee's data.
displayEmployee(susan);
displayEmployee(mark);
displayEmployee(joy);
return 0;
}//end main

______________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
Write a C++ program Write a class named Employee that has the following member variables: name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Create a C# Console program. Add a class named Employee that has the following public fields:...

    Create a C# Console program. Add a class named Employee that has the following public fields: • Name. The name field references a String object that holds the employee’s name. • IDNumber. The IDNumber is an int that holds the employee’s ID number. • Department. The department field is a String that holds the name of the department where the employee works. • Position. The position field is a String that holds the employee’s job title. Once you have written...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // 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...

  • Design and write a class named Employee that inherits the Person class from the previous exercise...

    Design and write a class named Employee that inherits the Person class from the previous exercise and holds the following additional data: ID number, department and job title. Once you have completed the Employee class, write a Python program that creates three Employee objects to hold the following data: Name ID Number Department Job Title Phone Susan Meyers 47899 Accounting Vice President 212-555-1212 Mark Jones 39119 IT Programmer 212-555-2468 Joy Rogers 81774 Operations Engineer 212-555-9753 The Python program should store...

  • Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points...

    Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points Design a class named Employee that has the following attributes: * Name ID Number- (Employee's] Identification Number " Department-the name of the department where the employee works " Position-the employee's job title The class should have the following constructors: A constructor that accepts values for all the member data as arguments A constructor that accepts the following values as arguments and assigns them to...

  • in C++: Create a class named Student that has three member variables: name - string that...

    in C++: Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100. classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • 1) Introduction to Objects (with Constructors and Properties) We need to answer the question which are...

    1) Introduction to Objects (with Constructors and Properties) We need to answer the question which are below. and instruction are given down starting with part(b). Just we need to copy paste code file and follow the instruction and answer related to them. a) Enter the following program.Answer The questions below the codes, Notice that it consists of two classes that will go into the same project. Please put each class into its own code file (use Lab5_1 for the Project...

  • Write a full class definition for a class named Player , and containing the following members: A data member name of t...

    Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...

  • Design a class named Employee. The class should keep the following information in

    WRITE IN C++ ONLY PLEASE. IM USING VISUAL STUDIO CODE.1. Employee and ProductionWorker ClassesDesign a class named Employee. The class should keep the following information in• Employee name• Employee number• Hire dateWrite one or more constructors and the appropriate accessor and mutator functions for the class.Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:• Shift (an integer)• Hourly pay rate (a double )The workday...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT