$30
COEN 243
Assignment 4 – Two Dimensional Arrays/Strings/User‐Defined Classes
Group Assignment
This assignment is worth 5% of your final grade
Submission instructions:
- Provide comments for your code
- Compress the files using zip or other tools
- Submit the zip file on Moodle
- Do not submit executable files
- All submissions must be done through Moodle
Questions:
Q1. (30 marks) Write a C++ program to add the elements on the two diagonals of a square two‐
dimensional integer array and display that sum. Ensure that if there is a middle element in the array it is
not counted twice in the sum.
For example, with the array:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
your program should display 68 (1+6+11+16+4+7+10+13).
With the array:
1 2 3
5 6 7
9 10 11
your program should display 30 (1+6+11+3+9) (note that the 6 is not counted twice).
Q2. (35 marks) We want to create a class called Employee, which represents the employees of a
department at the univerity. An employee is defined with the following attributes: employee id (int),
first name (string), last name (string), date of birth (string), address (string), year hired (int), salary
COEN 243 – Summer 2023
2/3
(double) and telephone (area code (int) and 7‐digit telephone number(string). The member functions of
the class Employee must perform the following operations:
Return the employee id number.
Return the first name of the employee
Modify the first name of the employee
Return the last name of the employee
Modify the last name of the employee
Return the hired year of the employee
Return the full name, i.e., first name and last name
Return the date of birth
Modify the date of birth
Return the salary of the employee
Modify the salary of the employee
Return the address of the employee
Modify the address of the employee
Return the telephone number
Modify the telephone number
Return true if two given employees have the same last name. Return false otherwise
Return true if two employees have the same salary or they were hired on the same year. Return
false otherwise
Test your class by prompting the user to enter information about two particular employees. Create two
objects of the class Employee with the information entered by the user, and finally, and test the
member functions of the class.
Deliverables:
A file called employee.h that contains the specification of the class.
A file called employee.cpp that contains the implementation of the member functions of the
class.
A file called testemployee.cpp that contains the main function.
Q3. (35 marks) We want to create a class called Department, which represents the information of a
department at the university. A department is defined with the following attributes: identification
number (string), name (string), department history (string), and a list of employees worked in the
department (array of type Employee from previous question). You can assume that a department
cannot have more than 25 employees. The member functions of the class Department must perform
the following operations:
Return the department identification number
Return the department name
Modify the department name
Return the department history
Modify the department history
Add a new employee to the department
Remove one employee from a department
COEN 243 – Summer 2023
3/3
Search if an employee with a certain employee id works in the department
Output list of employees
Output the number of employees
Test your class by prompting the user to enter information about one of the university department and
five employees. Create the department object and five objects of the class Employee. Assign the
employees to the department. Test the member functions of the class.
Deliverables:
A file called employee.h that contains the specification of the class.
A file called employee.cpp that contains the implementation of the member functions of the
class.
A file called department.h that contains the specification of the class.
A file called department.cpp that contains the implementation of the member functions of the
class.
A file called testdepartment.cpp that contains the main function.