Each Question Is Worth 5 Points Unless Otherwise Noted
Total Page:16
File Type:pdf, Size:1020Kb
Name______Spring 2013 Sample Exam 3 CompSci117 Each question is worth 5 points unless otherwise noted.
____1. When an argument is ______it is protected from accidental change in the function. a. overloaded b. pass-by-reference c. pass-by-value d. Global
______2. The return statement in C++: A. Returns a value to the statement that called the function. B. Is used to stop execution of a function. C. Returns just one value. D. All of the above.
____3. A local variable is: a. Declared inside brackets{}. b. A private data member. c. Illegal. d. Declared outside any block.
____4. In the function call pow(2.0, 3.0), 2 and 3 are examples of: A. Subscripts. B. Operators. C. Parameters. D. Arguments.
____5. An advantage of using functions is: A. They help make decisions. B. They are used to store data. C. They break the program into manageable parts. D. They allow for input from files.
6. Do all functions need a return statement? Explain.
7. In the program below circle and label an example of each of the following. (5 points each)
A function call.
1 A parameter. A function definition. #include
8.Show the output of this program. #include
2 9.What is the output of this program? #include
10. Show the output. #include
11. Correct the error that causes the message when a compile is attempted.
3 1 #include 12. This program finds the area of a circle, using the radius input by the user. The output shows a incorrect value echoed for the radius. Correct the parameter list in the function to protect the radius from this change. //Finds the area of a circle. #include circleArea(radius, area, perimeter); //Function Call cout << "Circle with radius " << radius << " has area " << area << " and perimeter " << perimeter << endl; return 0; } Output: (User input is underlined.) Enter radius:3.0 Circle with radius 9 has area 28.2743 and perimeter 18.8495 4 13. In the program be below tell what the scope of each of the following names is: (10 points) a. TODEGREES b. dist #include 14. Write a function that takes a movie time in minutes, e.g. 125, and relays to the calling program the time in hours and minutes, 2 & 5. Make appropriate use of pass-by-reference and pass-by-value. (10 points) 5