Object that holds Objects

Hi, I think I have done this correctly. I have created three objects bassed off the employee class, and built them with contructor and named them emp1, emp2, and emp3. Now the requirement is to pass these three objects to a function. I am really new to C++, and have tried to find a way to do this. The function in the code below is called 'Addsomethingup', which totals out a few of the items created after passing some of the information around within each of the objects: Here's my code below. I took out the output section as that works just fine. Any help would be great. Also note when replying to this thread that I have about 8 weeks of part time class experience so you may think that I understand what you are talking about, but in reality I don't - lol - that's why I'm here =).

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <iostream>
#include <string>
#include <iomanip>
#pragma once


using namespace std;

//
//CLASS DECLARATION SECTION
//
class EmployeeClass {
public:
	void ImplementCalculations(string EmployeeName, int hours, double wage);
	void DisplayEmployInformation(string EmployeeName, double basepay, int overtime_hours, double overtime_pay, double iIndividualSalary);
	void Addsomethingup(EmployeeClass Employ1, EmployeeClass Employ2, EmployeeClass Employ3);
	string EmployeeName;
	int hours;
	double wage;
	double basepay;
   	int overtime_hours;
	double overtime_pay;
	double overtime_extra;
	double iTotal_salaries;
	double iIndividualSalary;
	int iTotal_hours;
	int iTotal_OvertimeHours;

	EmployeeClass(string name, int employee_hours, double employee_base_wage): EmployeeName(name), hours(employee_hours), wage(employee_base_wage){}

};

int main()
{	system("cls"); 

	cout << "\nWelcome to the Employee Pay Center\n\n" ;

/*
Use this section to define your objects.  You will have one object per employee.  You have only three employees.
The format is your class name and your object name.
*/

	string emp_name;
	int emp_hours;
	double emp_wage;

	emp_hours = 0;
	emp_wage = 0.0;

	EmployeeClass emp1(emp_name, emp_hours, emp_wage);
	EmployeeClass emp2(emp_name, emp_hours, emp_wage);
	EmployeeClass emp3(emp_name, emp_hours, emp_wage);




	/*first employee enter*/
	cout << "Enter the first employee's name = " << endl;
	cin >> emp1.EmployeeName;
	cout << "Enter the hours worked = " << endl;
	cin >> emp1.hours;
	cout << "Enter his or her hourly wage = " << endl;
	cin >> emp1.wage;
	cout << endl;

	/*second employee enter*/
	cout << "Enter the second employee's name = " << endl;
	cin >> emp2.EmployeeName;
	cout << "Enter the hours worked = " << endl;
	cin >> emp2.hours;
	cout << "Enter his or her hourly wage = " << endl;
	cin >> emp2.wage;
	cout << endl;

	/*third employee enter*/
	cout << "Enter the third employee's name = " << endl;
	cin >> emp3.EmployeeName;
	cout << "Enter the hours worked = " << endl;
	cin >> emp3.hours;
	cout << "Enter his or her hourly wage = " << endl;
	cin >> emp3.wage;
	cout << endl;


/*
Here you will implement a function call to implement the employ calcuations for each object defined above.  You will do this for each of the three employees or objects.
The format for this step is the following:
 [(object name.function name(objectname.name, objectname.hours, objectname.wage)] ;
*/
	emp1.ImplementCalculations(emp1.EmployeeName, emp1.hours, emp2.wage);
	emp2.ImplementCalculations(emp2.EmployeeName, emp2.hours, emp3.wage);
	emp3.ImplementCalculations(emp3.EmployeeName, emp3.hours, emp3.wage);

/*
This section you will send all three objects to a function that will add up the the following information:
- Total Employee Salaries 
- Total Employee Hours
- Total Overtime Hours
The format for this function is the following:
-	Define a new object.
-	Implement function call [objectname.functionname(object name 1, object name 2, object name 3)]
*/	
	

double total_salaries = emp1.iIndividualSalary + emp2.iIndividualSalary + emp3.iIndividualSalary;
	int total_hours = emp1.hours + emp2.hours + emp3.hours;
double total_overtime = emp1.overtime_hours + emp2.overtime_hours + emp3.overtime_hours;

	cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl 
		 << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl
		 << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl
         << "%%%% Total Employee Salaries ..... = " << total_salaries << endl
         << "%%%% Total Employee Hours ........ = " << total_hours << endl
		 << "%%%% Total Overtime Hours......... = " << total_overtime << endl
         << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl
         << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;


	system("pause");

} //End of Main Function




void EmployeeClass::Addsomethingup(EmployeeClass Employ1, EmployeeClass Employ2, EmployeeClass Employ3){



// Adds three objects of class Employee passed as 
// function arguments and saves them as the calling object's data member values. 

/* 
Add the total hours for objects 1, 2, and 3.
Add the salaries for each object.
Add the total overtime hours.
*/

/*
Then display the information below.  

*/
	} // End of function




Sorry the above code was about an hour too old. I was also able to create this array that I thought I might have been able to use:

1
2
3
4
	EmployeeClass *ptr_arr[2];
	ptr_arr[0] = new EmployeeClass(emp1);
	ptr_arr[1] = new EmployeeClass(emp2);
	ptr_arr[2] = new EmployeeClass(emp3);


I think it holds the objects of emp1, emp2, and emp3 in the associated array locations.
EmployeeClass *ptr_arr[2];

This is an array with only two elements: ptr_arr[0] and ptr_arr[1]. When you declare an array, you say how many elements it's going to hold. When you use those elements, you count them from 0 to size - 1.
Last edited on
ahh lol - right - my bad...i totally over looked that. and i wondered why i kept blowing out the array. thanks! I will change that. it was originally three....any ideas how i can pass the three objects emp1, emp2, and emp3 to the function Addsomethingup? that's where i'm really stuck.
Topic archived. No new replies allowed.