Lab 7 - Function Pointers

In this lab, we review the concept of function pointers and how they can be used in OS programming.

Lab Materials

  1. Slides
  2. Material

Assignment

Task-1: Your first task is to complete the comparer function in the func-ptr.c file present in the provided source code. The details of this assignment are provided in the lab slides.

Task-2: Write a program that takes a single character ('0', '1', '2', '3') from the user as input and based on the character; it performs the following operation (on two pre-defined integers):

Please note that you are not allowed to use any conditional statements (e.g. if-else, switch-case, goto etc.) in your program. You must insert your code for this task in the task2.c file included in the lab template.
Expected Output for Task-1

bash$ ./qsort test-data/test1.csv
5 (3, 10)
6 (3, 12)
4 (2, 8)
1 (1, 2)
3 (1, 6)
2 (0, 4)
7 (0, 14)
Expected Output for Task-2

bash$ ./func_ptr
Operand 'a' : 6 | Operand 'b' : 3
Specify the operation to perform (0 : add | 1 : subtract | 2 : Multiply | 3 : divide): 0
Adding 'a' and 'b'
x = 9
bash$ ./func_ptr
Operand 'a' : 6 | Operand 'b' : 3
Specify the operation to perform (0 : add | 1 : subtract | 2 : Multiply | 3 : divide): 1
Subtracting ‘b' from 'a'
x = 3
bash$ ./func_ptr
Operand 'a' : 6 | Operand 'b' : 3
Specify the operation to perform (0 : add | 1 : subtract | 2 : Multiply | 3 : divide): 2
Multiplying 'a' and 'b'
x = 18
bash$ ./func_ptr
Operand 'a' : 6 | Operand 'b' : 3
Specify the operation to perform (0 : add | 1 : subtract | 2 : Multiply | 3 : divide): 3
Dividing 'a' by 'b'
x = 2

Submission

The total grade of this lab is split equally between the two tasks. You must insert your code in the appropriate files in the given template code. The 'make zip' target in the template Makefile should be used to create the archive file for submission on blackboard.





< Back to the Lab Home Page