Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 20th, 2005, 10:32 PM   #1
nerdfiles
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 nerdfiles is on a distinguished road
Employee Class/Implementation help

#include <iostream.h>

const unsigned LastNameSize = 10;

class Employee {
public:
	Employee E1( long id );
	Employee E2( long id, char lastName, float payRate, int hours );
	long GetId();
	char * GetLastName();
	float GetPayRate();
	int GetHours();
	int CalcGrossPay();
	void Display() const;
	
	int SetHours();
	int SetPayRate();

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

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

private:
	float setpayRate;
	int sethours;
};

My class. ^

#include "employee.h"

Employee::SetHours( int hours )
{
	sethours = hours;
}

Employee::SetPayRate( float payRate )
{
	setpayrate = payRate;
}

Employee::Display() const
{
	cout << "Weekly gross pay: " << CalcGrossPay();
}

Employee::GetLastName()
{
	char lastName[LastNameSize];
	char ch = '\0';
	int i = 0;

	cout << "Enter last name: ";
	while(1)
	{
		cin.get(ch);
		if( ch == '\n') break;
		name[i++] = ch;
	}
	name[i] = '\0';
}

Employee::GetId()
{
	long id;
	cout << "Please enter ID number: ";
	cin >> id;
}

Employee::GetHours()
{
	int hours;
	cout << "Please enter hour amount: ";
	cin >> hours;
}

Employee::GetPayRate()
{
	float payRate;
	cout << "Please enter pay rate: ";
	cin >> payRate;
}

Employee::CalcGrossPay()
{
	return hours * payRate;
}

My implementation of the class. ^

As far as the test program is concerned, I can figure that out on my own. However, the overall goals are to make ways to set and retrieve certain fields, construct and destruct an object made from Employee and to calculate the pay while having the Employee object initialize as either E1 or E2. And just for kicks, =P, the program constructs, initializes and displays the objects, and calculates/displays the gross pay for the week for one employee.

Basically, I've tried my best to do this but I've run into a plethora of syntax errors due to my lack of skills with C++. With that said, here's my error log:

(4): error C2511: 'int Employee::SetHours(int)' : overloaded member function not found in 'Employee'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\useoldio.h(29): warning C4995: '_OLD_IOSTREAMS_ARE_DEPRECATED': name was marked as #pragma deprecated
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\main.cpp(5): error C2065: 'Display' : undeclared identifier
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\useoldio.h(29): warning C4995: '_OLD_IOSTREAMS_ARE_DEPRECATED': name was marked as #pragma deprecated
(9): error C2511: 'int Employee::SetPayRate(float)' : overloaded member function not found in 'Employee'
(14): error C2556: 'int Employee::Display(void) const' : overloaded function differs only by return type from 'void Employee::Display(void) const'
(14): error C2371: 'Employee::Display' : redefinition; different basic types
(15): error C2662: 'Employee::CalcGrossPay' : cannot convert 'this' pointer from 'const Employee' to 'Employee &'
(19): error C2556: 'int Employee::GetLastName(void)' : overloaded function differs only by return type from 'char *Employee::GetLastName(void)'
(19): error C2040: 'Employee::GetLastName' : 'int (void)' differs in levels of indirection from 'char *(void)'
(29): error C2065: 'name' : undeclared identifier
(29): error C2109: subscript requires array or pointer type
(31): error C2109: subscript requires array or pointer type
(35): error C2556: 'int Employee::GetId(void)' : overloaded function differs only by return type from 'long Employee::GetId(void)'
        c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(9) : see declaration of 'Employee::GetId'
(35): error C2371: 'Employee::GetId' : redefinition; different basic types
        c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(9) : see declaration of 'Employee::GetId'
(49): error C2556: 'int Employee::GetPayRate(void)' : overloaded function differs only by return type from 'float Employee::GetPayRate(void)'
(49): error C2371: 'Employee::GetPayRate' : redefinition; different basic types
(57): error C2065: 'hours' : undeclared identifier
(57): error C2065: 'payRate' : undeclared identifier
(57): error C2296: '*' : illegal, left operand has type ''unknown-type''
(57): error C2297: '*' : illegal, right operand has type ''unknown-type''

Any help is greatly appreciated. (=
nerdfiles is offline   Reply With Quote
Old Feb 21st, 2005, 12:13 AM   #2
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
Well, my compiler is being screwy, so i'll look at it more when i get that running again (damn you VS .NET!) but i noticed for your include your using iostream.h which is the old version, now use:
#include<iostream>
using namespace std;
is the easiest way.
Also, in your .cpp file, you didnt specify any return types, which is probably why your getting all those "overloaded function differs only by return type..." errors.

for example:
int Employee::GetHours()

Last edited by ZenMasterJG; Feb 21st, 2005 at 12:16 AM.
ZenMasterJG is offline   Reply With Quote
Old Feb 21st, 2005, 5:38 AM   #3
drewlander
Newbie
 
drewlander's Avatar
 
Join Date: Jan 2005
Location: Pittsburgh, PA
Posts: 16
Rep Power: 0 drewlander is on a distinguished road
Send a message via AIM to drewlander
I dont have time to sit down and compile it but I notice that in your header file you have:
int SetHours();
and in the .cpp you have
Employee::SetHours( int hours )
The parameters should be the same, so they both should be SetHours(int)
Same with SetPayRate
also, before Employee:: you should have the return type of the function too
i.e. void Employee:etHours( int hours ){

for name, in your while loop you just have name[i++], I assume you meant lastname[i++]

That should take care of most of your errors, at least I think. Its 5:30am and ive been working all night, so I hope I'm not too wrong. Good luck!
__________________
On and on....
drewlander is offline   Reply With Quote
Old Feb 22nd, 2005, 1:27 AM   #4
nerdfiles
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 nerdfiles is on a distinguished road
Welp, I'm back again. I've tried a few things and I've found myself even further back than when I started. If you could help, it'd be much appreciated. And yes, I'm thankful for the help I have received. Thanks, people.

Class:
#include <iostream>
using namespace std;

const unsigned LastNameSize = 10;

class Employee {
public:
	Employee E1( long id ); //Construct an employee file from I.D. alone.

	Employee E2( long id, char lastName, float payRate, int hours ); //Construct an
	//employee file from an I.D., last name, pay rate, and number of hours.

	long GetId(); //Get/return employee I.D. number.
	char GetLastName(); //Get/return employee's last name.
	float GetPayRate(); //Get/return employee's pay rate.
	int GetHours(); //Get/return employee's hours.

	float CalcGrossPay( int hours, float payRate); //Calculate and return gross pay.
	
	int SetHours( int hrs ); //Set the number of hours.
	float SetPayRate( float pRate ); //Set the pay rate.

	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.
	int hours; //Number of hours value.
	float payRate; //Pay rate value.
	char name; //Last name value.
};

inline unsigned Employee::GetPayRate() const
{
	return payRate;
}

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

inline unsigned int Employee::GetHours()
{
	return hours;
}

inline int Employee::SetHours( int hrs )
{
	hours = hrs;
}

Implementation:
#include "employee.h"

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

Employee::E2( long id, char lastName, float payRate, int hours )

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

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

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

Error log:
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(12): error C2248: 'Employee::hours' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(4): error C2600: 'Employee::Employee' : cannot define a compiler-generated special member function (must be declared in the class first)
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(5): error C2109: subscript requires array or pointer type
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(10): error C2143: syntax error : missing ',' before '&'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(10): error C2146: syntax error : missing ';' before identifier 'istream'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(10): error C2761: 'Employee Employee::E2(long,char,float,int)' : member function redeclaration not allowed
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(12): error C2248: 'Employee::id' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(12): error C2248: 'Employee::name' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(12): error C2248: 'Employee::payRate' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(16): error C2143: syntax error : missing ',' before '&'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(18): error C2248: 'Employee::id' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(19): error C2248: 'Employee::name' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(20): error C2248: 'Employee::payRate' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.cpp(21): error C2248: 'Employee::hours' : cannot access private member declared in class 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(39): error C2511: 'unsigned int Employee::GetPayRate(void) const' : overloaded member function not found in 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(39): error C2511: 'unsigned int Employee::GetPayRate(void) const' : overloaded member function not found in 'Employee'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(44): error C2371: 'Employee::SetPayRate' : redefinition; different basic types
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(44): error C2371: 'Employee::SetPayRate' : redefinition; different basic types
        c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(21) : see declaration of 'Employee::SetPayRate'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(44): error C2556: 'void Employee::SetPayRate(float)' : overloaded function differs only by return type from 'float Employee::SetPayRate(float)'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(44): error C2556: 'void Employee::SetPayRate(float)' : overloaded function differs only by return type from 'float Employee::SetPayRate(float)'
        c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(21) : see declaration of 'Employee::SetPayRate'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(49): error C2371: 'Employee::GetHours' : redefinition; different basic types
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(49): error C2371: 'Employee::GetHours' : redefinition; different basic types
        c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(16) : see declaration of 'Employee::GetHours'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(49): error C2556: 'unsigned int Employee::GetHours(void)' : overloaded function differs only by return type from 'int Employee::GetHours(void)'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(49): error C2556: 'unsigned int Employee::GetHours(void)' : overloaded function differs only by return type from 'int Employee::GetHours(void)'
        c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\Employee.h(16) : see declaration of 'Employee::GetHours'
c:\Documents and Settings\nerdfiles\My Documents\Projects\C++\PayrollApplication\main.cpp(5): error C2065: 'Display' : undeclared identifier
nerdfiles is offline   Reply With Quote
Old Feb 22nd, 2005, 3:41 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
lots of things are wrong here :/

ostream & operator <<( ostream & os, const Employee E2 & E2)

you cant use the & symbol when declaring a function i dont think, you have to specifiy it as 2 seperate variables and declare then thus.

In your header file you have specified payrate, hours etc as private but then in the class you are trying to access them directly, you will need to use the getter's and setter to access them.

Still going through the file will report back other things.

I looked into it, it is a mess i would think about re-reading up on this stuff you have a lot wrong and personally i cant fix it

Last edited by Berto; Feb 22nd, 2005 at 4:08 AM.
Berto is offline   Reply With Quote
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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC