Q and A 1 The types of the parameters are optional in the fu
Q and A
1. The \"types\" of the parameters are optional in the function declaration.
a. True b. False
2. Variables that are declared outside of any function body or paramenter list including main, are considered global.
a. True b. False
3. What is the value of x after the following statements?
int x,y,z;
y = 10;
z = 3;
x = (y * (z + 3));
a. 60 b. 30 c. 36 d. none of these
4. Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?
a. cin << myFloat;
b. cin >> myFloat;
c. cin >> \"myFloat\";
d. cout >> myFloat >> endl;
5. What is the output of the following code fragment?
int index = 5 // initalize i to 5
switch(index) // switch on cases of i
{ // assign a new value to I when the case matches
case 0: index = 15; break;
case 1: index = 25; break;
case 2: index = 35; break;
case 3: index = 40; break;
default: index = 0;
}
cout << index << endl;
a. 15 b. 25 c. 35 d. 0
6. What is the value returned by the following function?
int function ()
{
int value = 35;
return (value + 5);
value += 10;
}
a. 35 b. 40 c. 50 d. 10
7. What is the value of x after the following code fragment executes?
double x = 36.0;
x = sqrt (x);
a. 72 b. 36.0 c. 6.0 d. 2.456
8. What is the output of the following code fragment?
double size, volume = 16.0;
size = (sqrt(sqrt(volume))) / 2
cout.setf (ios::fixed);
cout.setf (ios::showpoint);
cout.precision (2);
cout << size;
a. 2 b. 2.00 c. 1.00 d. 0.00
9. What is the output of the following function and function call?
void calculateCost (int count, float& subTotal, float& taxCost); // declaration
float tax = 0.0, subTotal = 0.0; // program fragment
calculateCost (15, subTotal, tax);
cout << \"The cost for 15 items is \" << subTotal << \" , and the tax for \" << subTotal << \" is \" << tax << endl;
// end of fragment
// Function definition
void calculateCost (int count, float& subTotal, float& taxCost); // definition
{
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
10. Which of the following function prototypes are valid?
a. void doSomething(int&x, int y);
b. void doSomething( int& x, int& y);
c. void doSomething( int x, int y);
d. all are valid
11. 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 If any of the other paramenter are reference parameters
12. Which of the following is the correct way to close a file stream named outFile?
a. outFile.close();
b. outFile.close;
c. outFile.close(\"project.txt:);
d. close(outfile);
13. The manipulator used to make the number of decimal places displayed 2, is:
cout.precision(2);
a. True b. False
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. Which statement correctly opens an input stream named in_file and attaches it to a file named project.txt?
a. in_file=project.txt
b. in_file=\"project.txt\"
c. in_file.open(\"project.txt\");
d. in_file.open(porject.txt);
16. When is the external name of the file used in the program?
a. Any time you read or write to the file
b. Never
c. Only when reading from the file
d. When opening the file stream
17. Generally speaking, a function that returns a value is like a small program. The arguments to a function are like inputs to the \"program\", and the value returned is like the output of the \"program\".
a. True b. False
18. A variable that is declared inside a function defintion is only local in scope to the function.
a. True b. False
19. Given the following function definition and program fragment, what is the output?
void function_One1 (int& z, int& q) // definiton
{
int temp;
temp = q;
q = z;
z = temp;
}
void function_Two2 (int& a, int& b) //definition
if (a < b)
function_One1 (a, b);
else
a = b;
}
int x = 3, y = 4 // code fragment
function_Two2 (y, x);
cout << x << \" \" << y << endl;
a. 3 3 b. 4 3 c. 3 4 d. 4 4
20. A variable that is declared globally is accessible by all the functions in the program including main.
a. True b. False
21. What value, if any, is modified in the following function body?
void calculate (int count, float price, float& cost)
{
if (count < 0)
cost = 0.0;
else
cost = count * price;
return;
}
a. Void functions don\'t modify parameters
b. Nothing is modified
c. The argument cost
d. The argument price and count
22. When the function below is called with 1 dependent and $400 as grossPay, what value is returned?
double computeWithholding (int dependents, double grossPay)
{
double withheldAmount;
if (dependents > 2)
withheldAmount = 0.15;
else if (dependents == 2)
withheldAmount = 0.18;
else if (dependnets == 1)
withheldAmount = 0.2;
else // no dependents
withheldAmount = 0.28;
withheldAmount = grossPay * withheldAmount;
return (withheldAmount);
}
a. 60.0 b. 80.0 c. 720.0 d. None of these
23. When the function declared below is called, what would be returned?
double computeTaxes (int hours, double grossPay);
a. hours and grossPay
b. A double
c. Nothing, the function is void
d. The declaration is illegal
24. Referring to the function declaration below, which of the following statements is true?
void calculateOvertimePay(int hours, double& timeHalfPay, double& doubleTimePay)
a. Nothing is returned
b. It is a void function
c. timeHalfPay and doubleTimePay are modified
d. They are all true
25. The body of a while loop may execute once or never.
a. True b. False
Solution
The \"types\" of the parameters are optional in the function declaration
Answer:TRUE
Variables that are declared outside of any function body or paramenter list including main, are considered global.
Answer:TRUE





