Skip to content

Latest commit

 

History

History
847 lines (545 loc) · 13.7 KB

examenvragen.md

File metadata and controls

847 lines (545 loc) · 13.7 KB

Examenvragen Programmeren voor Multimeadia 2022

Bits tellen

Vraag 1

What is the minimal amount of storage bits needed to store the grades of 150 students?

math.ceil(math.log2(21) * 150) = ...

Vraag 2

How many bits are minimally required to store 950 student ids? A student id starts with either r or s and is then followed by 7 decimal digits.

math.ceil(math.log2(2*(10**7)) * 950) = ...

Vraag 3

Your website demands its users have passwords exactly 10 characters long. Only lowercase and uppercase letters are allowed. You have 450 users.

How many bits do you minimally require to store all the users' passwords?

math.ceil(math.log2(52**10) * 450) = ...

Vraag 4

How many bits are minimally necessary to store 800 times of day up to the second?

math.ceil(math.log2(86400) * 800) = ...

Vraag 5

You're a bank. Each of your customers has a bank card with a 4 digit PIN code. You have 4500 customers.

How much storage do you minimally need to store all these PIN codes?

math.ceil(math.log2(2*(10**4)) * 4500) = ...

Vraag 6

What is the minimal number of bits required to store 500 birthdays?

math.ceil(math.log2(366) * 500) = ...

Bitwise operator

Vraag 1

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 | 0x C00000 == 0x12F45678

Vraag 2

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 & 0x 8 == 0x00000008

Vraag 3

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 | 0x 7 == 0x1234567F

Vraag 4

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 & 0x 600 == 0x00000600

Vraag 5

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 << 0x 8 == 0x34567800

Vraag 6

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 & 0x 2000000 == 0x02000000

Vraag 7

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 & 0x 10000000 == 0x10000000

Vraag 8

Fill in a bitwise operator and an operand so as to make the following expression true:

0x12345678 >> 0x4 == 0x01234567

Types

Vraag 1

type1

Antwoord: int*

Vraag 2

type2

Antwoord: int

Vraag 3

type3

Antwoord: int**

Vraag 4

type4

Antwoord: int*

Vraag 5

type5

Antwoord: int

Vraag 6

type6

Antwoord: int***

Vraag 7

type7

Antwoord: char*

Vraag 8

type8

Antwoord: char

Vraag 9

type9

Antwoord: char**

Vraag 10

type10

Antwoord: char*

Vraag 11

type11

Antwoord: char

Vraag 12

type12

Antwoord: char***

Vraag 13

type13

Antwoord: bool*

Vraag 14

type14

Antwoord: bool

Vraag 15

type15

Antwoord: bool**

Vraag 16

type16

Antwoord: bool*

Vraag 17

type17

Antwoord: ``

Vraag 18

type18

Antwoord: bool***

Vraag 19

type19

Antwoord: double*

Vraag 20

type20

Antwoord: double

Vraag 21

type21

Antwoord: double**

Vraag 22

type22

Antwoord: double*

Vraag 23

type23

Antwoord: double

Vraag 24

type24

Antwoord: double***

Classes

Vraag 1

classes1

Antwoord: [a]c

Vraag 2

classes2

Antwoord: []

Vraag 3

classes3

Antwoord: [aa]cc

Vraag 4

classes4

Antwoord: [a]c

Vraag 5

classes5

Antwoord: [ab]cc

Vraag 6

classes6

Antwoord: [a]

Vraag 7

classes7

Antwoord: [abc]c

Vraag 8

classes8

Antwoord: [a]c

Vraag 9

classes9

Antwoord: [a]c

Vraag 10

classes10

Antwoord: [aac]c

Vraag 11

classes11

Antwoord: [ac]

Vraag 12

classes12

Antwoord: [a]c

Vraag 13

classes13

Antwoord: [abc]c

Vraag 14

classes14

Antwoord: [abc]c

Vraag 15

classes15

Antwoord: ``

Vraag 16

classes16

Antwoord: [a]c

Vraag 17

classes17

Antwoord: [ac]

Vraag 18

classes18

Antwoord: [a]

Vraag 19

classes19

Antwoord: [ac]

Vraag 20

classes20

Antwoord: [abc]

Code

Vraag 1

code1

a

Vraag 2

code2

c

Vraag 3

code3

b

Vraag 4

code4

d

Vraag 4b

code4b

b

Vraag 5

code5

e

Vraag 6

code6

e

Vraag 6b

code6b

g

Vraag 7

code7

f

Vraag 8

code8

h

Vraag 8b

code8b

f

You are given

Vraag 1

void foo(const T& x);
std::unique_ptr<T> x;

foo(*x)

Vraag 2

void foo(std::unique_ptr<T> x);
const T* x;

None of the above works, or it's impossible

Vraag 3

void foo(std::unique_ptr<T> x);
const T& x;

None of the above works, or it's impossible

Vraag 4

void foo(T* x);
const T& x;

None of the above works, or it's impossible

Vraag 5

void foo(T x);
const T x;

foo(x)

Vraag 6

void foo(T& x);
T* x;

foo(*x)

Vraag 7

void foo(T x);
std::unique_ptr<T> x;

foo(*x)

Vraag 8

void foo(T x);
T* x;

foo(*x)

Vraag 9

void foo(const T* x);
const T* x;

foo(x)

Vraag 10

void foo(T& x);
std::shared_ptr<T> x;

foo(*x)

Vraag 11

void foo(const T& x);
T& x;

foo(x)

Vraag 12

void foo(T* x);
std::shared_ptr<T> x;

foo(&*x)

Vraag 13

void foo(const T& x);
const T x;

foo(x)

Vraag 14

void foo(T* x);
std::unique_ptr<T> x;

foo(&*x)

Vraag 15

void foo(const T& x);
const T* x;

foo(*x)

Vraag 16

void foo(T x);
std::shared_ptr<T> x;

foo(*x)

Vraag 17

void foo(std::unique_ptr<T> x);
T x;

None of the above works, or it's impossible

Vraag 18

void foo(const T* x);
T& x;

antwoord

Vraag 19

void foo(std::unique_ptr<T> x);
T& x;

antwoord

Vraag 20

void foo(const std::shared_ptr<T> x);
const T x;

antwoord

Vraag 21

void foo(const T x);
T x;

antwoord

Vraag 22

void foo(const std::unique_ptr<T> x);
const T x;

None of the above works, or it's impossible

Vraag 23

void foo(T x);
const T* x;

foo(*x)

Vraag 24

void foo(T x);
const T* x;

foo(x)

Vraag 25

void foo(const T& x);
T* x;

foo(*x)

Vraag 26

void foo(T* x);
T& x;

foo(&x)

Vraag 27

void foo(const T& x);
const T& x;

foo(x)

Vraag 28

void foo(T* x);
T& x;

foo(*x)

Vraag 29

void foo(T& x);
const T& x;

None of the above works, or it's impossible

Vraag 30

void foo(T x);
T** x;

foo(**x)

Pass function

Vraag 1

You need to pass a int to a function. The function does not need to store it somewhere, but it does need to modify its value.

How should you best pass the parameter?

T*

Vraag 2

You need to pass a std::vector to a function. The function does not need to store it somewhere, nor does it want to modify it.

How should you best pass the parameter?

antwoord

Vraag 3

You are writing a function that takes a std::vector and negates all bools in the vector.

How do you best pass this parameter?

antwoord

Vraag 4

You are dealing with a class hierarchy of shapes, with abstract supertype Shape. A function needs to receive a shape but will not modify it in any way. The function does also not need to store the shape for layer.

How should you best pass the parameter?

const T&

Vraag 5

You need to pass a bool to a function. The function does not need to store it somewhere, nor does it require write access.

How should you best pass the parameter?

T

Vraag 6

You are keeping a central Log object, which is used all over your codebase to write diagnostic messages to.

How should you best pass the parameter?

shared_ptr<T>

Vraag 7

You are writing a templated function called contains that checks if some value x is an element of some vector.

How should you best pass the parameter?

antwoord

Vraag 8

You are writing a function that takes a std::vector and removes all negative values from the vector.

How should you best pass the parameter?

T*

Vraag 9

You are creating a templated collection class (such as std::vector). The add method takes an element and copies it to its internal data structure.

How should you best pass the parameter?

antwoord

Vraag 10

You create your own version of std::vector. Internally, you rely on an array in which you store your data.

How should you best pass the parameter?

antwoord

Vraag 11

You are writing a function with type parameter T. The function expects a value of type T, but only for reading purposes. The function does not store the value for later use.

How should you best pass the parameter?

const T&

Vraag 12

You need to pass a std::vector to a function. The function takes over full ownership.

How should you best pass the parameter?

unique_ptr<T>

Vraag 13

You need to pass a std::vector to a function. The function does not need to store it somewhere, but it wishes to modify its contents.

How should you best pass the parameter?

T*

Vraag 14

You are writing a function that takes a std::vector and returns the index of the largest element.

How should you best pass the parameter?

const T&

Vraag 15

You are writing a function selectYoungerThan that takes a std::vector<Person*> and an age.

How should you best pass the parameter?

T

Vraag 15

You are creating a chess application. Pieces are represented by a Piece class, and each Piece object keeps track of an Image object that represents the piece visually. The same Image object is reused for pieces of the same type, e.g., all pawns use the same Image.

How should you best pass the parameter?

shared_ptr<T>

Vraag 16

You are storing a family tree. Each child needs to keep track of both of its parents. We do not want to deal manually with memory management.

How should you best pass the parameter?

shared_ptr<T>

Vraag 17

You need to pass a std::vector to a function. The function stores it somewhere for later use and the same vector will still also be kept track of in other parts of the code.

How should you best pass the parameter?

shared_ptr<T>

Vraag 18

You create your own version of std::vector. Internally, you rely on an array in which you store your data.

How should you best pass the parameter?

unique_ptr<T>

Vraag 19

You are creating a templated collection class (such as std::vector). The add method takes an element and copies it to its internal data structure.

How should you best pass the parameter?

const T&

Vraag 20

You are writing a templated function called contains that checks if some value x is an element of some vector.

How should you best pass the parameter?

const T&

Reverse

Vraag 1

You are creating a function that reverses a std::vector in place.

Select all signatures that allow this functionality to be implemented.

answer:

void reverse(std::vector<T>& xs)	
void reverse(std::vector<T>* xs)	
void reverse(std::shared_ptr<T> xs)	

Vraag 2

You're making a game with different kinds of units (tanks, infantry, ...). The units are implemented as a class hierarchy with supertype Unit. You are writing a function render that draws the unit to the screen. No changes need to be made to the Unit object.

answer:

void render(Unit&)	
void render(const Unit*)		
void render(std::shared_ptr<Unit>)		
void render(const Unit&)		
void render(Unit*)

Vraag 3

You are creating a function count that counts the number of elements in std::vector.

correct items: (everything except unique_ptr)

int count(std::vector<T>)		
int count(std::unique_ptr<std::vector<T>>)		
int count(const std::vector<T>&)	
int count(std::shared_ptr<std::vector<T>>)		
int count(std::vector<T>*)	
int count(std::vector<T>&)

Vraag 4

You have a class hierarchy of shapes with abstract supertype Shape. You are writing a function clear_color that takes a shape and changes its color to transparent. Select all signatures that allow this functionality to be implemented. Selected Answers:void clear_color(Shape)

answer:

Shape*
Shape&
shared_ptr

Vraag 5

I wish to store Person objects in a vector. I do not want to preoccupy myself with memory management. In other words, I don't want to have to manually free each Person object in the vector: deallocation should happen automatically. Which types of vector-of-Persons do satisfy this requirement? If it matters: Person is not part of a class hierarchy.

Selected Answers:

std::vector<std::unique_ptr<Person>>
std::vector<std::shared_ptr<Person>>
std::vector<Person>