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...
-
Demand for a certain product is 25,000 units/yr. Unit cost is $10.00. Holding cost rate is 30%/yr. Changeover (setup) time between products is 10.0 hr, and downtime cost during changeover is $150/hr....
-
Use the European option-pricing models developed in the chapter to value the call of problem 9 and the put of problem 10. Assume the annualized volatility of the Swiss franc is 14.2 percent. This...
-
Plaintiff grounds manager sued a manufacturer, Monsanto, alleging that herbicide use caused his non-Hodgkins lymphoma. The jury awarded the plaintiff \($39.3\) million in compensatory damages and...
-
The Town of Wilson has a Water Utility Fund with the following trial balance as of July 1, 2011, the first day of the fiscal year: During the year ended June 30, 2012, the following transactions and...
-
Explain the relationship and the difference between online analytical processing systems and customer relationship management systems within a business intelligence program.?
-
Kitchen Care Inc. (KCI) is a manufacturer of toaster ovens. To improve control over operations, the president of KCI wants to begin using a flexible budgeting system, rather than use only the current...
-
Assume that you purchased 1000 shares of Super Performing mutual fund at a net asset value of $22 per share. During the year you received dividend income distributions of $2.50 per share and capital...
-
Ryan left the U.S. for Estonia, where he took a position as VP of EMEA Operations for a U.S. employer. He did not establish residency because he only anticipated being in Estonia for two years. His...
-
Leah operates a side hustle as a baker. Her total sales were $6,825. Her cost of goods sold (COGS) was $2,616, and other expenses totaled $1,973. What is Leah's self-employment (SE) tax total?
-
Explain the significance and structure of the "Consolidated Statement of Cash Flows". How does it differ from the cash flow statement of an individual entity?
-
When is it not What is Apple attempting to achieve? How is it possible that Apple, as a U.S. company, does not pay the regular corporate tax rate? appropriate to deduct subsidiary preferred dividends...
-
What would be a drawback when using the API Profile System?
-
Assume that you have been assigned the 166.70.9.28/20 network block. Define an extended-network-prefix that allows the creation of 13 subnets. 1. What is the maximum number of subnets that can be...
-
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...
-
With regard to genotypes, what is a true-breeding organism?
-
With regard to biological evolution, which of the following statements is incorrect? Explain why. A. During its lifetime, an animal evolves to become better adapted to its environment. B. The process...
-
Marfan syndrome is a rare inherited human disorder characterized by unusually long limbs and digits plus defects in the heart (especially the aorta) and the eyes, among other symptoms. Following is a...
Study smarter with the SolutionInn App