Object Oriented Programming Using C Plus Plus - Study Mode

[#476] One way in which a structure differs from an array is that _____
Correct Answer

(A) a structure may have members of more than one type

[#477] The statement double val[15]={44.123456}

Correct Answer

(B) assigns the value 44.123456 to val[0] and 0 to the rest of the members

[#478] Which of the following C++ expressions will find the square root of the number 16?
Correct Answer

(D) sqrt (16)

Explanation

Solution: sqrt is a function from the C++ standard library that calculates the square root of a given number. In this case, the expression sqrt(16) calculates the square root of 16. The function pow from the C++ standard library calculates the power of a number, i.e., it raises a number to a specified power. The expression pow(16, 2) calculates 16 raised to the power of 2, which is 256, and is not the square root of 16. sqroot is not a standard C++ function and will result in a compile-time error. sqrt (16, 2) is not a correct syntax for the sqrt function in C++, which takes only one argument, the number for which the square root is to be calculated. So, the correct expression to find the square root of 16 in C++ is sqrt(16) . C++ program to find out square root of 16 #include <iostream>
#include <cmath>
using namespace std

int main() {
cout << "Square root of 16 = "

// print the square root of 16
cout << sqrt(16)

return 0

} Here is an explanation of the code: 1. #include <iostream> - This line includes the input/output stream library, which provides the cout function that is used later in the code to print the output. 2. #include <cmath> - This line includes the C++ mathematics library, which provides mathematical functions such as sqrt() that is used later in the code to calculate the square root. 3. using namespace std

- This line is used to make all the elements of the standard C++ library available to the program. 4. int main() - This is the main function of the program. All C++ programs must have a main function, which is where the program starts executing. 4. cout << "Square root of 16 = "

- This line outputs the string "Square root of 16 =" to the console. 6. cout << sqrt(16)

- This line calculates the square root of 16 using the sqrt() function from the C++ mathematics library and outputs the result to the console. 7. return 0

- This line is the return statement of the main function. It returns 0, indicating that the program has executed successfully. In summary, this program calculates the square root of 16 and outputs the result to the console.

[#479] Which of the following statements declares a variable that can contain a decimal number?
Correct Answer

(D) float hourlyPay

[#480] The statement int num[2][3] = {{1,2}, {3,4}, {5, 6}}

Correct Answer

(C) gives an error message