View Single Post
Old Feb 23rd, 2005, 11:59 PM   #6
nerdfiles
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 nerdfiles is on a distinguished road
Well, now I think I've got the class and implementation down.

Class:
#ifndef EMPLOYEE_H
#define COURSE_H

#include <iostream>
using namespace std;

const unsigned LastNameSize = 30;

class Employee {
public:
	Employee();
	Employee( long idVal, const char *lastNameVal, float payRateVal, float hoursVal ); //Construct an
	//employee file from an I.D., last name, pay rate, and number of hours.

	long const GetId(); //Get/return employee I.D. number.
	char const GetLastName(); //Get/return employee's last name.
	float const GetPayRate() const; //Get/return employee's pay rate.
	float const GetHours(); //Get/return employee's hours.
	float CalcGrossPay( float hours, float payRate); //Calculate and return gross pay.
	float CalcWeekPay( float hours, float payRate);
	
	void SetHours( float hoursVal ); //Set the number of hours.
	void SetPayRate( float payRateVal ); //Set the pay rate.
	void Display() const;

	friend istream & operator >>( istream & input, Employee & E);
	friend ostream & operator <<( ostream & os, const Employee & E);

	~Employee() //Destructor.
	{
		cout << "Employee class destructor called.\n";
	}

private:
	long id; //ID number value.
	char name[LastNameSize]; //Last name value.
	float hours; //Number of hours value.
	float payRate; //Pay rate value.
};

long const Employee::GetId()
{
	return id;
}

char const Employee::GetLastName()
{
	return name[LastNameSize];
}

float const Employee::GetPayRate() const
{
	return payRate;
}

float const Employee::GetHours()
{
	return hours;
}

void Employee::SetPayRate( float payRateVal )
{
	payRate = payRateVal;
}

void Employee::SetHours( float hoursVal )
{
	hours = hoursVal;
}

float CalcGrossPay( float hours, float payRate)
{
	return hours * payRate;
}

float CalcWeekPay( float hours, float payRate)
{
	return hours * payRate * 5;
}

#endif

Implementation:
#include "employee.h"

Employee::Employee()
{
	name[0] = '\0';
}

Employee::Employee( long idVal, const char *lastNameVal, float payRateVal, float hoursVal )
{
	strncpy( name, lastNameVal, LastNameSize );
	payRate = payRateVal;
	hours = hoursVal;
}

istream & operator >>( istream & input, Employee & E )
{
	input >> E.id >> E.name >> E.payRate >> E.hours;
	return input;
}

ostream & operator <<( ostream & os, const Employee & E )
{
	os	<< " I.D.:      " << E.id << '\n'
		<< " Last name: " << E.name << '\n'
		<< " Pay rate:  " << E.payRate << '\n'
		<< " Hours:     " << E.hours << '\n';
	return os;
}

void Employee::Display() const
{
	cout << "I.D.:      " << id << '\n'
		<< " Last name: " << name << '\n'
		<< " Pay rate:  " << payRate << '\n'
		<< " Hours:     " << hours << '\n'
		<< " Pay:       " << CalcWeekPay( float hours, float payRate )
		<< endl;
}

Now I'm just having trouble with displaying my information through the test program. I virtually have nothing but ideas on how I'm supposed to get the information to display which is kind of apparent through my Display() function, lol. But I've grown sore of writing incorrect code that I'm for certain won't work. Here's what I have so far:

#include "employee.h"

int main()
{
	Employee( long idVal, const char *lastNameVal, float payRateVal, float hoursVal)

	cout << "I.D.:      " << id << '\n'
		<< "Last name: " << name << '\n'
		<< "Pay Rate:  " << payRate << '\n'
		<< "Hours:     " << hours << '\n'
		<< "Week Pay:  " << CalcWeekPay()
		<< endl;
}

Any help?

Last edited by nerdfiles; Feb 24th, 2005 at 12:27 AM.
nerdfiles is offline   Reply With Quote