1. (2) main() is a function. a. true b. false c. it depends on how you define it
ID: 3651839 • Letter: 1
Question
1. (2) main() is a function.a. true
b. false
c. it depends on how you define it
2. (2) A function knows _______ about the calling code.
a. something
b. nothing
c. everything
3. (2) Every function must return a value.
a. true
b. false
4. (2) It is legal and acceptable to have two local variables in two different functions with the same name and the same data type.
a. true
b. false
c. only if they always have different values
d. only if they always have the same value
5. (2) With what we have learned so far about C++ functions, a function can directly (i.e. by itself, not as a consequence of an assignment statement in the calling function) alter _____________ in the calling function
a. no values
b. at most 1 value
c. 1 or more values
6. (4) Write a complete function that will return the larger of two integers.
7. (4) Write a complete function that will return the area of a triangle given the base and altitude. Allow real values. The area of a triangle is one-half the base times the altitude.
8. (2) A function exists called calc(). It takes two integer arguments and returns a real result. Assume
int a = 4, b = 5;
Write a single statement that will print the result of calling calc() with these arguments.
9. (2) If a function takes two integer arguments it
a. must return an int
b. must return a numeric value of some kind
c. can return any valid data type
Explanation / Answer
1)Main() is a function and it is the starting point of execution for a program . Main function is called by the operating system when the program is executed.
Hence, the correct option is “a”. That is , true.
2)A function can’t see anything about the calling function. That is , a function did not know anything about the calling function or calling code.
Hence, the correct option is “b”. That is, “nothing”.
3)A function’s return type specifies that which type of data the function should return. For example, if the return type is integer, then the function should return integer data. If the return type is double, the function should return double type of data. If the return type is void, the function needs not to return any data.
That is, every function may not return a value.
Hence, the correct option is “b”. That is, false.
4)Every variable in the program have a scope. A variable may be global or local. Scope of a variable defines the visibility of a variable.
If a variable is declared as global , the variable is visible throughout the whole program.
If a variable is declared as local variable in a function, then the variable is visible only in that function. Thus, two local variable with same name and same type may be declared in two different functions. But two local variables with same name and same type must not be declared in the same function, because of the ambiguity problem.
Hence the correct option is “a”. That is true.
5)If parameters are passed using call by reference, then the function may alter more than one values. Thus, the function can directly change one or more values in the calling function.
Hence, the correct option is “c”. That is, “1 or more values”.
6)
int largerOfTwoInts(int x, int y)
{
if ( x>y)
return x;
else
return y;
}
7)
double areaOfTriangle(double b, double a)
{
double area=0;
area=0.5*b*a;
return area;
}
8)
Since the function is returning a real value, it can directly print using the following statement:
cout<<calc(4,5);
9)
The return type is not depends on the input arguments. Thus, a function may return any valid data type.
Hence the correct option is “c”. That is “can return any valid data type”.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.