What is the minimal amount of storage bits needed to store the grades of 150 students?
math.ceil(math.log2(21) * 150) = ...
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) = ...
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) = ...
How many bits are minimally necessary to store 800 times of day up to the second?
math.ceil(math.log2(86400) * 800) = ...
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) = ...
What is the minimal number of bits required to store 500 birthdays?
math.ceil(math.log2(366) * 500) = ...
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 |
0x C00000
== 0x12F45678
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 &
0x 8
== 0x00000008
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 |
0x 7
== 0x1234567F
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 &
0x 600
== 0x00000600
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 <<
0x 8
== 0x34567800
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 &
0x 2000000
== 0x02000000
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 &
0x 10000000
== 0x10000000
Fill in a bitwise operator and an operand so as to make the following expression true:
0x12345678 >>
0x4
== 0x01234567
Antwoord: int*
Antwoord: int
Antwoord: int**
Antwoord: int*
Antwoord: int
Antwoord: int***
Antwoord: char*
Antwoord: char
Antwoord: char**
Antwoord: char*
Antwoord: char
Antwoord: char***
Antwoord: bool*
Antwoord: bool
Antwoord: bool**
Antwoord: bool*
Antwoord: ``
Antwoord: bool***
Antwoord: double*
Antwoord: double
Antwoord: double**
Antwoord: double*
Antwoord: double
Antwoord: double***
Antwoord: [a]c
Antwoord: []
Antwoord: [aa]cc
Antwoord: [a]c
Antwoord: [ab]cc
Antwoord: [a]
Antwoord: [abc]c
Antwoord: [a]c
Antwoord: [a]c
Antwoord: [aac]c
Antwoord: [ac]
Antwoord: [a]c
Antwoord: [abc]c
Antwoord: [abc]c
Antwoord: ``
Antwoord: [a]c
Antwoord: [ac]
Antwoord: [a]
Antwoord: [ac]
Antwoord: [abc]
a
c
b
d
b
e
e
g
f
h
f
void foo(const T& x);
std::unique_ptr<T> x;
foo(*x)
void foo(std::unique_ptr<T> x);
const T* x;
None of the above works, or it's impossible
void foo(std::unique_ptr<T> x);
const T& x;
None of the above works, or it's impossible
void foo(T* x);
const T& x;
None of the above works, or it's impossible
void foo(T x);
const T x;
foo(x)
void foo(T& x);
T* x;
foo(*x)
void foo(T x);
std::unique_ptr<T> x;
foo(*x)
void foo(T x);
T* x;
foo(*x)
void foo(const T* x);
const T* x;
foo(x)
void foo(T& x);
std::shared_ptr<T> x;
foo(*x)
void foo(const T& x);
T& x;
foo(x)
void foo(T* x);
std::shared_ptr<T> x;
foo(&*x)
void foo(const T& x);
const T x;
foo(x)
void foo(T* x);
std::unique_ptr<T> x;
foo(&*x)
void foo(const T& x);
const T* x;
foo(*x)
void foo(T x);
std::shared_ptr<T> x;
foo(*x)
void foo(std::unique_ptr<T> x);
T x;
None of the above works, or it's impossible
void foo(const T* x);
T& x;
antwoord
void foo(std::unique_ptr<T> x);
T& x;
antwoord
void foo(const std::shared_ptr<T> x);
const T x;
antwoord
void foo(const T x);
T x;
antwoord
void foo(const std::unique_ptr<T> x);
const T x;
None of the above works, or it's impossible
void foo(T x);
const T* x;
foo(*x)
void foo(T x);
const T* x;
foo(x)
void foo(const T& x);
T* x;
foo(*x)
void foo(T* x);
T& x;
foo(&x)
void foo(const T& x);
const T& x;
foo(x)
void foo(T* x);
T& x;
foo(*x)
void foo(T& x);
const T& x;
None of the above works, or it's impossible
void foo(T x);
T** x;
foo(**x)
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*
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
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
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&
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
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>
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
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*
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
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
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&
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>
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*
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&
You are writing a function selectYoungerThan that takes a std::vector<Person*> and an age.
How should you best pass the parameter?
T
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>
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>
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>
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>
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&
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&
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)
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*)
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>&)
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
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>