Lecture 21 Quiz Review Introduction to Computer Science

  • Slides: 32
Download presentation
Lecture 21: Quiz Review Introduction to Computer Science Spring 2006 1

Lecture 21: Quiz Review Introduction to Computer Science Spring 2006 1

1. What value is returned by the return statement above? a 0. b 5.

1. What value is returned by the return statement above? a 0. b 5. c 6. d 7. 2

2. Given the following function prototype: int test(float, char); which of the following statements

2. Given the following function prototype: int test(float, char); which of the following statements is valid? a cout<<test(12, &); . b cout<<test(“ 12. 0”, '&'); . c int u = test(5. 0, '*'); . d cout<<test('12', '&'); . 3

3. To use the predefined function tolower, the program must include the header file

3. To use the predefined function tolower, the program must include the header file _____. a cctype. c cmath. b iostream. d cstdlib. 4

4. A function prototype is _____. a a definition, but not a c a

4. A function prototype is _____. a a definition, but not a c a declaration, but not. declaration. a definition b a declaration and a. definition d a comment line. 5

5. Given the following function prototype: double try. Me(double, double); which of the following

5. Given the following function prototype: double try. Me(double, double); which of the following statements is valid? Assume that all variables are properly declared. a cin>>try. Me(x, y); . b cout<<try. Me(2. 0, 3. 0); . c cout<<try. Me(double, double); . d cout<<try. Me(float, float); . 6

6. Given the following function prototype: int my. Func(int, int); which of the following

6. Given the following function prototype: int my. Func(int, int); which of the following statements is valid? Assume that all variables are properly declared. a cin>>my. Func(x, y); . b cout<<my. Func(7, 8), 15); . c cin>>my. Func(‘ 2’, ‘ 3’); . d cout<<my. Func(7), 15); . 7

7. Given the above function, choose the output of the following statement: cout<<mystery(9, 7);

7. Given the above function, choose the output of the following statement: cout<<mystery(9, 7); . a 2. c 7. b 4. d 9. 8

8. Given the above function, choose the output of the following statement: cout<<strange(4, 5);

8. Given the above function, choose the output of the following statement: cout<<strange(4, 5); . a -1. c 9. b 1. d 20. 9

9 Assume the above. The output of the statement: cout<<static_cast<int>(tolower('B')); is _____. a 65.

9 Assume the above. The output of the statement: cout<<static_cast<int>(tolower('B')); is _____. a 65. c 96. b 67. d 98. 10

10. Given the function prototype: double test. Alpha(int u, char v, double t); which

10. Given the function prototype: double test. Alpha(int u, char v, double t); which of the following statements is legal? a cout<<test. Alpha(5, 'A', 2); . b cout<<test. Alpha( int 5, char 'A', int 2); . c cout<<test. Alpha(‘ 5. 0’, 'A', 2. 0); . d cout<<test. Alpha(5. 0, 65, 2. 0); . 11

11. Which of the following function prototypes is valid? a int func. Test(int x,

11. Which of the following function prototypes is valid? a int func. Test(int x, int y, float z){}. b func. Test(int x, int y, float){}; . c int func. Test(int, int y, float z). d int func. Test(int, float); . 12

12. Given the function prototype: float test(); , which of the following statements is

12. Given the function prototype: float test(); , which of the following statements is legal? a cout<<test; . c cout<<test(); . b cout<<test(void); . d cout<<test(“Out”). ; 13

13. The output of the statement: cout<<pow(2, pow(3, 1)); is _____. a 6. c

13. The output of the statement: cout<<pow(2, pow(3, 1)); is _____. a 6. c 8. b 7. d 9. 14

14. The standard header file for the abs(x)function is _____. a <cmath>. c <cctype>.

14. The standard header file for the abs(x)function is _____. a <cmath>. c <cctype>. b <ioinput>. d <cstdlib>. 15

15. Functions that do not have a data type are called _____ functions. a

15. Functions that do not have a data type are called _____ functions. a zero. c void. b null. d empty. 16

16. Which statement about prototypes and headers is true? a Parameter names must be

16. Which statement about prototypes and headers is true? a Parameter names must be listed in the prototype, . but not necessarily in the header. b Prototypes end with a semicolon, but headers do. not. c Headers should come before prototypes. . d Headers end with a semicolon, but prototypes do. not. 17

17. A variable listed in a function call is known as a(n) _____ parameter.

17. A variable listed in a function call is known as a(n) _____ parameter. A variable list in a header is known as a(n) _____ parameter. a actual; actual. c actual; formal. b formal; formal. d formal; actual. 18

18. If an & is attached after the data type of a formal parameter,

18. If an & is attached after the data type of a formal parameter, then the formal parameter is a _____. a value parameter. c global variable. b reference parameter. d default variable. 19

19. What are the values of x and y after the statements above execute?

19. What are the values of x and y after the statements above execute? (Assume that variables are properly declared. ) a x = 10; y = 10. c x = 15; y = 10. b x = 10; y = 15. d x = 15; y = 15. 20

20. What are the values of one and letter after the statements above execute?

20. What are the values of one and letter after the statements above execute? a one = 5; letter = 'A'. b one = 10; letter = 'A'. c one = 10; letter = 'B'. d one = 12; letter = 'B'. 21

21. parameters are useful when you want to return more than one value from

21. parameters are useful when you want to return more than one value from a function. a Default. c Reference. b Value. d Automatic. 22

22. Suppose that print. Heading is a function without any parameters. Which of the

22. Suppose that print. Heading is a function without any parameters. Which of the following is a valid function heading? a void. b void. c void. d void. print. Heading() print. Heading(no. Parameters) print. Heading(); print. Heading(void); 23

23. A void function accomplish has three parameters: a parameter u of the type

23. A void function accomplish has three parameters: a parameter u of the type int, a parameter v of the type double, and a parameter letter of the type char. The parameters u and letter need to pass their values out of the function and the parameter v is to only receive the value from the calling environment. Which of the following is a correct function heading? a void accomplish(int& u, double v, char& letter) b. void accomplish(int u, double& v, char letter) c. void accomplish(int& u, double v, char& letter); d. void accomplish(int u, double& v, char letter); 24

24. Suppose that you are given the function definition above. What is the output

24. Suppose that you are given the function definition above. What is the output of the following statements? print. Some. Thing(1); print. Some. Thing(2); print. Some. Thing(3); a ******. b *. * * * c. d. * * * * 25

25. What is the output of the program shown above? a 1 1. 3

25. What is the output of the program shown above? a 1 1. 3 1 c 1 2. 2 3 b 1 2. 1 3 d 2 2. 2 3 26

26. Which of the following is a legal C++ function definition? a void func.

26. Which of the following is a legal C++ function definition? a void func. Test(int& u, double& v) { cout<<u<<" "<<v<<endl; } b void func. Test(int& u, double& v); . { cout<<u<<" "<<v<<endl; } c void func. Test(int& u, double& v). ( cout<<u<<" "<<v<<endl ) d void func. Test(int& u, double& v). [ cout<<u<<" "<<v<<endl; ] 27

27. What is the output of the C++ code above? a 4 5. c

27. What is the output of the C++ code above? a 4 5. c 6 5. b 6 4. d 6 6. 28

28. Based on the function definition above, which of the following statements is valid?

28. Based on the function definition above, which of the following statements is valid? a one is a value parameter and two is a reference. parameter. b one is a reference parameter and two is a value. parameter. c one and two are reference parameters. . d one and two are value parameters. . 29

29. Which of the following is a legal C++ function definition? a void func.

29. Which of the following is a legal C++ function definition? a void func. Alpha(int u, double v &) { cout<<u<<" "<<v<<endl; } b void func. Alpha(int #, double #). { cout<<u<<" "<<v<<endl; } c void func. Alpha(int &, double &). { cout<<u<<" "<<v<<endl; } d void func. Alpha(int u, double& v). { cout<<u<<" "<<v<<endl; } 30

30. In C++, the scope resolution operator is _____. a |. b. . c

30. In C++, the scope resolution operator is _____. a |. b. . c : . d : : . 31

#include <iostream> void Calc. Rectangle(double length, double width, double& circum, double& area); void Print.

#include <iostream> void Calc. Rectangle(double length, double width, double& circum, double& area); void Print. Result(double length, double width, double circum, double area); using namespace std; int main() { double length, width, circumference, area; cout<< “This program will calculate the circumference and area of the rectangle. ” cout << “Please input the length and width of the rectangle: ” << endl; cin>>length >> width; Calc. Rectangle(length, width, circum, area); Print. Result(length, width, circum, area); return 0; } void Calc. Rectangle(double length, double width, double& circum, double& area); { circum = 2*(length+width); area = length * width; } void Print. Result(double length, double width, double circum, double area); { cout << “Length = ” << length <<endl; cout << “ Width = ”<< width <<endl; cout << “ Circumference = ” << circum <<endl; cout << “ Area = ”<< area <<endl; } 32