Create a class called Employee that includes three pieces of information as data members – a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.

Can you help me solve this Question??

Recommended Answers

All 5 Replies

I think you can start here:

class Employee {
	string FirstName;
	string LastName;
	int MonthlySalary;
	public:
	Employee();
	// if you like, you can also add 'Employee(string firstname, string lastname, int salary);'
	void SetFirstName(string firstname);
	void SetLastName(string lastname);
	void SetSalary(int salary);
	string GetFirstName(void);
	string GetLastName(void);
	int GetSalary(void);
};

Now that you have all the functions declared and data members declared all you have to do is implement the functions. For example you would want the function GetFirstName(void) to return the first name so just impliment them all and you should be done.

Hi there,
Saw your question here, so decided to give you some advice. First, no one is going to spoon feed you any code unless you have made an effort and have got to the point where you are pulling you hair out. Second, Im a beginner in c++, and although I find some parts tricky, I like to find out by myself before approaching anyone on the forum. ie read some books, google it etc.
I have just coded your homework, and found it to be extremely easy, even for me. It is a very straightforward employee example in a nice clean class. Have a go, and if in some difficulty or do not understand something, post your code and then we can help you. If we give you the whole program, you are not really learning anything, nor will you be able to grasp or understand anything. If you have only just started learning classes, you would do well to grasp the basics now as its only going to get more complicated.

Try checking out this site, they have some basic tutorials on c++ plus other languages:
www.warebizprogramming.com

cheers
nm

This should get you started. All you have to do it break it out in to a class.

int main()
{

	double grossPay;
	double salary;
	int employee=2;

	cout << "\n***To Exit, enter zero(0)***";
	cout << "\n\nEnter Gross Sales for employee:";
	cin >> grossPay;
	cout << endl;

	while (grossPay > 0)
	{
		

		salary = (grossPay * .09) + 200;
		cout << "Employees Salary = " << salary;
		cout << endl;

		cout << "\n***To Exit, enter zero(0)***";
		cout << "\n\nEnter Gross Sales for employee #" << employee <<":";
		cin >> grossPay;
		cout << endl;

		employee = employee + 1;

	}

	
	cout << "Goodbye" << endl;
	system("PAUSE");
	return 0;

}

Hi there,
Saw your question here, so decided to give you some advice. First, no one is going to spoon feed you any code unless you have made an effort and have got to the point where you are pulling you hair out. Second, Im a beginner in c++, and although I find some parts tricky, I like to find out by myself before approaching anyone on the forum. ie read some books, google it etc.
I have just coded your homework, and found it to be extremely easy, even for me. It is a very straightforward employee example in a nice clean class. Have a go, and if in some difficulty or do not understand something, post your code and then we can help you. If we give you the whole program, you are not really learning anything, nor will you be able to grasp or understand anything. If you have only just started learning classes, you would do well to grasp the basics now as its only going to get more complicated.

Try checking out this site, they have some basic tutorials on c++ plus other languages:
www.warebizprogramming.com
cheers
nm

Thank you so much for your advice :D but the thing was i've never written a class before and i dont even know how to start ,, thats why i didnt give it a shot, i guess!
Thanks again :)
see you around..

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.