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
  • Write a class named Employee that holds the following data about an employee in attributes: name,...

    Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Don't include a constructor or any other methods. Written in Python and formatted like it says below!!!!! Once you have written the class, write a program that creates three Employee objects to hold the following data: Name ID Number Department Job Title Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineering...

  • 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...

  • 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...

  • 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...

  • 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...

  • Part 1 (employee.py): Write a class name Employee that holds the following data about an employee...

    Part 1 (employee.py): Write a class name Employee that holds the following data about an employee in attributes:name, ID number, department and job title. Once you have written the class, write a program that creates three Employee objects to hold the following data: The program should store this data in the three objects, then display the data for each employee on the screen as a table like this (Use fstring or "format" function to format the output as a table,...

  • 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...

  • C++ 8. Circle Class Write a Circle class that has the following member variables: • radius:...

    C++ 8. Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area...

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