Determine whether the following program segments contain errors. For each error, explain how it can be corrected. [Note: For a particular program segment, it’s possible that no errors are present.]
```
a)
template
int sum(int num1, int num2, int num3) {
return num1 + num2 + num3;
}
b)
void printResults(int x, int y) {
cout << "The sum is " << x + y << '\n';
return x + y;
}
c)
template
A product(A num1, A num2, A num3) {
return num1 * num2 * num3;
}
d) double cube(int);
int cube(int);
```
a) Error: The function return type and parameter types are int.
Correction: The function return type and parameter types should be A or the function should not be a template.
b) Error: The function specifies a void return type and attempts to return a value.
Two possible solutions: (1) change void to int, or (2) remove the line return x + y;.
c)Error: Keyword class is missing in the template declaration.
Correction: Insert keyword class (or keyword typename), as in template
d) Error: The signatures are not different. Overloaded functions must have different signatures—the name and/or parameter list must be different. If only the returns types differ, the compiler generates an error message.
Correction: Change either the name or parameter list of one of the functions.
You might also like to view...
The structure shown in the accompanying figure is a hierarchical structure.
Answer the following statement true (T) or false (F)
Where are
tags placed?a. Directly after the opening
tag and must be closed right before the closing tag b. Anywhere in the HTML document c. Anywhere in the body of a web page d. In the sectionDoes this function sort ascending or descending?
``` 1. function bubbleIt(A, B) 2. { 3. var flag = 0; var temp = 0; 4. while (flag == 0) 5. { 6. flag = 1; 7. for (var count = 0; count <= (A – 2); count++) 8. { 9. if(myArray[count] < myArray[count + 1]) 10. { 11. temp = myArray[count]; 12. myArray[count] = myArray[count + 1]; 13. myArray[count + 1} = temp; 14. flag = 0; 15. } 16. } 17. } 18. } ``` a. ascending b. descending
Any smartphone with an FM radio chip can be used to receive FM radio
Indicate whether the statement is true or false