Professional Documents
Culture Documents
Erik Karstens
W2.32
w.f.karstens@saxion.nl
Today’s topics
• Written exam information
• Example exam questions & answers
2 Programming 2 2019-2020
Kom verder. Saxion.
Final grade
Final grade = rounded written exam grade
Example:
Sufficient amount of practical assignments.
Written exam grade = 6.6 (= 7)
Final grade = 7
3 Programming 2 2019-2020
Kom verder. Saxion.
Written exam
It is always possible to do the written exam!
4 Programming 2 2019-2020
Kom verder. Saxion.
• 25 points: Functions
• 25 points: Binary numeral system & operators
• 25 points: Pointers
• 25 points: Characters and strings
5 Programming 2 2019-2020
Kom verder. Saxion.
Written exam
• The exam will be on paper.
• Duration is 2 hours (+ 30 minutes for
students entitled to special exam facilities).
• Only a pen (or pencil) is allowed to use during
the written exam. You are not allowed to use
any tools, books, notes or your laptop.
• An example exam available on Blackboard.
• A reference sheet (see Blackboard at General
information) will be added to the question
papers.
6 Programming 2 2019-2020
Kom verder. Saxion.
Today’s topics
• Written exam information
• Example exam questions & answers
7 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
#include <stdio.h>
#define MAX_GRADES 10
int main()
{
int index;
float entered_value;
unsigned int nr_grades;
float total = 0.0;
unsigned int nr_passed_students = 0;
float average;
8 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
nr_grades = index;
9 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
if (nr_grades > 0)
{
average = total / nr_grades;
}
else
{
average = 0.0;
}
10 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
return 0;
}
11 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
a) Describe the four functional parts within the given source code.
12 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
#include <stdio.h>
#define MAX_GRADES 10
int main()
{
int index;
float entered_value;
unsigned int nr_grades;
float total = 0.0;
unsigned int nr_passed_students = 0;
float average;
13 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
nr_grades = index;
14 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
if (nr_grades > 0)
{ The average of the entered
average = total / nr_grades; grades is calculated.
}
else
{
average = 0.0;
}
15 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
Given the following program:
return 0;
}
16 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
a) Describe the four functional parts within the given source code.
• The entered grades, the average and the number of passed students
are printed in the console.
17 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
b) The parts identified in a) will be written in functions of a new
program. Give the declarations (prototypes) of these functions.
Describe the meaning of each argument and the return value. You
do not have to give the implementation (function body) of the
functions.
The user enters maximum MAX_GRADES grades in the console and can
stop by entering a negative value.
unsigned int enter_grades(void);
18 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
b) The parts identified in a) will be written in functions of a new
program. Give the declarations (prototypes) of these functions.
Describe the meaning of each argument and the return value. You
do not have to give the implementation (function body) of the
functions.
19 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
b) The parts identified in a) will be written in functions of a new
program. Give the declarations (prototypes) of these functions.
Describe the meaning of each argument and the return value. You
do not have to give the implementation (function body) of the
functions.
20 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
b) The parts identified in a) will be written in functions of a new
program. Give the declarations (prototypes) of these functions.
Describe the meaning of each argument and the return value. You
do not have to give the implementation (function body) of the
functions.
The entered grades, the average and the number of passed students
are printed in the console.
void print_results(
unsigned int nr_grades,
float average,
unsigned int nr_passed_students);
21 Programming 2 2019-2020
Kom verder. Saxion.
Open question 1
c) Write the main function of the new program calling the new
functions.
#define MAX_GRADES 10
float grades[MAX_GRADES] = {0.0};
int main()
{
unsigned int nr_grades;
unsigned int nr_passed_students;
float average;
nr_grades = enter_grades();
average = calculate_average(nr_grades);
nr_passed_students = count_nr_passes_students(nr_grades);
print_results(nr_grades, average, nr_passed_students);
return 0;
}
22 Programming 2 2019-2020
Kom verder. Saxion.
Open question 2
Write a program that finds the position of the most significant bit set
to 1 in an unsigned integer.
…
unsigned int num = 20;
if (num == 0)
{
printf("Number is zero. No bits set to 1.\n");
}
else
{
int index;
for (index = -1; num > 0; index++)
{
num = num >> 1;
}
if (num == 0)
{
printf("Number is zero. No bits set to 1.\n");
}
else
{
int index, msb_pos = 0;
for (index = 0; index < sizeof(num) * 8; index++)
{
if((num >> index) & 1) msb_pos = index;
}
Open question 3
Write a function that swaps the values of two variables of the type int.
The function has two arguments to pass the addresses of the variables
(pass by reference). Show the function call to swap the values of the
given integer variables.
…
int x = 1;
int y = 2;
swap(&x, &y);
…
25 Programming 2 2019-2020
Kom verder. Saxion.
Open question 4
A program contains the following string:
Write a program that converts all the letters of this string to uppercase.
Make your program generic such that it can handle other text in the
string, containing other characters and of different sizes.
26 Programming 2 2019-2020
Kom verder. Saxion.
Write a program that converts all the letters of this string to uppercase.
Make your program generic such that it can handle other text in the
string, containing other characters and of different sizes.
27 Programming 2 2019-2020
Kom verder. Saxion.
Write a program that converts all the letters of this string to uppercase.
Make your program generic such that it can handle other text in the
string, containing other characters and of different sizes.
29 Programming 2 2019-2020
Kom verder. Saxion.
Questions
30 Programming 2 2019-2020