Session 1

Examen 2017-2018 - Session 1

Part A:test

Getting start code - Part B

Start code: code_session1.tar.gz

Download the start code, upack it and copy the top directory examen in a new directory, named examen-YourFamilyName, or examen-YourFamilyName1_YourFamilyName2 if you work in binome. You should develop your solutions in the new directory.

tar xzvf examen-start.tar.gz
cp -r examen examen_YourFamilyName
cd examen_YouFamilyName

Task 1: shape

The given code in readShape.cxx is buggy. Correct the compilation warnings, errors and the program behavior.

Task 2: perfect

A perfect number is a number that is half the sum of all of its positive divisors (including itself).

Compute the list of perfect numbers between 1 and 10000 (you should find 6, 28, 496, 8128).

A boolean function isDivisor of two integer arguments is provided with prototype:

bool isDivisor (int multiple, int divisor)

It returns true if and only if divisor divides multiple.

  1. Define a function fillDivisorList according to the prototype below, given divisors, a vector of integer, it fills this vector with the list of divisors.

     void fillDivisorList (int number, vector<int>& divisors)
  2. Define a function getDivisorSum according to the prototype below, given divisors, the list of divisors as a vector of integer, it returns the sum of the list.

     int getDivisorSum (vector<int>& divisors)
  3. Define a function isPerfect according to the prototype below. It returns true if and only if the int argument number is a perfect number.

     bool isPerfect (int number)

Task 3: histogram

The program testHistogram.cxx can be used to display histograms in a terminal output. It uses two classes: Histogram and Generator.

  1. Implement the Histogram class member function fill() which implementation is missing in the given code.

  2. Add (implement) an evaluation and printing of the number of generated values which were outside the histogram range.

  3. Extend the program and add another histogram, which will be filled with a new random numbers distribution and then displayed in terminal.

Task 4: isotopes

Implement a program isotopes.cxx, which will process the provided data file isotopes.dat, evaluate the read data and display the isotope(s) which data meet the following condition:

  • the abundance must be greater than 10 percent
  • the half-life must be greater than 100 years

The class Isotope, which can be used to hold the data read from a file, is provided.

The data file format:

  Z 92 
  A 235 
  HALFLIFE 703800000 

where Z and A represent the number of protons and nucleons respectively; HALFLIFE is the isotope half-life time in years and ABUNDANCE is the isotope abundance in percent.

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-YourFamilyName.tar.gz examen-YourFamilyName