Deck 5: Functions for All Sub Tasks

Full screen (f)
exit full mode
Question
What is the correct way to call the following function? Assume that you have two variables named intArgument int)and floatArgumentfloat).
void doThingsfloat x,int y);
Use Space or
up arrow
down arrow
to flip the card.
Question
A ___________ is a main program that only checks that functions execute correctly.
Question
When the address of the actual argument is passed to the formal parameter,this is called __________________________
Question
In a function with call-by-reference parameters,any changes to the formal parameters will change the actual arguments passed to the function.
Question
It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration.
Question
A stub is a function that is completely defined and well tested
Question
What symbol is used to signify that a parameter is a reference parameter? ______
Question
The following is legal in a void function
return;
Question
The variables passed a function are called _________.
Question
If we want to test if a given function works correctly,we would write a _________ to test it.
Question
What type of value does a void function return? ____________
Question
The values or variables listed in the function declaration are called _________ to the function.
Question
It is illegal to call other functions from inside a function definition.
Question
What is the correct way to call the following function? _________________________
void setDisplay);
Question
A function that does not return a value is known as a ________ function.
Question
Functions can return at most one value.
Question
A void function can be used in an assignment.
Question
In a function with call-by-reference parameters,the values of the actual arguments are passed to the function.
Question
A void function may not be used in an output statement.
Question
A void function can return any value
Question
What is the output of the following function and function call?
Void calculateCostint count,float& subTotal,float& taxCost);
Float tax = 0.0,
SubTotal = 0.0;
CalculateCost15,subTotal,tax);
Cout << "The cost for 15 items is " << subtotal
<< ",and the tax for " << subTotal << " is " << tax << endl;
//end of fragment
Void calculateCostint count,float& subTotal,float& taxCost)
{
If count < 10)
{
SubTotal = count * 0.50;
}
Else
{
SubTotal = count * 0.20;
}
TaxCost = 0.1 * subTotal;
}

A)The cost for 15 items is 3.00,and the tax for 3.00 is 0.30;
B)The cost for 15 items is 0.00,and the tax for 3.00 is 0.00;
C)The cost for 15 items is 0.00,and the tax for 3.00 is 0.30;
D)The cost for 15 items is 3.00,and the tax for 3.00 is 0.00;
Question
The preconditions)for a function describe:

A)What is true after the function is executed
B)What the function does
C)How to call the function
D)What must be true before the function executes
Question
Which of the following is a legal call to the displayOutput function?
Void displayOutputint total);

A)void displayOutputmyTotal);
B)displayOutputint mytotal);
C)displayOutputmyTotal);
D)cout << displayOutputmyTotal);
Question
Which of the following function prototypes are not valid?

A)void doSomethingint& x,int y);
B)void doSomething int& x,int& y);
C)void doSomething int x,int y);
D)all are not valid
E)all are valid
Question
Given the following function declaration and local variable declarations,which of the following is not a correct function call?
Int myInt;
Float myFloat;
Char ch;
Void someFunctionint& first,float second,char third);

A)someFunction1,2.0,ch);
B)someFunctionmyInt,myFloat,ch);
C)someFunctionmyInt,2.0,'c');
D)someFunctionmyInt,myFloat,'1');
Question
Using functions in a program is called _____________.
Question
Testing a program with values that are close to values that will change the execution of a program is called _________________.
Question
Which of the following are true?

A)a function can call another function.
B)as long as the function is defined anywhere in your program,it can be used anywhere else.
C)a function definition can contain another function definition.
D)if you have function prototypes,the order in which you define your functions is important.
Question
A ________ is a simplified version of a function used to test the main program.
Question
Given the function definition
Void something int a,int& b )
{
Int c;
C = a + 2;
A = a * 3;
B = c + a;
}
What is the output of the following code fragment that invokes something?
All variables are of type int.)
R = 1;
S = 2;
T = 3;
Somethingt,s);
Cout << r << ' ' << s << ' ' << t << endl;

A)1 14 3
B)1 10 3
C)5 14 3
D)1 14 9
E)none of the above
Question
Call-by-reference parameters are passed

A)nothing
B)the actual argument.
C)the value in the actual argument.
D)the address of the argument.
Question
What is the output of the following function and function call?
Void calculateCostint count,float& subTotal,float taxCost);
Float tax = 0.0,
Subtotal = 0.0;
CalculateCost15,subtotal,tax);
Cout << "The cost for 15 items is " << subtotal
<< ",and the tax for " << subtotal << " is " << tax << endl;
//end of fragment
Void calculateCostint count,float& subTotal,float taxCost)
{
If count < 10)
{
SubTotal = count * 0.50;
}
Else
{
SubTotal = count * 0.20;
}
TaxCost = 0.1 * subTotal;
}

A)The cost for 15 items is 3.00,and the tax for 3.00 is 0.30;
B)The cost for 15 items is 0.00,and the tax for 3.00 is 0.00;
C)The cost for 15 items is 0.00,and the tax for 3.00 is 0.30;
D)The cost for 15 items is 3.00,and the tax for 3.00 is 0.00;
Question
If you were to write a function for displaying the cost of an item to the screen,which function prototype would be most appropriate?

A)void display);
B)void displayfloat myCost);
C)int display float myCost);
D)float display);
Question
You should make a parameter a reference parameter if:

A)You need the function to change the value of the argument passed to the function.
B)you need to be able to change the value of the parameter in the function,but not the value of the argument.
C)Always.
D)If any of the other parameters are reference parameters.
Question
What is wrong with the following function body?
Void calculateint count,float price,float& cost)
{
If count < 0)
Cost=0.0;
Else
Cost=count*price;
Return;
}

A)void functions may not have a return statement.
B)void functions must return a value
C)nothing
D)can not mix reference and value parameters
Question
If you need a function to get both the number of items and the cost per item from a user,which would be a good function declaration to use?

A)int,float getData);
B)int getDatafloat cost);
C)void getDataint count,float cost);
D)void getDataint& count,float& cost);
Question
The postcondition of a function

A)determines how the function will complete its job.
B)tells what must be true before the function executes.
C)declares the function for the compiler.
D)tells what will be true after the function executes.
Question
Which of the following is true for a void function?

A)There cannot be a return statement.
B)The value of void should be returned.
C)The value of 0 should be returned.
D)Nothing is returned.
Question
What is the value of choice after the following statements?
Void getChoiceint& par_choice,in par_count);
Int choice,count=3;
GetChoicechoice,count);
Void getChoiceint& par_choice,in par_count)
{
Ifpar_count<0)
Par_choice =0;
Ifpar_count = 0)
Par_choice=-1;
Else
Par_choice=99;
Return;
}

A)3
B)0
C)-1
D)99
Question
pre and post conditions for a function should be written before/after)the function definition is written.
Question
In the following function,what is passed to the first parameter?
Void f1 int& value1,int value2);
Int x,y;
F1x,y);

A)The value of x
B)nothing,it is a void function
C)the value of y
D)the variable x or its memory location)
Question
When a void function is called,it is known as

A)An output function.
B)A returned value.
C)An executable statement.
D)A comment
Question
Call-by-reference should be used

A)For all variables
B)When the function needs to change the value of one or more arguments
C)Never
D)only in void functions
Question
If a function needs to modify more than one variable,it must

A)be pass by value
B)be a void function
C)return all values needed
D)be a call by reference function
Question
Testing your program should be done

A)As each function is developed
B)At the end of the coding
C)Only if there appear to be problems
D)Only if your instructor requires it.
Question
Given the following function definitions and program fragments,what is the output?
Void f1int& z,int &q)
{
Int temp;
Temp=q;
Q=z;
Z=temp;
}
Void f2 int& a,int& b)
{
If aF1a,b);
Else
A=b;
}
Int x=3,y=4;
F2y,x);
Cout << x <<" " << y << endl;

A)3 3
B)4 3
C)3 4
D)4 4
Question
A simplified version of a function which is used to test the main program is called

A)A stub
B)Abstraction
C)Polymorphism
D)A driver
Question
Which of the following comments would be the best post-condition for this swap function void swap int& left,int&right);

A)//Postcondition: None
B)//Postcondition: the values of left and right are exchanged.
C)//Postcondition: left has the value of right
D)//Postcondition: left and right are unchanged
Question
Given the following function definition
Void shiftint& a,int&b)
{
A=b;
B=a;
}
What is the output after the following function call?
Int first=0,second=10;
Shiftfirst,second);
Cout << first <<" "<< second << endl;

A)0 10
B)10 0
C)0 0
D)10 10
Question
If you write a function that should use call-by-reference,but forget to include the ampersand,

A)The program will not compile
B)The program will not link
C)The program will not run without a run-time error
D)The program will run with incorrect results
E)It doesn't matter
Question
Testing a function or program using test values that are at or near the values that change the outcome of the program is known as using

A)parameters
B)functional decomposition
C)boundary values
D)a black-box
Question
What is the output of the following code fragments?
Int trial int& a,int b)
{
Ifb > a)
{
A=b;
Return -a;
}
Else
{
Return 0;
}
}
Float x=0,y=10,z;
Z=trialy,x);
Cout << z << " " << x <<" " << y << endl;

A)-10 0 0
B)0 10 0
C)10 0 0
D)0 0 10
Question
A simplified main program used to test functions is called

A)A stub
B)Abstraction
C)Polymorphism
D)A driver
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/53
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 5: Functions for All Sub Tasks
1
What is the correct way to call the following function? Assume that you have two variables named intArgument int)and floatArgumentfloat).
void doThingsfloat x,int y);
doThingsfloatArgument,intArgument);
2
A ___________ is a main program that only checks that functions execute correctly.
driver
3
When the address of the actual argument is passed to the formal parameter,this is called __________________________
call-by-reference -or- pass-by-reference
4
In a function with call-by-reference parameters,any changes to the formal parameters will change the actual arguments passed to the function.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
5
It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
6
A stub is a function that is completely defined and well tested
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
7
What symbol is used to signify that a parameter is a reference parameter? ______
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
8
The following is legal in a void function
return;
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
9
The variables passed a function are called _________.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
10
If we want to test if a given function works correctly,we would write a _________ to test it.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
11
What type of value does a void function return? ____________
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
12
The values or variables listed in the function declaration are called _________ to the function.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
13
It is illegal to call other functions from inside a function definition.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
14
What is the correct way to call the following function? _________________________
void setDisplay);
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
15
A function that does not return a value is known as a ________ function.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
16
Functions can return at most one value.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
17
A void function can be used in an assignment.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
18
In a function with call-by-reference parameters,the values of the actual arguments are passed to the function.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
19
A void function may not be used in an output statement.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
20
A void function can return any value
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
21
What is the output of the following function and function call?
Void calculateCostint count,float& subTotal,float& taxCost);
Float tax = 0.0,
SubTotal = 0.0;
CalculateCost15,subTotal,tax);
Cout << "The cost for 15 items is " << subtotal
<< ",and the tax for " << subTotal << " is " << tax << endl;
//end of fragment
Void calculateCostint count,float& subTotal,float& taxCost)
{
If count < 10)
{
SubTotal = count * 0.50;
}
Else
{
SubTotal = count * 0.20;
}
TaxCost = 0.1 * subTotal;
}

A)The cost for 15 items is 3.00,and the tax for 3.00 is 0.30;
B)The cost for 15 items is 0.00,and the tax for 3.00 is 0.00;
C)The cost for 15 items is 0.00,and the tax for 3.00 is 0.30;
D)The cost for 15 items is 3.00,and the tax for 3.00 is 0.00;
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
22
The preconditions)for a function describe:

A)What is true after the function is executed
B)What the function does
C)How to call the function
D)What must be true before the function executes
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is a legal call to the displayOutput function?
Void displayOutputint total);

A)void displayOutputmyTotal);
B)displayOutputint mytotal);
C)displayOutputmyTotal);
D)cout << displayOutputmyTotal);
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following function prototypes are not valid?

A)void doSomethingint& x,int y);
B)void doSomething int& x,int& y);
C)void doSomething int x,int y);
D)all are not valid
E)all are valid
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
25
Given the following function declaration and local variable declarations,which of the following is not a correct function call?
Int myInt;
Float myFloat;
Char ch;
Void someFunctionint& first,float second,char third);

A)someFunction1,2.0,ch);
B)someFunctionmyInt,myFloat,ch);
C)someFunctionmyInt,2.0,'c');
D)someFunctionmyInt,myFloat,'1');
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
26
Using functions in a program is called _____________.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
27
Testing a program with values that are close to values that will change the execution of a program is called _________________.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following are true?

A)a function can call another function.
B)as long as the function is defined anywhere in your program,it can be used anywhere else.
C)a function definition can contain another function definition.
D)if you have function prototypes,the order in which you define your functions is important.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
29
A ________ is a simplified version of a function used to test the main program.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
30
Given the function definition
Void something int a,int& b )
{
Int c;
C = a + 2;
A = a * 3;
B = c + a;
}
What is the output of the following code fragment that invokes something?
All variables are of type int.)
R = 1;
S = 2;
T = 3;
Somethingt,s);
Cout << r << ' ' << s << ' ' << t << endl;

A)1 14 3
B)1 10 3
C)5 14 3
D)1 14 9
E)none of the above
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
31
Call-by-reference parameters are passed

A)nothing
B)the actual argument.
C)the value in the actual argument.
D)the address of the argument.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
32
What is the output of the following function and function call?
Void calculateCostint count,float& subTotal,float taxCost);
Float tax = 0.0,
Subtotal = 0.0;
CalculateCost15,subtotal,tax);
Cout << "The cost for 15 items is " << subtotal
<< ",and the tax for " << subtotal << " is " << tax << endl;
//end of fragment
Void calculateCostint count,float& subTotal,float taxCost)
{
If count < 10)
{
SubTotal = count * 0.50;
}
Else
{
SubTotal = count * 0.20;
}
TaxCost = 0.1 * subTotal;
}

A)The cost for 15 items is 3.00,and the tax for 3.00 is 0.30;
B)The cost for 15 items is 0.00,and the tax for 3.00 is 0.00;
C)The cost for 15 items is 0.00,and the tax for 3.00 is 0.30;
D)The cost for 15 items is 3.00,and the tax for 3.00 is 0.00;
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
33
If you were to write a function for displaying the cost of an item to the screen,which function prototype would be most appropriate?

A)void display);
B)void displayfloat myCost);
C)int display float myCost);
D)float display);
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
34
You should make a parameter a reference parameter if:

A)You need the function to change the value of the argument passed to the function.
B)you need to be able to change the value of the parameter in the function,but not the value of the argument.
C)Always.
D)If any of the other parameters are reference parameters.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
35
What is wrong with the following function body?
Void calculateint count,float price,float& cost)
{
If count < 0)
Cost=0.0;
Else
Cost=count*price;
Return;
}

A)void functions may not have a return statement.
B)void functions must return a value
C)nothing
D)can not mix reference and value parameters
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
36
If you need a function to get both the number of items and the cost per item from a user,which would be a good function declaration to use?

A)int,float getData);
B)int getDatafloat cost);
C)void getDataint count,float cost);
D)void getDataint& count,float& cost);
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
37
The postcondition of a function

A)determines how the function will complete its job.
B)tells what must be true before the function executes.
C)declares the function for the compiler.
D)tells what will be true after the function executes.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following is true for a void function?

A)There cannot be a return statement.
B)The value of void should be returned.
C)The value of 0 should be returned.
D)Nothing is returned.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
39
What is the value of choice after the following statements?
Void getChoiceint& par_choice,in par_count);
Int choice,count=3;
GetChoicechoice,count);
Void getChoiceint& par_choice,in par_count)
{
Ifpar_count<0)
Par_choice =0;
Ifpar_count = 0)
Par_choice=-1;
Else
Par_choice=99;
Return;
}

A)3
B)0
C)-1
D)99
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
40
pre and post conditions for a function should be written before/after)the function definition is written.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
41
In the following function,what is passed to the first parameter?
Void f1 int& value1,int value2);
Int x,y;
F1x,y);

A)The value of x
B)nothing,it is a void function
C)the value of y
D)the variable x or its memory location)
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
42
When a void function is called,it is known as

A)An output function.
B)A returned value.
C)An executable statement.
D)A comment
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
43
Call-by-reference should be used

A)For all variables
B)When the function needs to change the value of one or more arguments
C)Never
D)only in void functions
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
44
If a function needs to modify more than one variable,it must

A)be pass by value
B)be a void function
C)return all values needed
D)be a call by reference function
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
45
Testing your program should be done

A)As each function is developed
B)At the end of the coding
C)Only if there appear to be problems
D)Only if your instructor requires it.
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
46
Given the following function definitions and program fragments,what is the output?
Void f1int& z,int &q)
{
Int temp;
Temp=q;
Q=z;
Z=temp;
}
Void f2 int& a,int& b)
{
If aF1a,b);
Else
A=b;
}
Int x=3,y=4;
F2y,x);
Cout << x <<" " << y << endl;

A)3 3
B)4 3
C)3 4
D)4 4
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
47
A simplified version of a function which is used to test the main program is called

A)A stub
B)Abstraction
C)Polymorphism
D)A driver
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following comments would be the best post-condition for this swap function void swap int& left,int&right);

A)//Postcondition: None
B)//Postcondition: the values of left and right are exchanged.
C)//Postcondition: left has the value of right
D)//Postcondition: left and right are unchanged
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
49
Given the following function definition
Void shiftint& a,int&b)
{
A=b;
B=a;
}
What is the output after the following function call?
Int first=0,second=10;
Shiftfirst,second);
Cout << first <<" "<< second << endl;

A)0 10
B)10 0
C)0 0
D)10 10
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
50
If you write a function that should use call-by-reference,but forget to include the ampersand,

A)The program will not compile
B)The program will not link
C)The program will not run without a run-time error
D)The program will run with incorrect results
E)It doesn't matter
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
51
Testing a function or program using test values that are at or near the values that change the outcome of the program is known as using

A)parameters
B)functional decomposition
C)boundary values
D)a black-box
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
52
What is the output of the following code fragments?
Int trial int& a,int b)
{
Ifb > a)
{
A=b;
Return -a;
}
Else
{
Return 0;
}
}
Float x=0,y=10,z;
Z=trialy,x);
Cout << z << " " << x <<" " << y << endl;

A)-10 0 0
B)0 10 0
C)10 0 0
D)0 0 10
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
53
A simplified main program used to test functions is called

A)A stub
B)Abstraction
C)Polymorphism
D)A driver
Unlock Deck
Unlock for access to all 53 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 53 flashcards in this deck.