Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Using Functions w/ Classes && Saving Data to Class

$
0
0
I've having a decent amount of trouble with classes and objects at the moment. I've looked all around, and I can't really find any sample code that applies directly to what I'm doing. Here is my code:

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

class employee{
private:
	string _name;
	int _idNumber;
	string _department,
		   _position;
	
public:
	employee()
	{
		_name = " ";
		_department = " ";
		_position = " ";
		_idNumber = NULL;
	}

	void setName(string name)
	{
		_name = name;
	}
	string getName(string name)
	{
		name = _name;
		return name;
	}
	void setIdNumber(int idNumber)
	{
		_idNumber = idNumber;
	}
	int getIdNumber(int idNumber)
	{
		idNumber = _idNumber;
		return idNumber;
	}
	void setDepartment(string department)
	{
		_department = department;
	}
	string getDepartment(string department)
	{
		department = _department;
		return department;
	}
	void setPosition(string position)
	{
		_position = position;
	}
	string getPosition(string position)
	{
		position = _position;
		return position;
	}
};
	
 void displayEmployee(employee);

// Driver program to demonstrate the class
int main()
{
   // Create an Employee object to test constructor #1.
   //employee susan("Susan Meyers", 47899, "Accounting", "Vice President");
   
   // Create an Employee object to test constructor #2.
   //employee mark("Mark Jones", 39119);
   //mark.setDepartment("IT");
   //mark.setPosition("Programmer");

   // Create an Employee object to test constructor #3.
   employee joy;
   joy.setName("Joy Rogers");
   joy.setIdNumber(81774);
   joy.setDepartment("Manufacturing");
   joy.setPosition("Engineer");
   
   // Display each employee's data.
   //displayEmployee(susan);
   //displayEmployee(mark);
   displayEmployee(joy);

   system("pause");
   return 0;
}//end main

void displayEmployee()
{
	cout << "Name: " << name << endl << "ID Number: " << idNumber << endl
			<< "Department: " << department << endl << "Position: " << position;
}



The first issue I'm having is figuring out how exactly to store the data I have in comments (line 65 and lines 68-70). Can anyone give me a bit of clarification, or at least point me to some sample code?

The second issue I'm having is calling the information to the function at line 88. I've tried quite a few different things, and no matter how I configure it I can't properly call in the data. Once I get to that point, I'll need to figure out how to sort the data for each 'employee'.

I apologize for all of the questions, but I've had minimal instruction and maximum frustration with this lab, and I still need to finish another after this by tomorrow night. Thanks in advance for any help!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>