Computing.Net > Forums > Programming > A little nudge

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

A little nudge

Reply to Message Icon

Name: viginti.tres
Date: May 6, 2009 at 17:47:58 Pacific
OS: Windows XP
Product: Dell / XPS 400
Subcategory: C/C++
Comment:

Create a class called Employee with the following characteristics.
There should be 5 private data types ID (unsigned int), Last name
(string), first name (string), and hourly rate (float), and total
salary earned (float).
There should be 1 constructor that takes 4 arguments and populates the
class data. It should be robust by ensuring that the hourly rate is
above the minimum wage of $7.15/hour
Create Get and Set methods to change of the 4 variables.
Create a method 'float Pay( float nHours )' that returns the pay
received by multiplying the hourly rate by the number of hours worked.
This method should also add this value to a variable storing the total
salary earned.
Create a method to get the total amount of salary earned.
Your main file should demonstrate that all methods and that they are
working correctly.

#ifndef FINAL_H
#define FINAL_H


class Employee
{
private:
	unsigned int ID;
	string LastName;
	string FirstName;
	float HourlyRate;
	float salary;

public:

	Employee(); // default constructor

	Employee(int, string, string, float);
	

	void setID(int num) { ID = num ;}
	void setLastName(string last) { LastName = last; }
	void setFirstName(string first) { FirstName = first; }
	void setHourlyRate( float rate) { HourlyRate = rate; }

	float Pay( float nHours );

	void Print();


	int getID() { return ID; }
	float getHourlyRate();
	float getSalary();
	

};

#endif

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



void main(void)
{
	Employee guy_two;

	guy_two.Print();

	Employee guy(1, "Bell", "Stephen", 7.05);

	

	cout<<endl;

	guy.setFirstName("Joe");
	guy.setLastName("Player");
	guy.setHourlyRate(7.25);
	guy.setID(22);

	guy.Print();

	cout<<"pay earned for work:  "<<guy.Pay(30)<<endl;

	cout<<guy.getSalary()<<endl;



	return;
}

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

using namespace std;

Employee::Employee()
{
	ID = 0;
	LastName = "no";
	FirstName = "name";
	HourlyRate = 0;
	
}

Employee::Employee(int ID, string LastName, string FirstName, float rate)
{
		float min = 7.15;

	if (rate < min)
		rate = 7.15;
	else
		HourlyRate = rate;

	this->ID = ID;
	this->LastName = LastName;
	this->FirstName = FirstName;
	HourlyRate = rate;


}

float Employee::Pay(float hours)
{
	float pay;
	float salary = 0;

	pay = HourlyRate*hours;

	salary += pay;

	return pay;
}

float Employee::getSalary()
{

	return salary;
}

float Employee::getHourlyRate()
{
	
	return HourlyRate;
}


void Employee::Print( )
{
	
	cout << "Hourly rate:  "<<HourlyRate << endl;
	cout << "ID number:  "<< ID << endl;
	cout << LastName<<", "<<FirstName << endl;
	
}


I have written all this code myself, and now the problem I'm having is with the part about: "This method should also add this value to a variable storing the total
salary earned.
Create a method to get the total amount of salary earned." I can't figure out how to do this part. I'm an ME not CS but this is an entry level course required in my major... I do enjoy programming though :)



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch file for Internet E... echo vbs code but errors,...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: A little nudge

Make me a little program, please www.computing.net/answers/programming/make-me-a-little-program-please/3342.html

A little web browsers I made www.computing.net/answers/programming/a-little-web-browsers-i-made-/11045.html

Script to remove lines from a file www.computing.net/answers/programming/script-to-remove-lines-from-a-file/7090.html