### Two dimensional array

Im preparing for an exam and Im wondering if anyone can show me an example code for this project:

Stores information on salaries of employees of an enterprise in a two
dimentional array. The company has several departments and each department has
several employees. Define two constants to specify "number of departments" and
"MaxNumEmployees" containing a number of departments in the company and the
maximum number of employees in the department. Store information about salaries of employees in the array. If the number of employees in one department does not reach the maximum limit, -1 is entered after the last employee.

Write a function that receives an array as in a) and the size of the array. The
function creates a dynamic array containing the average salary of employees in each department, and returns a pointer which points at the array.
this should give you an idea:

 ``12345678`` ``````int main() { int size1 = number_of_departments; int size2 = max_number_of_employees; int A[size1][size2] = {{salary_of_worker1_in_department1, salary_of_worker2_in_department1, ...,-1}, ..., {salary_of_worker1_in_department_n, salary_of_worker2_in_department_n,...,-1}}; }``````

now you just need to write the function to calculate the average
Last edited on

@Darkmaster
this should give you an idea:

 ``12345`` ``````int main() { int size1 = number_of_departments; int size2 = max_number_of_employees; int A[size1][size2] =...``````

Your code is not valid C++ code and does not corresponds to the assignment where there is said:

 Define two constants to specify "number of departments" and "MaxNumEmployees" containing a number of departments in the company and the maximum number of employees in the department

So it should be written as

 ``12345`` ``````int main() { const int number_of_departments = 5; /* can be any value */ const int max_number_of_employees = 10; /* can be any value */ float salaries[number_of_departments][max_number_of_employees] = ...``````

it was just to show how the 2d array works in this case. i know that my code won't compile, was just to give him an idea.
Topic archived. No new replies allowed.