Question Bank
Let suppose that we have an int variable x and an int* pointer variable p. We have initialized x by 2 and p to the address of x. Which of the following statements are true?
The address of x and the value of p is the same
The value of x and the value of *p is the same
The address of p and the value of &x are equal
&x == *p
Which of the following statements is true (in a C++ context)?
A static function cannot throw an exception.
A static function cannot access a non-static member of the class.
A static function cannot access a static member of the class.
A static member cannot be modified in const non-static member functions.
Match the verb with the class relationship it describes:
(1, a), (2, b), (3, c)
(1, b), (2, c), (3, a)
(1, c), (2, b), (3, a)
(1, b), (2, a), (3, c)
The OCP principle refers to:
responsibilities that a class must implement
defining a consistent class hierarchy
problems that appear because of duplicate code
the possibility of class extension and avoidance of the modification of existing classes / code
If a class X has pointer variable members, then the class should also contain:
an empty destructor X(){}
a fiend function that copies an object of class X
an overload of the assignment operator
a copy constructor
an overload of the == operator
a destructor that releases the memory pointed by the members of type pointer
Given the following code:
class Date {
public:
Date(int day=0, int month=0, int year=0);
Date(const Date& ref);
};
void g(Date d) { }
void f() {
Date d{7 , 3, 2007};
Date d1;
Date d2 = d;
d2 = d;
g(d);
}How many times the constructors of class Date are invoked?
2
3
4
5
Which of the following statements is/are true?
class Shape { virtual void draw() = 0; };
struct Rectangle : Shape {
void addControlPoint(int x, int y);
};
int main() { Rectangle c; return 0; }class Rectangle cannot be instantiated because of the method addControlPoint that is not implementated
class Rectangle cannot be instantiated because it is an abstract class
the code compiles successfully.
Which of the following code snippets is the correct implementation of the static function MyClass* instance() declared in class MyClass? (Raul notes: no extra code provided)
static MyClass* MyClass::instance() {return new MyClass; }MyClass* instance() { return new MyClass; }MyClass MyClass::instance() { return new MyClass; }MyClass* MyClass::instance() { return new MyClass; }MyClass::MyClass* instance() { return new MyClass; }What is the minimal implementation of class INT so that the declarations INT i{10}, ii{i}; are correct.
struct INT
{
INT(int x);
};struct INT
{
INT(int x) {};
};struct INT
{
INT(int x) {}
INT(const INT& r) {}
};struct INT
{
INT(int x);
INT(const INT& r);
};Which condition needs to be be satisfied so that the code below compiles and the execution of function min returns the minimum value of the arguments?
template <class T> min(T x, T y) {
return x < y ? x : y;
}?: operator needs to be overloaded for type T
< operator needs to be overloaded for type T
T need to be a numeric type
Running the C++ code below will print
#include <iostream>
struct C {
C() { std::cout << "Red "; }
};
class B {
protected:
B() { std::cout << "Vehicle "; }
};
struct A : B {
C c;
A() { std::cout << "Car "; }
};
int main(){
A a;
}Red Vehicle Car
Red Car Vehicle
Car Vehicle Red
Car Red Vehicle
Vehicle Red Car
Vehicle Car Red
Which C++ keyword is used to create a custom error object when a problem is detected at runtime?
try
catch
throw
return
Assuming that the exception class Overflow is derived from MathException, in the try block below, when an Overflow exception is thrown, then the code will print ...
try {
// calling math operations that may throw exceptions
}
catch(MathException me) {
std::cerr << "MathException ";
}
catch(Overflow o) {
std::cerr << "Overflow ";
}Overflow
Overflow MathException
MathException
MathException Overflow
None
Fill in the space below the message that reflects the result
void f(list<string>& lst) {
list<string>::const_iterator x = find(lst.begin(), lst.end(), "Timisoara");
if (x==lst.end()) std::cout << "_______________________"; }Found Timisoara
Did not find Timisoara
Timisoara is the last element in the list
Timisoara is the first element in the list
Which members of a base class are accessible in member functions of derived classes?
private
protected
public
Given the code below, which of the following declarations are correct
class Int {
int x;
public: Int(int i) : x{i} {}
};
template<class T, int size> struct vec { };vec<int, 10> v
vec<Int, 100-10/2> v
const int x = 12; vec<int, x> v
int x = 12; vec<int, x> v
vec<int, int> v
Given the class date defined as below, which declarations are not correct?
class date{
public:
explicit date(int day = 0, int month = 0, int year = 0);
~date();
};date d
date d = 1
date d{1}
date d{1, 2}
date d{1, 6, 2024}
Which assertions are true with respect to Virtual Functions Table (VTBL)
one VTBL is created for each class that has at least one virtual function
one VTBL is created for each object (instance) of a class that has at least one virtual function
the VTBL contains one entry for each member function of a class
the VTBL contains one entry only for virtual member functions of a class
Given the code snippet below, what do you need to do in order to successfully compile the code.
class animal {
virtual void make_noise() = 0;
virtual void eat() = 0;
};
struct cat : animal {
char* fur_color();
};
int main() {
cat tom;
}override the virtual method make_noise in class cat
override the virtual method eat in class cat
implement cat::fur_color non-static member function
define a default constructor for class cat
Select all the true statements
A class can have zero or more user-defined constructors
It is not possible to invoke a member function from a constructor
If there are no user-defined constructors, the compiler generates one default constructor
The programmer needs to explicitly call a constructor to initialize the object
Given the following overload of operator <<, select all true statements
std::ostream& operator<<(std::ostream& out, const complex& o){
std::cout << re << "i" << im;
return out;
}(This question is wrong, but the commission has not been announced.)
given the declaration complex c{1, 2}; will print 1i2
compiling the code will produce an error because operator << doesn’t have access to internal representation of a complex number (re and im) (this should be correct after further checking)
compiling the code will produce an error because operator << is not a member function of complex type (this is not correct after further checking, but marked here as correct)
may be made friend of class complex
Given the relation R(A) with two tuples in it {(1), (2)} and the following two transactions
/*T1*/ UPDATE R SET A = A*2
/*T2*/ SELECT AVG(A) FROM R; SELECT MAX(A) FROM RIf T2 is executed under repeatable read isolation level, which statements are true?
IF AVG(A) = 1.5 then MAX(A) equals to 2 or 4
AVG(A) = 1.5 and MAX(A) = 2 , always
Possible values for AVG(A) are 1.5 or 3, and possible values for MAX(A) are 2 or 4
Three of the following four expressions find the names of all students who did not apply to major in CS or PH. Which one finds something different? (Hint: You should not assume that the student names are unique.)
The table below contains a representative data sample for all the functional dependencies in a real-life data set. Which are the functional dependencies that hold for the data below?
A → {B, C}, E → {F}
D → {A, B, C, E, F}, F → {E}
{A, E} → {D}
{D, E} → {A, B}
Considering the relation R(A, B, C, D, E, F) with attributes and functional dependencies from the previous question, which of the following sets of attributes is/are candidate keys in R?
Previous question:
The table below contains a representative data sample for all the functional dependencies in a real-life data set. Which are the functional dependencies that hold for the data below?
{B, F}
{A, E}
{A, E, D}
{A}