Help please.

I am trying to write a program that asks for a first name, last name, and salary. I have got it to ask for first name and last name, but I cannot seem to introduce salary as an integer variable in the class definition. I have tried it a bunch of different ways and I keep getting errors.
I am sure your program is quite small, why don't you post the program.
Last edited on
1
2
3
string firstName, lastName;
int salary;
cin >> firstName >> lastName >> salary;
#include "stdafx.h"
#include <iostream> // allows basic input\output
#include <string> // allows string class
using namespace std; // sets namespace to std

// Employee class defintion
class Employee
{

public: // sets function to public

void displayFirstName( string fname ) // function header
{
cout << endl; // starts new line
cout <<"Employee's first name is: " << fname << endl; // displays employee's first name
cout << endl; // starts a new line
} //end function displayFirstName

public: // sets function to public

void displayLastName( string lname ) // function header
{
cout << endl; // starts new line
cout << "Employee's last name is: " << lname << endl; // displays employee's last name
cout << endl; // starts a new line
} // end function display LastName


}; // end class Employee
int _tmain(int argc, _TCHAR* argv[])


{

string firstName; // characters used to store FirstName
Employee myEmployee; // create an object named myEmployee
cout << "Enter employee's first name: " << endl; // asks user for First Name
cout << endl; // starts new line
getline( cin, firstName ); // reads a line of text
myEmployee.displayFirstName( firstName ); // calls function display FirstName


string lastName; // characters to store LastName
cout << "Enter employee's last name: " << endl; // asks user for Last Name
cout << endl; // starts new line
getline(cin, lastName ); // reads a line of text
myEmployee.displayLastName( lastName ); // calls function display LastName

return 0;
} // end main

This is what I have so far. I have tried introductin salary at the very beginning under the includes, at the beginning of the class definition and even at the beginning of the main function. I do know that it has to be introduced in the class definition

Code tags man...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "stdafx.h"
#include <iostream> // allows basic input\output
#include <string> // allows string class
using namespace std; // sets namespace to std

// Employee class defintion
class Employee
{

public: // sets function to public

void displayFirstName( string fname ) // function header
{
cout << endl; // starts new line
cout <<"Employee's first name is: " << fname << endl; // displays employee's first name
cout << endl; // starts a new line
} //end function displayFirstName

public: // sets function to public

void displayLastName( string lname ) // function header
{
cout << endl; // starts new line
cout << "Employee's last name is: " << lname << endl; // displays employee's last name
cout << endl; // starts a new line
} // end function display LastName


}; // end class Employee
int _tmain(int argc, _TCHAR* argv[])


{

string firstName; // characters used to store FirstName
Employee myEmployee; // create an object named myEmployee
cout << "Enter employee's first name: " << endl; // asks user for First Name
cout << endl; // starts new line
getline( cin, firstName ); // reads a line of text
myEmployee.displayFirstName( firstName ); // calls function display FirstName


string lastName; // characters to store LastName
cout << "Enter employee's last name: " << endl; // asks user for Last Name
cout << endl; // starts new line
getline(cin, lastName ); // reads a line of text
myEmployee.displayLastName( lastName ); // calls function display LastName

return 0;
} // end main 
Last edited on
Thanks, everybody. It was really easy. I was putting it in the wrong spot.
Now I am having trouble with a constructor for this code. Any ideas??
What would you want to do with it?
Topic archived. No new replies allowed.