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...
Temporal Key Integrity Protocol (TKIP) has three major components to address vulnerabilities. List and describe them.
What will be an ideal response?
Primary keys must be numbers that already represent something (like a telephone number.)
Answer the following statement true (T) or false (F)