Question
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- (Employees] Identification Number Department-the name of the department where the employee works Position-the employees 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 the appropriate member variables: Name and ID number. The department and position fields should be assigned empty strings( . . A default constructor that assigns empty strings(to the name, department and position member variables, and 0 to the ID Number Write appropriate mutator functions that store values in these member variables and accessor functions that return the values in these member variables. Once you have designed and written the class, write a separate program that crates three Employee objects to hold the following data: D Number Department 47899 9119 81774 Position Vice President Name Susan Meyers Mark Jones Joy Rogers IT The program should store this data in three objects and also display them. Please submit the following: 1. Your analysis What data member(s) and data types will you use to model the Employee attribute(s) a. 2. Your UML 3. Your source code, the entire project including all cpp and h files 4. The program output CIS-2541 C++ Language Programming Homework Ch. 13-Employee Class Points will be given based on the following requirements: . Program Specifications/ Correctness . Readability . Code Efficiency
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

File: Employee.h

#ifndef EMPLOYEE_H_INCLUDED
#define EMPLOYEE_H_INCLUDED

#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);
};

#endif // EMPLOYEE_H_INCLUDED

File: Employee.cpp

#include<iostream>
#include<string>

#include "Employee.h"

using namespace std;

//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;
}

File: main.cpp

#include <iostream>
#include <iomanip>
#include <string>

#include "Employee.h"

using namespace std;

//Main method
int main()
{
    //Employee array
    Employee emps[3];

    //First object
    Employee e1("Jenny Jacobs", 8890, "Accounting", "President");
    emps[0] = e1;

    //Second object
    Employee e2("Myron Smith", 7571);
    emps[1] = e2;

    emps[1].setDepartment("IT");
    emps[1].setPosition("Programmer");

    //Setting values for third employee object
    emps[2].setName("Chris Raines");
    emps[2].setIdNumber(6873);
    emps[2].setDepartment("Manufacturing");
    emps[2].setPosition("Engineer");

    //Printing header
    cout << endl << left << setw(20) << "Name" << left << setw(20) << "Id Number" << left << setw(20) << "Department" << left << setw(20) << "Position" << endl << endl;

    //Printing data
    for(int i=0; i<3; i++)
    {
        cout << left << setw(20) << emps[i].getName() << left << setw(20) << emps[i].getIdNumber() << left << setw(20) << emps[i].getDepartment() << left << setw(20) << emps[i].getPosition() << endl;
    }

    cout << endl << endl;
    return 0;
}


______________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points...
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,...

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

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

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

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • 1. Write a class named Employee that holds the following data about an employee in attributes:...

    1. Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. (employee.py) 2. Create a UML diagram for Employee class. (word file) 3. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. (employee_App.py) The program should present a menu that lets the user perform the following actions: ✓ Look up an employee in the dictionary ✔ Add a new...

  • Write a Java class named Employee to meet the requirements described in the UML Class Diagram...

    Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • Design a Payroll class with the following fields:

    IN JAVADesign a Payroll class with the following fields:• name: a String containing the employee's name• idNumber: an int representing the employee's ID number• rate: a double containing the employee's hourly pay rate• hours: an int representing the number of hours this employee has workedThe class should also have the following methods:• Constructor: takes the employee's name and ID number as arguments• Accessors: allow access to all of the fields of the Payroll class• Mutators: let the user assign values...

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