0

Hi there,

I was wondering if anyone can help me out here...This is what I have so far:

#include<iostream.h>
#include<conio.h>
class Employee
{
private:
	int idNum;
	char name[20];
	double rate;
public:
	Employee(const int id); //The Constructor with Arguments
	Employee();//The Default Constructor
	void displayValues();
};
Employee::Employee(const int id)
{
	idNum = id;
	cout<<"Enter the employee's last name";
	cin>>name;
	cout<<"What is the hourly rate for this employee?";
	cin>>rate;
}
Employee::Employee()
{
	idNum = 0;
	cout<<"Enter the last namd of this contractual worker";
	cin>>name;
	cout<<"What is the fee for this contract?";
	cin>>rate;
}
void Employee::displayValues()
{
	cout<<"Employee "<<name<<" rate $"<<rate;
	if(idNum == 0)
		cout<<" for this contract"<<endl;
	else
		cout<<" per hour"<<endl;
}

Now, I'm suppose to include an additional function GetValues that will get the values for an employee from the user.
Include an additional member function to overload the assignment operator (=)
Include an additional member function to overload the addition operator (+)
//This operator will return an item of type employee whose idnum is 0 and
// Whose salary is the sum of the two employee salaries being added.

Include A Friend overload function to be able to cout an employee.


If anyone can help me with this, that would be great. I'll be working on it in the meantime....

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by HelpMeImLost
0

cosider this, but i think even after implimenting this re defition of class u will not able to solve all of ur problems, although it contains answer of both of ur questions.

class Employee
{
private:
	int idNum;
	char name[20];
	double rate;
public:
                Include an additional member function to overload the addition operator (+)
	Employee operator + (const Employee obj) {
		Employee temp ;
		temp.idNum = 0;
		temp.rate = this->rate + obj.rate ;
		return temp;
	}
                //Include an additional member function to overload the assignment operator (=)
	Employee & operator = (const Employee &obj) {
		this->idNum = obj.idNum;
		this->rate =  obj.rate ;
		strcpy(this->name,obj.name);
		return *this;
	}
	Employee(const int id); //The Constructor with Arguments
	Employee();//The Default Constructor
	void displayValues();
};
0

I dunno I'm just learning this. But I might do something like so:-

#include <iostream>
#include <string>
using namespace std;

class Employee
{
public:
Employee(); //The Constructor
~Employee();//The Default destructor
//void displayValues();
void Set(int,string,double);
int Num();
string Name();
double Rate();
//overloaded operators
Employee operator=(Employee); //Overloaded = operator
Employee operator+(Employee); //overloaed + operator
//ostream &operator<<( ostream &output );
// cout an employee yet to be implemented!!
private:
int idNum;
string name;
double rate;
};
/** Default constructor,initialises the
* three variables
*/
Employee::Employee()
{
idNum = 0;
name = "";
rate = 0;
}
/** Employee destructor
*/
Employee::~Employee()
{
//
};
/** Overloaded operators+
*/
Employee Employee::operator=(Employee e) {
idNum = e.Num();
name = e.Name();
rate = e.Rate();
return *this;
}
Employee Employee::operator+(Employee e)
{
Employee tmp;
double new_wage;
new_wage = rate + e.Rate();
tmp.Set(idNum,name,new_wage);
return tmp;
}

void Employee::Set(int id, string person, double wage) {
idNum = id;
name = person;
rate = wage;
}
double Employee::Rate() {
return rate;
}
int Employee::Num() {
return idNum;
}
string Employee::Name() {
return name;
}

int main()
{
Employee a,b,c;

a.Set(282,"Chump",4.57);
b.Set(147,"faggot",2.50);
c = a + b;
cout<<"That total wage of "<<a.Name()<<" and "<<b.Name();
cout<<" is $";
cout<<c.Rate();
//cout<<a.Rate();

//getchar();
getchar();
return 0;
}

http://img476.imageshack.us/img476/5171/cut20ln.png
Piworld ™
Tis simple as Pie

Edited by Dani: Formatting fixed

0

Thank you both for your help. I will show you what i have as my final draft when its done.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.