Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt filec.txt $ mv filea.txt filed.txt $ mv filed.txt filee.txt $ rm fileb.txt $ cp filec.txt filef.txt $ cp filec.txt fileg.txt 2. Complete missing words in the following statement: The function main() in a C++ program returns a value of If return statement is not present, the value = is returned implicitly type. 3. How many times will the following code print each message? for ( int i = 0; i < 10; i++ ) { cout << "Looping over i" << endl; if ( i == 5 ) continue; for ( int j = 0; j < 10; j++ ) { cout << "Looping over j" << endl; if ( j == 5 ) break; "Looping over i" will be printed "Looping over j" will be printed times. times. 4. To share a completely new file in your directory with your team using git, which command is not necessary: a) git add b) git commit c) git push d) git log
Examen - Part A Page 2 5. Which objects for the input/output (I/O) functionality are provided with #include <iostream>? (Select the correct statement.) a) The cin and cout, which correspond to the standard input stream and services useful for performing formatted I/O with so-called parameterized stream manipulators, such as setw and setprecision. b) The cin and cout, which correspond to the standard input stream and the standard output stream, and the cerr and clog, which correspond to the un-buffered and buffered standard error stream. c) The cin and cout, which correspond to the standard input stream and the standard output stream, and services for user-controlled file processing. d) The cin and cout which correspond to the standard input stream and the standard output stream. 6. Let's have: vector<int> numbers = { 1, -1, 2, -2; numbers.push_back(3); numbers.push_back(-3); numbers.size(); numbers.push_back(4); numbers.push_back(-4); numbers.push_back(5); numbers.push_back(-5); What will be the number of elements in the 'numbers' vector after the last statement? 7. What does "Data encapsulation" mean in object-oriented programming?
Examen - Part A Page 3 8. Which code can be used to get the reference of the following variable: double x = 3.5; a) double& rx = x; b) double& rx = *x; c) double* rx = &x; d) double* rx = *x; 9. Which of the statements below is correct? int main() { for ( int i = 0; i < 10; i++ ) { int value1 = 5; int* value2 = new int(10); cout << End of program << endl; a) the memory allocated for both value1 and value2 will be released before printing the message b) the memory allocated for both value1 and value2 will be released after printing the message c) the memory allocated for value1 will be released before printing the message and for value2 after this printing d) the memory allocated for value1 will be released after printing the message and for value2 before this printing 10. Which of the statements below is incorrect? A class constructor function is different from an ordinary function in the following aspects: a) The name of the constructor is the same as the class name. b) Constructor has no return type. Hence, no return statement is allowed inside the constructor's body. c) Constructor cannot be overloaded. d) Constructor can only be invoked once to initialize the instance constructed.
Examen - Part A Page 4 11. The common behavior of objects can be expressed by means of inheritance, we can define a derived class that inherits data and functions of the base class. A member function of a base class can be also redefined in its derived classes, if it is declared with keyword virtual. Non virtual functions with the same name in a class hierarchy should be however avoided. Could you explain why? 12. What are the values of c and e variables after the following instructions? int c=2, e=5; e++; c=e++; c++; a) c=3, e=7 b) c=8, e=7 c) c=7, e=7 d) c=3, e=6 13. Which of the statements below is correct? a) A C++ program can output information only through <iostream>. b) A C++ program can output information through <iostream> and with a return code. c) A C++ program can output information with the main function argc, argv[] arguments. d) A C++ program can output information through others functions arguments. 14. Which of the following function declarations guarantee(s) that the argument will not be modified in the function? a) void fun1 (int* number); b) void fun2 (int& number); c) void fun2 (int number); d) void fun2 (const int& number);
Examen - Part A Page 5 15. Given the following function prototype: int funct (int a, int b, int c = 3); which of the following calls will fail at compilation? a) int i = funct (2, 3, 4); b) int j = funct (2); c) int k = funct (2, 3); d) int l = funct (1, 2, 3); 16. Given the executable program compute, how can you display the return value (called also exit code) of the program in the terminal? a) > echo compute b) > print compute c) >./compute > echo $? d)>./compute > echo argc 17. Can a C++ program call another program? a) Yes, using the system() function defined in <cstdlib> header. b) Yes, using the exec()function defined in <cstdlib> header. c) Yes, using the system() function defined in <execution> header. d) No, another program can only be called by the operational system. 19. What s the purpose of using Git and Make tools? Name at least one benefit of each of these tools.
Examen - Part A Page 6 18. Qt library introduces a special mechanism for communication between the Qt objects (buttons, windows, menus). a) Could you name some of the Qt specific keywords, functions or macros which are defined for this mechanism? b) Could you explain meaning of one of these keywords? a) b) 20. What is the meaning of nullptr? a) If a pointer has nullptr value, it means that the pointer variable is not yet defined and cannot be used in the program. b) If a pointer has nullptr value, it means that it is not yet initialized. It can point anywhere. c) If a pointer has nullptr value, it does not refer to anything. This value is attributed to a pointer by default when a variable of pointer type is defined. d) If a pointer has nullptr value, it does not refer to anything. This is different from a noninitialized pointer, which can point anywhere.