Deck 3: Function Basics

ملء الشاشة (f)
exit full mode
سؤال
Of what value are comments that accompany a function declaration?
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Consider two blocks,one within another.C++ prohibits an identifier to be declared as a variable in each of these blocks.
سؤال
Define a function named average_grade.This function returns a double and has four double arguments,test1,test2,test3,test4.The return value should be the average,or arithmetic mean of the four arguments.Be sure to include a comment that tells briefly what the function does.
سؤال
Each of the following lines of code purport to round the results of the division of doubles to the nearest integer value (but still of type double).All are correct C++ code but some do not round correctly.Tell which rounds down,up,or to the nearest integer value,or is not reasonable
Assume that math.h has been included,and that all variables have appropriate values.
double x,y,z;
a)z = ceil(x/y);
b)z = ceil(x/y-0.5);
c)z = floor(x/y-0.5);
d)z = floor(x/y+0.5);
e)z = floor(x/y);
سؤال
A variable declared within a function block is said to be local to the function.
سؤال
A variable declared outside any function is said to be a local variable.
سؤال
What is the error in the following code? Why is this wrong?
int f(int x)
{
int x;
// code for function body
}
سؤال
Calling something a black box is a figure of speech that conveys the idea that you cannot see inside.You know its behavior and interface but not its implementation.
سؤال
It is legal to replace the prototype
double totalCost(int numberParam,double priceParam);
with the more terse,alternate form
double totalCost(int,double);
سؤال
A sequence of calls to the library function rand()generates mathematically correct random number sequences.
سؤال
Consider two blocks,one within another.If an identifier is declared as a variable in the inmost of these two blocks,one can access this variable from the outer block.
سؤال
Given the function declaration (prototype),does the compiler complain or compile if you call this using the following line? If the compiler complains,what is the complaint?
//if score >= min_to_pass,returns 'P' for passing,
//else returns 'F' for failing.
char grade (int score,int min_to_pass);
int main()
{
double fscore;
char fgrade;
int need_to_pass;
//omitted code to get values for variables
//fscore and need
fgrade = grade(fscore,need);
return 0;
}
سؤال
Extensive use of global variables is a satisfactory replacement for the difficulties of parameter passing with functions.
سؤال
Code after a return or a call to the exit function is executed will not be executed.
سؤال
Procedural abstraction involves information hiding in that only the 'contract' between the programmer using the function (the client)and author of a function is known to either.
سؤال
In C++ Boolean value are represented only with the int values 0 for false and 1 for true.
سؤال
Every programmer must know all the details of what that programmer's team mates are doing in their projects to do the work assigned.Why?
سؤال
Declare (give a prototype for)a function named average_grade.This function returns a double and has four double arguments,test1,test2,test3,test4.The return value should be the average,or arithmetic mean of the four arguments.Be sure to include a "prototype comment" that tells briefly what the function does.
سؤال
Give an outline for the general form of a programmer defined function.
سؤال
In your own words discuss similarities and differences between a function and a small program.
سؤال
Assume this code fragment is embedded in an otherwise correct and complete program.What should be the output from this code segment? {
For( int i = 0;i < 10;i++)
{
)..
}
Cout << i << endl;
}

A)10
B)9
C)0
D)The variable i is undefined in this scope,so this should not compile
سؤال
A void function can have >>"void" is wrong font.

A)no arguments
B)as many arguments as the programmer wishes
C)no more than 3 arguments
D)exactly one argument
سؤال
What do the calls to exit(…)do? When exit(0)and exit(1)are called,what receives these arguments and what is done with them?

A)The exit( )function stops the program.The argument is discarded.
B)The exit( )function is obsolete.There is no longer any such function in the C++ libraries.
C)The exit( )function stops the program.The argument is passed to the operating system which uses it for an error code.
D)The exit( )function temporarily stops the program,and sends the argument to the operating system which uses it for an error code.The operating system restarts the program after fixing the error.
E)The exit( )function allows the systems programmer to escape when the power supply catches fire.
سؤال
Write a function definition for a function called inOrder that takes three arguments of type int.The function returns true if the arguments are in increasing order left to right;otherwise inOrder returns false.For example,inOrder(1,2,3)returns true,whereas inOrder(1,3,2)returns false.
سؤال
,A definition of a variable outside any function is called a

A)local function definition
B)global variable definition
C)global function header
D)global function definition
E)local variable definition
سؤال
A call to a C++ function is

A)The name of the function followed by empty parentheses.
B)The name of the function followed by any number of arguments,regardless of the number of parameters in the definition.
C)The name of the function followed by a number of arguments not greater than the number of parameters in the definition.
D)The name of the function followed by exactly the number of arguments as there are parameters in the definition.
E)The name of the function only.
سؤال
Where can you not declare a variable in a C++ program?

A)Within the parameter list of a function definition
B)Within the block of a void function.
C)Within the argument list of a function call
D)Within a block nested within another block
E)Within the block of a value returning function.
سؤال
Write a function definition called even that takes one argument of type int and returns a bool value.The function returns true if its one argument is an even number;otherwise it returns false.
سؤال
Write a function definition for a isDigit function that takes one argument of type char and returns a bool value.The function returns true if the argument is a decimal digit;otherwise it returns false.
سؤال
Write a prototype and prototype comments for the sqrt library function.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/30
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 3: Function Basics
1
Of what value are comments that accompany a function declaration?
These comments describe the requirements for correct behavior of the function and the value returned by the function and any other effects of the function for a person who does might not have access to or the desire to read the source code.
2
Consider two blocks,one within another.C++ prohibits an identifier to be declared as a variable in each of these blocks.
False
3
Define a function named average_grade.This function returns a double and has four double arguments,test1,test2,test3,test4.The return value should be the average,or arithmetic mean of the four arguments.Be sure to include a comment that tells briefly what the function does.
// returns arithmetic mean of the arguments test1 - test4
double average_grade (double test1-,double test2,
double test3,double test4)
{
double average;
average = (test1 + test2 + test3 + test4)/ 4;
return average;
}
This slightly more terse definition is sufficient:
//returns arithmetic mean of the arguments test1 - test4
double average_grade (double test1,double test2,
double test3,double test4)
{
return (test1 + test2 + test3 + test4)/ 4;
}
4
Each of the following lines of code purport to round the results of the division of doubles to the nearest integer value (but still of type double).All are correct C++ code but some do not round correctly.Tell which rounds down,up,or to the nearest integer value,or is not reasonable
Assume that math.h has been included,and that all variables have appropriate values.
double x,y,z;
a)z = ceil(x/y);
b)z = ceil(x/y-0.5);
c)z = floor(x/y-0.5);
d)z = floor(x/y+0.5);
e)z = floor(x/y);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
5
A variable declared within a function block is said to be local to the function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
6
A variable declared outside any function is said to be a local variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
7
What is the error in the following code? Why is this wrong?
int f(int x)
{
int x;
// code for function body
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
8
Calling something a black box is a figure of speech that conveys the idea that you cannot see inside.You know its behavior and interface but not its implementation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
9
It is legal to replace the prototype
double totalCost(int numberParam,double priceParam);
with the more terse,alternate form
double totalCost(int,double);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
10
A sequence of calls to the library function rand()generates mathematically correct random number sequences.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
11
Consider two blocks,one within another.If an identifier is declared as a variable in the inmost of these two blocks,one can access this variable from the outer block.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
12
Given the function declaration (prototype),does the compiler complain or compile if you call this using the following line? If the compiler complains,what is the complaint?
//if score >= min_to_pass,returns 'P' for passing,
//else returns 'F' for failing.
char grade (int score,int min_to_pass);
int main()
{
double fscore;
char fgrade;
int need_to_pass;
//omitted code to get values for variables
//fscore and need
fgrade = grade(fscore,need);
return 0;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
13
Extensive use of global variables is a satisfactory replacement for the difficulties of parameter passing with functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
14
Code after a return or a call to the exit function is executed will not be executed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
15
Procedural abstraction involves information hiding in that only the 'contract' between the programmer using the function (the client)and author of a function is known to either.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
16
In C++ Boolean value are represented only with the int values 0 for false and 1 for true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
17
Every programmer must know all the details of what that programmer's team mates are doing in their projects to do the work assigned.Why?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
18
Declare (give a prototype for)a function named average_grade.This function returns a double and has four double arguments,test1,test2,test3,test4.The return value should be the average,or arithmetic mean of the four arguments.Be sure to include a "prototype comment" that tells briefly what the function does.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
19
Give an outline for the general form of a programmer defined function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
20
In your own words discuss similarities and differences between a function and a small program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
21
Assume this code fragment is embedded in an otherwise correct and complete program.What should be the output from this code segment? {
For( int i = 0;i < 10;i++)
{
)..
}
Cout << i << endl;
}

A)10
B)9
C)0
D)The variable i is undefined in this scope,so this should not compile
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
22
A void function can have >>"void" is wrong font.

A)no arguments
B)as many arguments as the programmer wishes
C)no more than 3 arguments
D)exactly one argument
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
23
What do the calls to exit(…)do? When exit(0)and exit(1)are called,what receives these arguments and what is done with them?

A)The exit( )function stops the program.The argument is discarded.
B)The exit( )function is obsolete.There is no longer any such function in the C++ libraries.
C)The exit( )function stops the program.The argument is passed to the operating system which uses it for an error code.
D)The exit( )function temporarily stops the program,and sends the argument to the operating system which uses it for an error code.The operating system restarts the program after fixing the error.
E)The exit( )function allows the systems programmer to escape when the power supply catches fire.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
24
Write a function definition for a function called inOrder that takes three arguments of type int.The function returns true if the arguments are in increasing order left to right;otherwise inOrder returns false.For example,inOrder(1,2,3)returns true,whereas inOrder(1,3,2)returns false.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
25
,A definition of a variable outside any function is called a

A)local function definition
B)global variable definition
C)global function header
D)global function definition
E)local variable definition
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
26
A call to a C++ function is

A)The name of the function followed by empty parentheses.
B)The name of the function followed by any number of arguments,regardless of the number of parameters in the definition.
C)The name of the function followed by a number of arguments not greater than the number of parameters in the definition.
D)The name of the function followed by exactly the number of arguments as there are parameters in the definition.
E)The name of the function only.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
27
Where can you not declare a variable in a C++ program?

A)Within the parameter list of a function definition
B)Within the block of a void function.
C)Within the argument list of a function call
D)Within a block nested within another block
E)Within the block of a value returning function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
28
Write a function definition called even that takes one argument of type int and returns a bool value.The function returns true if its one argument is an even number;otherwise it returns false.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
29
Write a function definition for a isDigit function that takes one argument of type char and returns a bool value.The function returns true if the argument is a decimal digit;otherwise it returns false.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
30
Write a prototype and prototype comments for the sqrt library function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 30 في هذه المجموعة.