Problem with C++ exercise

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span> 
The exercise says:
( Employee Class) 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 Employees capabilities. Create two Employee objects and display each objects yearly salary. Then give each Employee a 10 percent raise and display each Employees yearly salary again.
 
I need to know if I am heading in the right direction so here is what I have so far: <font color="#008000" size=2>
// ex3.14.cpp : Defines the entry point for the console application.
// </font><font color="#0000ff" size=2>
#include</font><font size=2> </font><font color="#a31515" size=2>"stdafx.h"</font>
<font color="#0000ff" size=2>#include</font><font size=2> </font><font color="#a31515" size=2><iostream> </font><font color="#0000ff" size=2>
using</font><font size=2> std::cout; </font><font color="#0000ff" size=2>
using</font><font size=2> std::cin; </font><font color="#0000ff" size=2>
using</font><font size=2> std::endl; </font><font color="#0000ff" size=2>
#include</font><font size=2> </font><font color="#a31515" size=2><string> </font><font color="#0000ff" size=2>
using</font><font size=2> std::string; </font><font color="#0000ff" size=2>
using</font><font size=2> std::getline; </font><font color="#008000" size=2>
// Employee class definition </font><font color="#0000ff" size=2>
class</font><font size=2> Employee
{ </font><font color="#0000ff" size=2>
public</font><font size=2>:
Employee( string ); </font><font color="#008000" size=2>// constructor that initializes an Employee object </font><font size=2>
</font><font color="#0000ff" size=2>void</font><font size=2> setFirstName( string ); </font><font color="#008000" size=2>// function that sets the first name </font><font size=2>
string getFirstName(); </font><font color="#008000" size=2>// function that gets the first name </font><font size=2>
</font><font color="#0000ff" size=2>void</font><font size=2> displayMessage(); </font><font color="#008000" size=2>// function that displays a message </font><font size=2>
</font><font color="#0000ff" size=2>void</font><font size=2> setLastName( string ); </font><font color="#008000" size=2>// function that sets the last name </font><font size=2>
string getLastName( string ); </font><font color="#008000" size=2>// function that gets the last name </font><font size=2>
</font><font color="#0000ff" size=2>void</font><font size=2> displayMessage(); </font><font color="#008000" size=2>// function that displays a message </font><font size=2>
</font><font color="#0000ff" size=2>int</font><font size=2> salary; </font>

View the full article
 
Back
Top