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

name: The name attribute holds an employee’s first and last name

idNumber: The idNumber attribute is a string variable that holds an employee’s ID number

department: The department attribute holds the name of the employee’s department

position: The position attribute holds the name of the employee’s job title

yearsWorked: This attribute holds the number of years the employee has worked at the company

The class should have the following overloaded constructors:

• A constructor that accepts the following values as arguments and assigns them to the appropriate data members (attributes): employee’s name and employee’s ID number, employee’s department, employee’s position, and the number of years the employee has worked at the company.

• A constructor that accepts the fallowing values as arguments and assigns them to the appropriate data members (attributes): employee’s name and employee’s ID number. The department and position attributes should be initialized to the empty string (“”) and the yearsWorked attribute should be initialized to zero.

• A default constructor (accepts no arguments) that initializes the name, idNumber, department, and position attributes to the empty string (“”). The yearsWorked attribute should be initialized to zero.

Write Get and Set methods for each attribute: name, idNumber, department, position, and yearsWorked.
• Do not allow the yearsWorked attribute to be set to values less than zero. If an attempt is made to set yearsWorked to less than zero, do not set the attribute and communicate the problem to the calling program. Do not use cin or cout in the set method.

Employee.h – header file
Employee.cpp – Implementation file
EmployeeTest.cpp – Client main application program

1. Instantiate three Employee objects as follows:
Name ID Number Department Position Years Worked
Jenny Jacobs JJ8990 Accounting President 15
Myron Smith MS7571 IT Programmer 5
Chris Raines CR6873 Manufacturing Engineer 30


Hi there, I'm having trouble putting everything together. For instance, I know how to pass by value, but for strings i'm not sure if I'm suppose to pass by reference, use pointers, or include structs. If someone can point me in the right direction, that would be great!

//Class declaration (Employee.h file) contains class attributes and function prototypes.  

#ifndef EMPLOYEE_H

class Employee
{
	private:
		string name;
		string idNumber;
		string department;
		string position;
		int yearsWorked;
		
	public:
		Employee();
		Employee(string n, string id);
		Employee(string n, string id, string dept, string pos, int years);

		void setName();
		void setID();
		void setDept();
		void setPos();
		int setYears();
		
		void getName(string);
		void getID();
		void getDept();
		void getPos();
		int getYears();
};	

#endif
// Class implementation file - Employee.cpp.

#include "Employee.h"
#include <iostream>
using namespace std;

Employee::Employee()
{
	name = "";
	idNumber = "";
	department = "";
	position = "";
	yearsWorked = 0;
}

Employee::Employee(string n, string id)
{
	name = n;
	idNumber = id;
	department = "";
	position = "";
	yearsWorked = 0;
}


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

void Employee::setID(string id)
{
	idNumber = id;
}

void Employee::setDept(string dept)
{
	department = dept;
}

void Employee::setPos(string pos)
{
	position = pos;
}

void Employee::setYears(int years) 
{
	yearsWorked = years;
}
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include "Employee.h"
using namespace std;


/*Client File – EmployeeTest.CPP - Application File*/

int main()
{
	Employee box1, box2, box3;

	Employee box1("JennyJacobs" , "JJ8990" , "Accounting" , "President", 15);
	Employee box2("Myron Smith" , "MS7571", 	"IT", "Programmer", 5);
	Employee box3("Chris Raines" , "CR6873", "Manufacturing" , "Engineer", 30);

	cout << box1.getName() << " " << box1.getID() <<  " " << box1.getDept() << " " << box1.getPos() << " " << box1.getYears() << endl;
	cout << box2.getName() << " " << box2.getID() <<  " " << box2.getDept() << " " << box2.getPos() << " " << box2.getYears() << endl;
	cout << box3.getName() << " " << box3.getID() <<  " " << box3.getDept() << " " << box3.getPos() << " " << box3.getYears() << endl;
			
	system("PAUSE");
	return 0;
}

The assignment doesn't appear to say anything about that the only thing your missing as far as I can tell is the check to make sure yearsWorked can't be set to a value less than zero.

I don't see any problem with your code.. so what exactly is ur complain?

Other than your code not being complete, what you have seems to be spot on. you still have to insert a constructor that accepts all the values and sets the appropriate data members to the values and you still need to make sure your yearsWorked only accepts positive values, but the code you have looks fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.