Deck 6: User-Defined Functions
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
العب
ملء الشاشة (f)
Deck 6: User-Defined Functions
1
To use the predefined function tolower,the program must include the header file ____.
A)
B)
C)
D)
A)
B)
C)
D)
A
2
Using functions greatly enhances a program's readability because it reduces the complexity of the function main.
True
3
The data type of a variable in a return statement must match the function type.
True
4
The output of the statement: cout << pow(2.0,pow(3.0,1.0))<< endl;
Is ____.
A) 6.0
B) 7.0
C) 8.0
D) 9.0
Is ____.
A) 6.0
B) 7.0
C) 8.0
D) 9.0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
The output of the statement: cout << pow(3.0,2.0)+ 5 << endl; is ____.
A) 11.0
B) 12.0
C) 13.0
D) 14.0
A) 11.0
B) 12.0
C) 13.0
D) 14.0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
The function main is always compiled first,regardless of where in the program the function main is placed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
Assume the following. static_cast('a')= 97
Static_cast('A')= 65
The output of the statement:
Cout << static_cast(tolower('B'))<< endl; is ____.
A) 65
B) 67
C) 96
D) 98
Static_cast
The output of the statement:
Cout << static_cast
A) 65
B) 67
C) 96
D) 98
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
Assume that all variables are properly declared.The following statement in a value-returning function is legal.
if (x % 2 == 0)
return x;
else
return x + 1;
if (x % 2 == 0)
return x;
else
return x + 1;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
The execution of a return statement in a user-defined function terminates the program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
The following return statement returns the value 10.
return 10,16;
return 10,16;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
A variable or expression listed in a call to a function is called the ____.
A) formal parameter
B) actual parameter
C) data type
D) type of the function
A) formal parameter
B) actual parameter
C) data type
D) type of the function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The heading of the function is also called the ____.
A) title
B) function signature
C) function head
D) function header
A) title
B) function signature
C) function head
D) function header
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
Functions that do not have a return type are called ____ functions.
A) zero
B) null
C) void
D) empty
A) zero
B) null
C) void
D) empty
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
The following function heading in a C++ program is valid:
int funcExp(int u,char v,float g)
int funcExp(int u,char v,float g)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
In C++,a function prototype is the function heading without the body of the function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
If the formal parameter list of a function is empty,the parentheses after the function name are not needed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
The output of the statement: cout << tolower('$')<< endl;
Is ____.
A) '$'
B) '0'
C) '1'
D) An error, because you cannot use tolower with '$'.
Is ____.
A) '$'
B) '0'
C) '1'
D) An error, because you cannot use tolower with '$'.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
The standard header file for the abs(x)function is ____.
A)
B)
C)
D)
A)
B)
C)
D)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
Once you write and properly debug a function,you can use it in the program (or different programs)again and again without having to rewrite the same code repeatedly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
A variable listed in a header is known as a(n)____ parameter.
A) actual
B) local
C) formal
D) function
A) actual
B) local
C) formal
D) function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
The statement: return 8,10; returns the value ____.
A) 8
B) 10
C) 18
D) 80
A) 8
B) 10
C) 18
D) 80
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
The statement: return 37,y,2 * 3; returns the value ____.
A) 2
B) 3
C) y
D) 6
A) 2
B) 3
C) y
D) 6
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
The statement: return 2 * 3 + 1,1 + 5; returns the value ____.
A) 2
B) 3
C) 6
D) 7
A) 2
B) 3
C) 6
D) 7
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
Given the following function prototype: double tryMe(double,double);,which of the following statements is valid? Assume that all variables are properly declared.
A) cin >> tryMe(x);
B) cout << tryMe(2.0, 3.0);
C) cout << tryMe(tryMe(double, double), double);
D) cout << tryMe(tryMe(float, float), float);
A) cin >> tryMe(x);
B) cout << tryMe(2.0, 3.0);
C) cout << tryMe(tryMe(double, double), double);
D) cout << tryMe(tryMe(float, float), float);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which statement below 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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
Given the following function prototype: int myFunc(int,int);,which of the following statements is valid? Assume that all variables are properly declared.
A) cin >> myFunc(y);
B) cout << myFunc(myFunc(7, 8), 15);
C) cin >> myFunc('2', '3');
D) cout << myFunc(myFunc(7), 15);
A) cin >> myFunc(y);
B) cout << myFunc(myFunc(7, 8), 15);
C) cin >> myFunc('2', '3');
D) cout << myFunc(myFunc(7), 15);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
____________________ parameters are useful in three situations:
• When the value of the actual parameter needs to be changed
• When you want to return more than one value from a function
• When passing the address would save memory space and time relative to copying a large amount of data
• When the value of the actual parameter needs to be changed
• When you want to return more than one value from a function
• When passing the address would save memory space and time relative to copying a large amount of data
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
What value is returned by the following return statement? int x = 5;
Return x + 1;
A) 0
B) 5
C) 6
D) 7
Return x + 1;
A) 0
B) 5
C) 6
D) 7
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
A(n)____________________ parameter is a formal parameter that receives the location (memory address)of the corresponding actual parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
A function prototype is ____.
A) a definition, but not a declaration
B) a declaration and a definition
C) a declaration, but not a definition
D) a comment line
A) a definition, but not a declaration
B) a declaration and a definition
C) a declaration, but not a definition
D) a comment line
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
If a formal parameter is a nonconstant reference parameter,during a function call,its corresponding actual parameter must be a(n)____________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
A(n)____________________ parameter s a formal parameter that receives a copy of the content of the corresponding actual parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
When you attach & after the dataType in the formal parameter list of a function,the variable following that dataType becomes a(n)____________________ parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
Given the following function: int strange(int x,int y)
{
If (x > y)
Return x + y;
Else
Return x - y;
}
What is the output of the following statement?
Cout << strange(4,5)<< endl;
A) -1
B) 1
C) 9
D) 20
{
If (x > y)
Return x + y;
Else
Return x - y;
}
What is the output of the following statement?
Cout << strange(4,5)<< endl;
A) -1
B) 1
C) 9
D) 20
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Given the following function: int next(int x)
{
Return (x + 1);
}
What is the output of the following statement?
Cout << next(next(5))<< endl;
A) 5
B) 6
C) 7
D) 8
{
Return (x + 1);
}
What is the output of the following statement?
Cout << next(next(5))<< endl;
A) 5
B) 6
C) 7
D) 8
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
Given the function prototype: double testAlpha(int u,char v,double t); which of the following statements is legal?
A) cout << testAlpha(5, 'A', 2);
B) cout << testAlpha( int 5, char 'A', int 2);
C) cout << testAlpha('5.0', 'A', '2.0');
D) cout << testAlpha(5.0, "65", 2.0);
A) cout << testAlpha(5, 'A', 2);
B) cout << testAlpha( int 5, char 'A', int 2);
C) cout << testAlpha('5.0', 'A', '2.0');
D) cout << testAlpha(5.0, "65", 2.0);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
37
Which of the following function prototypes is valid?
A) int funcExp(int x, float v);
B) funcExp(int x, float v){};
C) funcExp(void);
D) int funcExp(x);
A) int funcExp(int x, float v);
B) funcExp(int x, float v){};
C) funcExp(void);
D) int funcExp(x);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
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', '&');
A) cout << test(12, &);
B) cout << test("12.0", '&');
C) int u = test(5.0, '*');
D) cout << test('12', '&');
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
39
Which of the following function prototypes is valid?
A) int funcTest(int x, int y, float z){}
B) funcTest(int x, int y, float){};
C) int funcTest(int, int y, float z)
D) int funcTest(int, int, float);
A) int funcTest(int x, int y, float z){}
B) funcTest(int x, int y, float){};
C) int funcTest(int, int y, float z)
D) int funcTest(int, int, float);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
Given the function prototype: float test(int,int,int);
Which of the following statements is legal?
A) cout << test(7, test(14, 23));
B) cout << test(test(7, 14), 23);
C) cout << test(14, 23);
D) cout << test(7, 14, 23);
Which of the following statements is legal?
A) cout << test(7, test(14, 23));
B) cout << test(test(7, 14), 23);
C) cout << test(14, 23);
D) cout << test(7, 14, 23);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
A variable for which memory remains allocated as long as the program executes is called a(n)____________________ variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
____________________ identifiers are not accessible outside of the function (block).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
In C++,:: is called the ____________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
If a function needs to return more than one value,as a rule of good programming style,you should change it to a(n)____________________ function and use the appropriate reference parameters to return the values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
A function ____________________ is a function that is not fully coded.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
The ____________________ of an identifier refers to where in the program an identifier is accessible (visible).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
The ____________________ of a function consists of the function name and its formal parameter list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
A variable for which memory is allocated at block entry and deallocated at block exit is called a(n)____________________ variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
Stream variables (for example,ifstream and ofstream)should be passed by ____________________ to a function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
The program that tests a function is called a(n)____________________ program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck