1.
What is the output of the following program fragment?
cout << static_cast<double>(3)/4 << endl;
Correct Answer
D. 0.75
Explanation
The program fragment is using static_cast to convert the integer value 3 to a double before dividing it by 4. Since both 3 and 4 are integers, the division will be performed as integer division, resulting in the quotient 0. However, since the numerator is now a double, the result of the division will be implicitly converted to a double, resulting in the output of 0.75.
2.
When parameters are passed between the calling code and the called function,
parameters and arguments are matched by:
Correct Answer
B. Their relative positions in the parameter and argument lists
Explanation
When parameters are passed between the calling code and the called function, the matching of parameters and arguments is based on their relative positions in the parameter and argument lists. This means that the first parameter in the function's parameter list will be matched with the first argument in the calling code's argument list, the second parameter will be matched with the second argument, and so on. The matching is done based on the order in which the parameters and arguments are defined, regardless of their names or data types.
3.
If you have the two functions as shown,
int someFunction(int value);
float someFunction(float value);
and a variable x, which is a double, which function is called by the following
statement?
cout << someFunction(x);
Correct Answer
C. Nothing, it is a syntax error
Explanation
The statement cout
4.
Which of the following are valid function calls to the fabs function?
Correct Answer
F. Fabs(3.5); and cout
Explanation
The function call fabs(3.5) is valid because it calls the fabs function with the argument 3.5, which returns the absolute value of 3.5. The function call cout is also valid because it is used to output data to the console. However, the other function calls are not valid. The function call cin >> fabs(3.5) is invalid because the cin function is used for input, not for calling a function. The function call fabs(cin >> x) is also invalid because it tries to use the cin function as an argument for the fabs function, which is not allowed. The function call cout > fabs(3.5) is invalid because the > operator is used instead of the
5.
The functions pow(), sqrt(), and fabs() are found in which include file?
Correct Answer
B. Cmath
Explanation
The functions pow(), sqrt(), and fabs() are found in the cmath include file.
6.
The expression static_cast<double>(3) is called a
Correct Answer
A. Type cast
Explanation
The expression static_cast(3) is called a type cast because it is used to explicitly convert the value 3 to the type double. Type casting allows for the conversion of one data type to another, and in this case, the integer value 3 is being converted to a double value. This is done by using the static_cast operator followed by the desired data type in angle brackets.
7.
If the variable x has the original value of 3.4, what is the value in x after the
following?
cout << static_cast<int>(x);
Correct Answer
D. 3
Explanation
The static_cast(x) statement converts the value of x to an integer. Since x has the original value of 3.4, it will be converted to the nearest integer, which is 3. Therefore, the value in x after the statement is 3.
8.
What is the value of the following?
sqrt(sqrt(pow(2,4)));
Correct Answer
B. 2
Explanation
The given expression calculates the square root of the square root of 2 raised to the power of 4. First, 2 raised to the power of 4 is calculated, which equals 16. Then, the square root of 16 is taken, resulting in 4. Finally, the square root of 4 is calculated, which equals 2. Therefore, the value of the expression is 2.
9.
Using functions in a program is known as
Correct Answer
B. Procedural abstraction
Explanation
Procedural abstraction refers to the practice of using functions in a program. Functions allow us to break down complex tasks into smaller, more manageable parts, making the code easier to understand and maintain. By encapsulating a set of instructions within a function, we can reuse that code whenever needed, improving code reusability and reducing redundancy. Therefore, the correct answer is procedural abstraction.
10.
Which of the following are valid function calls to the pow function?
Correct Answer
C. Pow(1.1,3.0);
Explanation
The only valid function call to the pow function is pow(1.1,3.0). This is because the pow function takes two arguments, both of which must be of type int or double. The first function call pow(int x, int y) is invalid because it does not provide the required second argument. The second function call pow(2) is also invalid because it does not provide the required first argument. The fourth function call double pow(1.1,3.0) is invalid because it includes the data type "double" before the function name, which is not allowed.
11.
If you have the following variable declaration in your program,
const int SIZE=34;
then which of the following statements are legal?
Correct Answer
C. Cout
Explanation
The statement "cout" is legal because it is used to display the value of the variable SIZE.
12.
Which of the following functions is a properly overloaded function of the following?
int doSomething(int first, float second);
Correct Answer
C. Int doSomething(int first, int second, float third);
Explanation
The correct answer is "int doSomething(int first, int second, float third)" because it has the same function name "doSomething" and the same parameter types "int, int, float" as the original function. Overloading a function means creating a new function with the same name but different parameters.
13.
Which of the following are not legal function declarations?
Correct Answer
B. Int 3ave(int a, int b, int c);
Explanation
The function declaration "int 3ave(int a, int b, int c);" is not legal because function names cannot start with a number.
14.
Information Hiding is analogous to using
Correct Answer
B. A black-box methodology
Explanation
Information hiding is a concept in software engineering that suggests hiding the implementation details of a module or component from other parts of the system. This is similar to using a black-box methodology, where the internal workings of the system are hidden and only the inputs and outputs are visible. By using a black-box methodology, the details of how the system functions are abstracted away, allowing for easier understanding and maintenance of the system as a whole. Similarly, information hiding allows for better modularization and encapsulation of code, making it easier to modify and maintain.