Part A:test
Start code: examen_code.tar.gz
Download the start code, upack it and copy the top directory examen_code
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.
cd
tar xzvf examen_code.tar.gz
cp -r examen_code examen_YourFamilyName
cd examen_YourFamilyName
car
The given code in readCar.cxx
is buggy. Correct the compilation warnings, errors and the program behavior.
triangle
This task is to develop a simple program which computes the area of a triangle.
Assignment 1: Ask the user for three lengths (a
, b
and c
) of the sides of a triangle.
Assignment 2: Check that this triplet of numbers represents a real triangle by testing the 3 Triangle inequalities:
a + b > c
b + c > a
c + a > b
If these three inequalities are not all satisfied, report it and abort the program.
Assignment 3: Compute and display the area of this triangle using Heron’s formula:.
First compute the semi-perimeter s
of the triangle
s = (a+b+c)/2;
Then, compute the area of this triangle
area = square_root_of (s * (s-a) * (s-b) * (s-c));
Assignment 4: Apply your program to the following triangles and report their areas
73 51 26
10 11 12
10 10 10
pascal
This program will compute and display Pascal’s triangle: a triangular array of the binomial coefficients.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
..................................
Assignment 1: Ask the user how many rows of the triangle he wants, and put it in the variable nbRows
.
Assignment 2: For each row i
from 0
to (nbRows-1)
compute and display all the coefficients in this line knowing the recursion formula:
— the first column of the row has coefficient 1
— for another column j
of the row i
, the coefficient (i, j)
is coefficient (i, j-1)
times (i-j+1)/j
Assignment 3: the display should be formatted as follows:
// 1
// 1 1
// 1 2 1
// 1 3 3 1
// 1 4 6 4 1
// 1 5 10 10 5 1
// 1 6 15 20 15 6 1
// ..................................
elements
The given program elements.cxx
is incomplete.
Inspect the code already implemented, build the program and run it.
Implement the code which will process all elements read, find the name of the heaviest one (the element with the highest density) and print this found name on the screen.
Add a new function, findElement
in elements.cxx
which will return the element of a given name. The function prototype is given below. When the function is implemented, use this function to find the the heaviest element object, which name was found in the previous step, and then use this object to print all its characteristics on the screen.
Element findElement(string name);
Pack the code which you developed in a single tar file and send the tar file by e-mail to both teachers: ivana@ipno.in2p3.fr, lafage@ipno.in2p3.fr.
Before you leave the room, check with the teachers that they received your code.
cd
tar czvf examen_YourFamilyName.tar.gz examen_YourFamilyName
Solution: