Question Bank

Rows per page: 1025100

Showing 151–175

Programming Languages and Software Engineering C Language #15

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

Programming Languages and Software Engineering C++ Language #1

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.

Programming Languages and Software Engineering C++ Language #2

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)

Programming Languages and Software Engineering C++ Language #3

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

Programming Languages and Software Engineering C++ Language #4

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

Programming Languages and Software Engineering C++ Language #5

Given the following code:

cpp
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

Programming Languages and Software Engineering C++ Language #6

Which of the following statements is/are true?

cpp
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.

Programming Languages and Software Engineering C++ Language #7

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)

○
cpp
static MyClass* MyClass::instance() {return new MyClass; }
○
cpp
MyClass* instance() { return new MyClass; }
○
cpp
MyClass MyClass::instance() { return new MyClass; }
✓
cpp
MyClass* MyClass::instance() { return new MyClass; }
○
cpp
MyClass::MyClass* instance() { return new MyClass; }
Programming Languages and Software Engineering C++ Language #8

What is the minimal implementation of class INT so that the declarations INT i{10}, ii{i}; are correct.

○
cpp
struct INT
{
   INT(int x);
};
✓
cpp
struct INT
{
    INT(int x) {};
};
○
cpp
struct INT
{
    INT(int x) {}
    INT(const INT& r) {}
};
○
cpp
struct INT
{
    INT(int x);
    INT(const INT& r);
};
Programming Languages and Software Engineering C++ Language #9

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?

cpp
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

Programming Languages and Software Engineering C++ Language #10

Running the C++ code below will print

cpp
#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

Programming Languages and Software Engineering C++ Language #11

Which C++ keyword is used to create a custom error object when a problem is detected at runtime?

○

try

○

catch

✓

throw

○

return

Programming Languages and Software Engineering C++ Language #12

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 ...

cpp
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

Programming Languages and Software Engineering C++ Language #13

Fill in the space below the message that reflects the result

cpp
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

Programming Languages and Software Engineering C++ Language #14

Which members of a base class are accessible in member functions of derived classes?

○

private

✓

protected

✓

public

Programming Languages and Software Engineering C++ Language #15

Given the code below, which of the following declarations are correct

cpp
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

Programming Languages and Software Engineering C++ Language #16

Given the class date defined as below, which declarations are not correct?

cpp
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}

Programming Languages and Software Engineering C++ Language #17

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

Programming Languages and Software Engineering C++ Language #18

Given the code snippet below, what do you need to do in order to successfully compile the code.

cpp
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

Programming Languages and Software Engineering C++ Language #19

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

Programming Languages and Software Engineering C++ Language #20

Given the following overload of operator <<, select all true statements

cpp
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

Programming Languages and Software Engineering Databases #1

Given the relation R(A) with two tuples in it {(1), (2)} and the following two transactions

sql
/*T1*/ UPDATE R SET A = A*2
/*T2*/ SELECT AVG(A) FROM R; SELECT MAX(A) FROM R

If 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

Programming Languages and Software Engineering Databases #2

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.)

○

πsName(Student▷◁(πsID(Student)−(πsID(σmajor=′CS′Apply)∪πsID(σmajor=′PH′Apply))))π_{sName}(Student ▷◁ (π_{sID}(Student)−(π_{sID}(σ_{major}=_{′CS′}Apply)∪π_{sID}(σ_{major}=_{′PH′}Apply))))

○

πsName(Student▷◁(πsIDStudent−πsID(σmajor=′CS′∨major=′PH′Apply)))π_{sName}(Student ▷◁ (π_{sID}Student − π_{sID}(σ_{major}=_{′CS′∨ major}=_{′PH′}Apply)))

○

πsName(πsID,sNameStudent−πsID,sName(Student▷◁πsID(σmajor=′CS′∨major=′PH′Apply)))π_{sName}(π_{sID,sName}Student− π_{sID,sName}(Student ▷◁ π_{sID}(σ_{major}=_{′CS′ ∨ major=′PH′}Apply)))

✓

πsNameStudent−πsName(Student▷◁πsID(σmajor=′CS′∨major=′PH′Apply))π_{sName}Student − π_{sName}(Student ▷◁ π_{sID}(σ_{major=′CS′ ∨ major=′PH′}Apply))

Programming Languages and Software Engineering Databases #3

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}

Programming Languages and Software Engineering Databases #4

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}