Exam text content

TIE-02207 Programming 2: Basics - 13.12.2018

Exam text content

The text is generated with Optical Image Recognition from the original exam file and it can therefore contain erroneus or incomplete information. For example, mathematical symbols cannot be rendered correctly. The text is mainly used for generating search results.

Original exam
 

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


We use cookies

This website uses cookies, including third-party cookies, only for necessary purposes such as saving settings on the user's device, keeping track of user sessions and for providing the services included on the website. This website also collects other data, such as the IP address of the user and the type of web browser used. This information is collected to ensure the operation and security of the website. The collected information can also be used by third parties to enable the ordinary operation of the website.

FI / EN