Session 2

Examen 2017-2018 - Session 2 - Part B

Part A:test

Getting start code - Part B

Start code: code_session2.tar.gz

Download the start code, upack it and copy the top directory examen_session2 in a new directory, named examen_session2_YourFamilyName. You should develop your solutions in the new directory.

tar xzvf examen_session2.tar.gz
cp -r examen_session2 examen_session2_YourFamilyName
cd examen_session2_YouFamilyName

Task 1: shape

The given code in readShape.cxx is buggy. Correct the compilation warnings, errors and the program behavior. The fixed program should open and read the provided data file up to its end without errors.

Task 2: fourDigits

fourDigits program list all four digits numbers that fulfill the following condition: If you split a four digits number into two parts each having two digits and add the squares of these numbers, you get the original four digit number. For examples:

1233 = 12*12 + 33*33

Complete the three missing parts of the program. These missing parts are preceded with a comment IMPLEMENT.

Task 3: twin

Complete the program twin.cxx. The program should then display the list of twin prime numbers below 100. A twin prime is a prime number that is either 2 less or 2 more than another prime number. Examples:

(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43),…

When the program is completed, increase the number limit to get displayed all twin prime numbers below 1000.

Task 4: points

In this task you get a class Point and a C++ program maximumDistance.cxx. Both the class and the program are completely implemented and working.

The class Point represents a geometrical point in two dimensions (x, y). Extend the class to represent a geometrical point in three dimensions (x, y, z) and adapt the maximumDistance.cxx program to take into account this change.

Your Solution

Pack the code which you developed in a single tar file and send the tar file by e-mail to both teachers:,

Before you leave the room, check with the teachers that they received your code.

tar czvf examen_session2_YourFamilyName.tar.gz examen_session2_YourFamilyName