Tentin tekstisisältö

TIE-02207 Programming 2: Basics - 13.12.2018

Tentin tekstisisältö

Teksti on luotu tekstintunnistuksella alkuperäisestä tenttitiedostosta, joten se voi sisältää virheellistä tai puutteellista tietoa. Esimerkiksi matemaattisia merkkejä ei voida esitää oikein. Tekstiä käytetään pääasiassa hakutulosten luomiseen.

Alkuperäinen tentti
 

TIE-02207 Programming 2: Basics

Exam 13.12.2018

Write your answers to guestions 1 and 2 on a single grid paper and those to guestions 3 and 4 on a
different grid paper. Remember to write your name and student number on the grid papers. You can
use either English or Finnish. You need not care about the exact syntax when writing C++ code.

Name:

Student number:

 

1

2 3 4

 

 

 

 

 

 

 

1. Assume that all necessary include directives and other program parts are available. Consider
the following data type.

struct Item (
int data;
Item* next;

1;

Assume that the above data type has been used to create the following data structure:

first

 

42 37 13 7 TI

 

 

 

 

o o —:0 ; O

 

 

 

 

 

 

 

 

 

 

 

where the diagonal line at the last element depicts nullptr.

(a) Which action does the following program code perform to the data structure, if the value
of test datais13? Do not explain each code line in English (or in Finnish), but describe
the action as a whole in one sentence. In addition, draw a figure of the data structure after
the action. (3 p.)

1
(2
3
4
5
6
7
8

9

10
11
12
13
14
15

Item* a = first;

if (a->data == test data) (
first = a->next;
] else (

Item* prev = a;
a = a->next;
while(a != nullptr) (
if(a->data == test data) (
prev->next = a->next;
] else (
prev = a;

)
a = a->next;
 

(b) The above code contains errors related to memory management (at least two different
errors). What are these errors? (2 p.)

(c) How to fix the errors without changing struct Item? Write the correction in C++. You
need not rewrite correct lines. (3 p.)

2. (a) Mention at least two important things that you must remember when writing a recursive
function. (2 p.)

(b) Write a recursive function that finds out the greatest element, still less than hundred, from
a vector. (4 p.)

3. (a) What are the most essential differences between static and dynamic typing? Which of
them is used in C++? (3 p.)

(b) What are the most essential differences between value semantics and reference semantics?
Which of them is used in C++? (3 p.)

(c) What kind of data structure (constructed from STL and other C++ structures) would you
use when implementing a membership register, i.e. a program that stores information
about members of a society? The program must be able to handle/search/print membership
data both in the order according to the names of the members and in the order according to
the dates, when the members have joined the society. In addition to the above mentioned
data, the program must be able print the address and email address of each member. (4 p.)

4. Suppose that you are writing a C++ program managing airports. An airport has at least flights,
which again have at least arrival and departure times. Which classes do you have, and what are
their public and private interfaces? Write the class definitions in C++. If you want, you can also
draw a picture. What are the benefits of dividing a program into classes? (6 p.)

2/12


Käytämme evästeitä

Tämä sivusto käyttää evästeitä, mukaanlukien kolmansien puolten evästeitä, vain sivuston toiminnan kannalta välttämättömiin tarkoituksiin, kuten asetusten tallentamiseen käyttäjän laitteelle, käyttäjäistuntojen ylläpitoon ja palvelujen toiminnan mahdollistamiseen. Sivusto kerää käyttäjästä myös muuta tietoa, kuten käyttäjän IP-osoitteen ja selaimen tyypin. Tätä tietoa käytetään sivuston toiminnan ja tietoturvallisuuden varmistamiseen. Kerättyä tietoa voi päätyä myös kolmansien osapuolten käsiteltäväksi sivuston palvelujen tavanomaisen toiminnan seurauksena.

FI / EN