1. If you need to write a function that will compute the cost of candy, where ea
ID: 3548720 • Letter: 1
Question
1. If you need to write a function that will compute the cost of candy, where each piece costs 25 cents, which of the following is an appropriate function declaration?
a. int calculateCost(char name);
b. char calculateCost(int count);
c. int calculateCost int count;
d. int calculateCost(int count);
2. What is value returned by the following function?
int function()
{
int value = 35;
return value + 5;
value += 10;
}
a. 35
b. 40
c. 50
d. 10
3. When overloading a function, what must be true?
a. The names should be different with the same number and/or types of parameters.
b. The names should be the same with different number and/or types of parameters.
c. The names should be different with different number and/or types of parameters.
d. The names should be the same with the same number and/or types of parameters.
4. Which of the following are valid function calls to the fabs function?
a. fabs(3.5);
b. cout << fabs(3.5);
c. cin >> fabs(3.5);
d. fabs(3.5);and cout << fabs(3.5);
5. The functions pow(), sqrt(), and fabs() are found in which include file?
a. cstdlib
b. cmath
c. iostream
d. regular
6. If the variable x has the original value of 3.4, what is the value in x after the following?
cout << static_cast<int>(x);
a. 3.4
b. 4
c. unknown
d. 3
7. If you have the following variable declaration in your program,
const int SIZE=34;
then which of the following statements are legal?
a. SIZE ++;
b. x = SIZE--;
c. cout << SIZE;
d. cin >> SIZE;
8. In the function declaration shown, the mechanism used to call this function is known as:
a. pass by name.
b. pass by value.
c. pass by name.
d. call by name.
9. What is the value of i after the following function call?
//function definition
int doSomething(int value)
{
value = 35;
return value;
value = 13;
}
//fragment of main program
int i=0;
cout << doSomething(i);
a. 13
b. 35
c. 48
d. 0
10. 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.
11. What is the output of the following function and function call?
void calculateCost(int count, float& subTotal, float& taxCost);
float tax = 0.0,
subTotal = 0.0;
calculateCost(15, subTotal,tax);
cout << "The cost for 15 items is " << subtotal
<< ", and the tax for " << subTotal << " is " << tax << endl;
//end of fragment
void calculateCost(int 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;
12. Which of the following function prototypes are not valid?
a. void doSomething(int& x, int y);
b. void doSomething( int& x, int& y);
c. void doSomething( int x, int y);
d. All of the choices apply.
13. You should make a parameter a reference parameter:
a. if you need the function to change the value of the argument passed to the function.
b. if 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.
14. What is the value of choice after the following statements?
void getChoice(int& par_choice, in par_count);
int choice, count=3;
getChoice(choice, count);
void getChoice(int& par_choice, in par_count)
{
if(par_count<0)
par_choice =0;
if(par_count = 0)
par_choice=-1;
else
par_choice=99;
return;
}
a. 3
b. 0
c. -1
d. 99
15. 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 display(float myCost);
c. int display (float myCost);
d. float display();
16. 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;
something(t, s);
cout << r << ' ' << s << ' ' << t << endl;
a. 1 14 3
b. 1 10 3
c. 5 14 3
d. 1 14 9
17. 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.
18. 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.
19. A simplified main program used to test functions is called:
a. a stub.
b. abstraction.
c. polymorphism.
d. a driver.
20. 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.
21. A function may return more than one item.
a. True
b. False
22. A function naming rules follow variable naming rules.
a. True
b. False
23. Every include directive must be followed by using namespace std;
a. True
b. False
24. The types of parameters are optional in the function declaration.
a. True
b. False
25. The parameter names are mandatory in the function header.
a. True
b. False
26. It is possible to have a function that has no parameters.
a. True
b. False
27. The parameters listed in the function declaration are considered global variables.
a. True
b. False
28. Variables that are declared outside of any function body or parameter list are considered global.
a. True
b. False
29. pow(2,3) is the same as pow(3,2).
a. True
b. False
30. Functions may have multiple return statements.
a. True
b. False
Explanation / Answer
please rate - thanks
any questions-ask
1. If you need to write a function that will compute the cost of candy, where each piece costs 25 cents, which of the following is an appropriate function declaration?
d. int calculateCost(int count);
2. What is value returned by the following function?
int function()
{
int value = 35;
return value + 5;
value += 10;
}
b. 40
3. When overloading a function, what must be true?
b. The names should be the same with different number and/or types of parameters.
4. Which of the following are valid function calls to the fabs function?
d. fabs(3.5);and cout << fabs(3.5);
5. The functions pow(), sqrt(), and fabs() are found in which include file?
b. cmath
6. If the variable x has the original value of 3.4, what is the value in x after the following?
cout << static_cast<int>(x);
a. 3.4
7. If you have the following variable declaration in your program,
const int SIZE=34;
then which of the following statements are legal?
c. cout << SIZE;
d. cin >> SIZE;
you can't change the value of SIZE
8. In the function declaration shown, the mechanism used to call this function is known as:
No function declaration is shown
a. pass by name.
b. pass by value.
c. pass by name.
d. call by name.
9. What is the value of i after the following function call?
//function definition
int doSomething(int value)
{
value = 35;
return value;
value = 13;
}
//fragment of main program
int i=0;
cout << doSomething(i);
d. 0
10. Which of the following is true for a void function?
d. Nothing is returned.
11. What is the output of the following function and function call?
void calculateCost(int count, float& subTotal, float& taxCost);
float tax = 0.0,
subTotal = 0.0;
calculateCost(15, subTotal,tax);
cout << "The cost for 15 items is " << subtotal
<< ", and the tax for " << subTotal << " is " << tax << endl;
//end of fragment
void calculateCost(int 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;
12. Which of the following function prototypes are not valid?
a. void doSomething(int& x, int y);
b. void doSomething( int& x, int& y);
c. void doSomething( int x, int y);
d. All of the choices apply.
all are valid prototypes
13. You should make a parameter a reference parameter:
a. if you need the function to change the value of the argument passed to the function.
14. What is the value of choice after the following statements?
void getChoice(int& par_choice, in par_count);
int choice, count=3;
getChoice(choice, count);
void getChoice(int& par_choice, in par_count)
{
if(par_count<0)
par_choice =0;
if(par_count = 0)
par_choice=-1;
else
par_choice=99;
return;
}
d. 99
this assumes if(par_count = 0) is supposed to be
if(par_count == 0)
15. If you were to write a function for displaying the cost of an item to the screen, which function prototype would be most appropriate?
b. void display(float myCost);
16. 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;
something(t, s);
cout << r << ' ' << s << ' ' << t << endl;
a. 1 14 3
17. If a function needs to modify more than one variable, it must:
d. be a call by reference function.
18. A simplified version of a function which is used to test the main program is called:
a. a stub.
19. A simplified main program used to test functions is called:
d. a driver.
20. Call-by-reference should be used:
.
b. when the function needs to change the value of one or more arguments.
21. A function may return more than one item.
b. False
technically true using reference parameters
22. A function naming rules follow variable naming rules.
a. True
23. Every include directive must be followed by using namespace std;
b. False
24. The types of parameters are optional in the function declaration.
b. False
25. The parameter names are mandatory in the function header.
a. True
26. It is possible to have a function that has no parameters.
a. True
27. The parameters listed in the function declaration are considered global variables.
b. False
28. Variables that are declared outside of any function body or parameter list are considered global.
a. True
29. pow(2,3) is the same as pow(3,2).
b. False
30. Functions may have multiple return statements.
a. True
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.