4. Short questions (a) For each of the questions that follow, choose the most appropriate option....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4. Short questions (a) For each of the questions that follow, choose the most appropriate option. i. Which one of the following is a correct function header for a function that computes and returns the square root of a float value? A. void squareRoot( float value) B. float squareRoot(int value) C. int squareRoot( float value) D. float squareRoot( float value) ii. Which of the following statements about arrays are true? (1) An array may contain elements of different data types. (2) A constant array must have an initialisation list. (3) When an array is passed as an argument to a function, the function has access to the original array. A. (1), (2) and (3) are true. B. (2) and (3) are true. C. (1) and (2) are true. D. Only (3) is true. iii. Given the following array declaration: const int SIZE = 5; int numbers[SIZE] = 10, 15, 20, 25, 30; Which of the following statements will display all the values in the array? A. for (int index= 1; index <= SIZE; index++) cout << numbers [index] << '\t'; B. for (int index = 0; index < SIZE; index++) cout << numbers [index] << '\t'; C. for (int index = 1; index < SIZE; index++) cout << numbers [index] << '\t'; iv. Which of the following is a correct declaration for a 2-dimensional array with 5 rows and 10 columns? A. int table[5][10]; B. int table [10][5]; C. int table[5], [10]; D. int table[10, 5); v. Given the following declarations: float num1 10.5, num2 = 5.2, temp; Which of the following statements will correctly swap the values of num1 and num2; A. B. C. D. num1 num2; num2 numl; num2 = num1; num1 num2; temp = numl; numl num2; num2 temp; temp = num2; num2 temp; num1 = num2; Page 3 vi. Study the program statements below and answer the question that follows. int num= 125; int *numPtr; numPtr&um; cout << numPtr << '\t << *numPtr; What will be displayed on the screen? A. memory address of variable numPtr, followed by a tab, followed by 125 B. memory address of variable num, followed by a tab, followed by 125 C. value of num in hexadecimal followed by a tab followed by 125 D. memory address of variable numPtr followed by a tab followed by NULL vii. Given the following statements: const int SIZE = 5; int values [SIZE] = { 10, 20, 30, 40, 50 }; for (index = 0; index < SIZE; index++) cout << values [index] << '\t'; Which of the following cout statements will produce the same output as the cout statement above? A. cout << *(values + index) B. cout << &(values + index) <<< '\t'; C. cout << *values [index] D. cout << &values [index] <<< '\t'; viii. Given the following statements: const int SIZE = 10; float sarray Ptr = new float [SIZE]; for (int index = 0; index < SIZE; index++) *(array Ptr + index) = index 10.0; //store value in array Which of the following is equivalent to the statement with the comment "store value in array"? A. arrayPtr[index] = index 10.0; B. &array Ptr [index] C. sarray Ptr [index] D. array Ptr + index Page 4 =index 10.0; = index 10.0; index 10.0; (b) What is the reason for undefined behaviour/errors that will occur when the following functions are called. multiply (int n) i. int { } ii. void { int Value n = 3; int q = &Value; ii. int int return q; (2 marks) set ToZero (int * const dptr) dptr = 0; } (c) Indicate if the following overloaded functions are valid or invalid. i. int get Minimum Value (int, int); int get Minimum Value (int, int, int); get Minimum Value (int, int); get Minimum Value (double, int); iii. int get Minimum Value (int, int); void get MinimumValue (int&, int&); (2) (2) (3) 4. Short questions (a) For each of the questions that follow, choose the most appropriate option. i. Which one of the following is a correct function header for a function that computes and returns the square root of a float value? A. void squareRoot( float value) B. float squareRoot(int value) C. int squareRoot( float value) D. float squareRoot( float value) ii. Which of the following statements about arrays are true? (1) An array may contain elements of different data types. (2) A constant array must have an initialisation list. (3) When an array is passed as an argument to a function, the function has access to the original array. A. (1), (2) and (3) are true. B. (2) and (3) are true. C. (1) and (2) are true. D. Only (3) is true. iii. Given the following array declaration: const int SIZE = 5; int numbers[SIZE] = 10, 15, 20, 25, 30; Which of the following statements will display all the values in the array? A. for (int index= 1; index <= SIZE; index++) cout << numbers [index] << '\t'; B. for (int index = 0; index < SIZE; index++) cout << numbers [index] << '\t'; C. for (int index = 1; index < SIZE; index++) cout << numbers [index] << '\t'; iv. Which of the following is a correct declaration for a 2-dimensional array with 5 rows and 10 columns? A. int table[5][10]; B. int table [10][5]; C. int table[5], [10]; D. int table[10, 5); v. Given the following declarations: float num1 10.5, num2 = 5.2, temp; Which of the following statements will correctly swap the values of num1 and num2; A. B. C. D. num1 num2; num2 numl; num2 = num1; num1 num2; temp = numl; numl num2; num2 temp; temp = num2; num2 temp; num1 = num2; Page 3 vi. Study the program statements below and answer the question that follows. int num= 125; int *numPtr; numPtr&um; cout << numPtr << '\t << *numPtr; What will be displayed on the screen? A. memory address of variable numPtr, followed by a tab, followed by 125 B. memory address of variable num, followed by a tab, followed by 125 C. value of num in hexadecimal followed by a tab followed by 125 D. memory address of variable numPtr followed by a tab followed by NULL vii. Given the following statements: const int SIZE = 5; int values [SIZE] = { 10, 20, 30, 40, 50 }; for (index = 0; index < SIZE; index++) cout << values [index] << '\t'; Which of the following cout statements will produce the same output as the cout statement above? A. cout << *(values + index) B. cout << &(values + index) <<< '\t'; C. cout << *values [index] D. cout << &values [index] <<< '\t'; viii. Given the following statements: const int SIZE = 10; float sarray Ptr = new float [SIZE]; for (int index = 0; index < SIZE; index++) *(array Ptr + index) = index 10.0; //store value in array Which of the following is equivalent to the statement with the comment "store value in array"? A. arrayPtr[index] = index 10.0; B. &array Ptr [index] C. sarray Ptr [index] D. array Ptr + index Page 4 =index 10.0; = index 10.0; index 10.0; (b) What is the reason for undefined behaviour/errors that will occur when the following functions are called. multiply (int n) i. int { } ii. void { int Value n = 3; int q = &Value; ii. int int return q; (2 marks) set ToZero (int * const dptr) dptr = 0; } (c) Indicate if the following overloaded functions are valid or invalid. i. int get Minimum Value (int, int); int get Minimum Value (int, int, int); get Minimum Value (int, int); get Minimum Value (double, int); iii. int get Minimum Value (int, int); void get MinimumValue (int&, int&); (2) (2) (3)
Expert Answer:
Answer rating: 100% (QA)
i D float squareRoot float value Rationale It is the correct function header for a function that com... View the full answer
Related Book For
Posted Date:
Students also viewed these computer network questions
-
If the cost of insuring your house is $1 per $1,000 of value, what will be the certainty equivalent of your end-of-year wealth if you insure your house at: a. its value. b. Its full value. c. 1...
-
The decline in real interest rates A. causes an increase in actual investment due to an increase in the cost of loans B. decreases the cost of borrowing which in turn increases investment spending C....
-
The probability that production will increase if interest rates decline more than 0.5 percentage point for a given period is 0.72. The probability that interest rates will decline by more than 0.5...
-
A survey of U.S. adults found that 33% name professional football as their favorite sport. You randomly select 14 U.S. adults and ask them to name their favorite sport. Find the probability that the...
-
Find the percentage errors of the approximations of Exercises 8.26 and 8.28, given that the actual value of the probability (rounded to five decimals) is 0.04596.
-
In this problem, we wish to understand the behavior of a singlepole on the real axis. Consider the simple \(R C\) circuit shown in Figure P9=57. The only energy in the circuit is an initial voltage...
-
From the following accounts of Kurlz Salon, Inc., prepare the businesss statement of retained earnings for the year ended December 31, 2010: Retained Earnings Dividends Clo 95,000 Jan 1 188,000 Mar...
-
The widget industry is a constant-cost industry, so that all firms are identical. The following chart shows the industry-wide demand curve and the marginal cost curve of a typical firm: The industry...
-
a. Suppose you noticed a cash deficit in investing activities. What would cause a cash deficit in this section? Is it a good or bad thing?
-
The client, Mr. David Keys, would like to know what state law provides concerning the removal of a director from the board of directors of a corporation. Prepare an information letter to Mr. Keys...
-
What is culture and Discuss what Model Minority Myth is and your reflection about it and how to avoid it happening and explain why? 9 Culture and Cultural Diversity and Their Relationship to Academic...
-
What is meant by presentation currency?
-
Describe the circumstances under which a modification in custody is likely to be sought and granted.
-
Describe e-discovery and give an example of when and how it might be sought.
-
Compressing a certain spring to \(50 \%\) of its relaxed length requires \(28 \mathrm{~J}\) of work. How much work would be required to compress the same spring by only half as much, to \(75 \%\) of...
-
Describe the nature of interrogatories and identify their strengths and weaknesses.
-
How do you think that years of purposeful "networking" can later help a person in their business endeavors, for example when they are trying to create new products and/or marketing campaigns? List 2...
-
Rewrite the code of Figure 7.3 in Ada, Java, or C#. Figure 7.3: template class queue { item items [max_items]; int next_free, next_full, num_items; public: queue () : next_free (0), next_full(0),...
-
If the business cycle is predictable, and a stock has a positive beta, the stocks returns also must be predictable. Respond.
-
Yields on short-term bonds tend to be more volatile than yields on long-term bonds. Suppose that you have estimated that the yield on 20-year bonds changes by 10 basis points for every 15-basis-point...
-
Spice asks Meyers to quantify price changes from changes in interest rates. To illustrate, Meyers computes the value change for the fixed-rate note in the table. Specifically, he assumes an increase...
-
The gross profit ratio is equal to: (a) profit divided by net sales. (b) cost of sales divided by net sales. (c) net sales minus cost of sales, divided by net sales. (d) net sales minus cost of...
-
What inventory cost flow method does Dominos Pizza Enterprises Ltd use for its inventories?
-
Which inventory cost flow method produces the highest profit in a period of rising prices?
Study smarter with the SolutionInn App