Lab Assignment 8
Lab Assignment 8
Lab Assignment 8
Lab Instructions
During the lab you should be doing the following things:
1. You need to open any IDE for C on your own laptops.
2. Read the following task carefully and start implementing it.
3. Implement the tasks in separate .c files.
4. During the lab you are allowed to ask for the help from one of our TAs and Instructors.
5. You can discuss the tasks with the classmates and friends during the lab, but you are NOT
allowed to do the tasks instead of each other.
6. During the lab you should finish all the required tasks and submit to Moodle before the
deadline to get the grades.
7. Ensure that your solutions adhere to the material that has been taught before or will be
taught in the current week.
8. The deadline for submission is October 17, Thursday, at 11:00 pm.
9. During the work, please make sure that you save your work frequently.
Lab Exercises
Task 1. Write a C program that reads positive integer numbers from the “number.txt” file and
performs several operations on them that require using recursive functions. Below is the sample content
of the text file. The numbers are separated by single-space. The number of pairs is not restricted, i.e. it
can be less or more than 5 shown below. Therefore, please do not hardcode the number of pairs.
Your program must perform the following operations with these numbers:
For each of the operations above you must create a separate function which will call itself recursively.
You must use recursion for each of the function to get a credit for this lab assignment.
Sample Input/Output:
Note: The contents of the txt file will be restricted only to positive integer numbers. You can also
ignore the issue of exceeding the max value for ints. The pairs of numbers tested during grading will
be selected such that this issue will not happen.
Task 2. Imagine you are working for some company. Your boss asked you to create a C program
that reads a file containing employees’ information, and then given an employee name it must
recursively output the information of the line managers of that employee (a.k.a. boss of that
employee), together with some information about them.
The file provided from the HR manager will be names as “employees.txt” and will contain the
following information:
All entrees in each line are separated by a single space. The format of each line (no title row):
Name of the Employee’s boss Position title Phone number Office number
employee name (can save as int) (can save as int)
You should implement a function that reads this employees list and saves it as Employee structs.
Afterward, you need to write a function with a recursion that prints the hierarchy of line managers
together with some information about them.
The program must ask the name of the employee from the user.
Sample Input/Output: (in italic red is the user input, do not hardcode it)
Example 1:
Type a name of the staff member: Aron
Aron’s position title: Senior. Aron’s phone and office: 601515 205
Example 2:
Type a name of the staff member: Basilius
Basilius’s position title: Senior. Basilius’s phone and office: 701011 108
In this task, you are allowed to external libraries such as string.h and stdbool.h in case you think you
need them.
Note: The contents of the txt file will not contain the same names for different employees. All
employees are assigned only to one boss. Information about the topmost boss (such as Mary in the
example above) will not be tested while grading since there is no information about that employee.
Assume that all other employees will have the full information about them, and all of them have some
line manager (boss). We will test only the names of the employees who do exist in the testcase txt list.