Worksheets Name
function overloading in c++
Class
Total questions: 29
Worksheet time: 22mins
Date
Instructor name: Ms. Sandeepi B
Multiple Choice
1. A function can have _____ inside the parenthesis
a) loops b) Types
c) Braces d) Arguments/Parameters
Multiple Choice
2. A function that has no return type starts with:
a) int b) Braces
c) Arguments d) void
Multiple Choice
3. A function that returns a whole number starts with the word
a) string b) int
c) void d) { }
Multiple Choice
4. Fill in the blank to have this function work properly
_____ function ( ) {
string greeting = "Welcome to my game";
return greeting;
a) variable b) void
c) string d) int
Multiple Choice
5. Fill in the blank to have this function work properly
_____ function ( ) {
int a;
cin >> a;
cout<<"You chose " << a <<endl;
a) variable b) int
c) string d) void
Multiple Choice
6. True or False. We can call functions inside of other functions.
a) False b) True
Multiple Choice
7. True or False. A function that returns a string starts with the word void.
a) False b) True
Multiple Choice
8. Select all of the types you may have for a function
a) variable b) bool
c) string d) int
e) void
Multiple Choice
9. Fill in the blank to have this function work properly
double function ( ) {
int a;
cin >> a;
cout<<"You chose " << a <<endl;
return ____ ;
a) a * 3.14 b) "a"
c) cin d) a
Multiple Choice
10. A function that is not void needs to have a _____ _______
a) Return statement b) printing statement
c) variable calculation d) cout statement
Multiple Choice
11. A function __________ contains the statements that make up the function.
a) prototype b) call
c) expression d) definition
Multiple Choice
12. function is executed when it is
a) called b) prototyped
c) declared d) defined
Multiple Choice
13. This type of variable is defined inside a function and is not accessible outside
the function.
a) counter b) local
c) global d) reference
Multiple Choice
14. These types of arguments are passed to parameters automatically if no
argument is provided in the function call.
a) global b) reference
c) default d) local
Multiple Choice
15. It is good programming practice to __________ your functions by writing
comments that describe what they do.
a) create b) retrieve
c) document d) execute
Multiple Choice
16. A _________ variable is declared outside all functions.
a) global b) floating-point
c) local d) counter
Multiple Choice
17. The value in a __________ variable persists between function calls.
a) static local b) floating-point
c) dynamic d) local
Multiple Choice
18. Which of the following is a complete correct function definition?
a) int funct(int x){ x = x +1; return x; } b) void funct(x){ printf( “Hello”); }
c) void funct(int){ printf( “Hello”); d) int funct();
Multiple Choice
19. What is the return type of the function with prototype: "int func(char x, float v,
double t);"?
a) float b) char
c) double d) int
Multiple Choice
20.
What will the above code display?
a) 4 b) 4
4 2
c) 2 d) 2
4 2
Multiple Choice
21. When a class becomes a friend of another class they are additionally getting
access to:
a) Private b) None of the above
c) Public d) Protected
Multiple Choice
22. In a class the access specifiers are _______ by default:
a) Protected b) Public
c) Private
Multiple Choice
23. What does the word const do when placed at the end of a member function in a
class?
a) States the return type is constant b) It is required for C++
c) States the member variables will not d) None of the above
change
e) States the input arguments are
constant
Multiple Choice
24.
a) There will be a compile error and it b) Nothing will be output on the
will not run console
c) Equal strings d) None of the above
Multiple Choice
25.
a) III only b) I only
c) I and II only d) II only
e) II and II only
Multiple Choice
26. When overloading a function, the signature of the function is determined by:
a) The return type, name and number b) The name of the function and
of arguments and types. number of argument and types
c) The name of the function
Multiple Choice
27. What happens if the word static is placed in front of a member function in C++?
a) None of the above. b) It places the member function in the
static part of memory
c) It will cause an error and the d) The member function can be called
program will not compile. even if we do not create an instance
of the class.
Multiple Choice
28. What does the word virtual do when placed in front of a member function in
C++?
a) Does not place the function in text b) Forces derived classes to define the
segment if it is not called. function to compile.
c) None of the above. d) Allows derived classes, not required,
to define the function.
Multiple Choice
29. What is the difference when allocating the following memory?
int array1[15];
int array2[3][5];
a) The size allocated is the same b) array1 is larger
c) array2 is larger
Answer Keys
1. d) Arguments/Parameters
2. d) void 3. b) int
4. c) string 5. d) void 6. b) True
7. a) False 8. d) int , void , bool , string
9. a) a * 3.14
e) b) c)
10. a) Return statement 11. d) definition 12. a) called
13. b) local 14. c) default 15. c) document
16. a) global 17. a) static local 18. a) int funct(int x){ x =
x +1; return x; }
19. d) int 20. b) 4 2 21. a) Private
22. c) Private 23. c) States the 24. b) Nothing will be
member variables output on the
will not change console
25. d) II only 26. b) The name of the 27. d) The member
function and function can be
number of called even if we
argument and do not create an
types instance of the
class.
28. d) Allows derived 29. a) The size allocated
classes, not is the same
required, to define
the function.