Quiz Review - Computer Science

advertisement
Lecture 21:Quiz Review
Introduction to Computer Science
Spring 2006
1
1.
What value is returned by the return statement above?
a 0
.
b5
.
c 6
.
d7
.
2
2. 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', '&');
.
3
3. To use the predefined function tolower, the program must include the header file _____.
a cctype
.
c cmath
.
b iostream
.
d cstdlib
.
4
4. A function prototype is _____.
a a definition, but not a
. declaration
c a declaration, but not a
. definition
b a declaration and a
. definition
d a comment line
.
5
5. 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,y);
.
b cout<<tryMe(2.0,3.0);
.
c cout<<tryMe(tryMe(double,double),double);
.
d cout<<tryMe(tryMe(float,float),float);
.
6
6. 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(x,y);
.
b cout<<myFunc(myFunc(7, 8), 15);
.
c cin>>myFunc(‘2’, ‘3’);
.
d cout<<myFunc(myFunc(7), 15);
.
7
7. Given the above function, choose the output of the following statement:
cout<<mystery(9, 7);.
a 2
.
c 7
.
b 4
.
d 9
.
8
8. Given the above function, choose the output of the following statement:
cout<<strange(4, 5);.
a -1
.
c 9
.
b 1
.
d 20
.
9
9 Assume the above. The output of the statement:
cout<<static_cast<int>(tolower('B')); is _____.
a 65
.
c 96
.
b 67
.
d 98
.
10
10. 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);
.
11
11. 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);
.
12
12. Given the function prototype: float test();,
which of the following statements is legal?
a cout<<test;
.
c cout<<test();
.
b cout<<test(void);
.
d cout<<test(“Out”);
.
13
13. The output of the statement: cout<<pow(2,pow(3,1)); is _____.
a 6
.
c 8
.
b 7
.
d 9
.
14
14. The standard header file for the abs(x)function is _____.
a <cmath>
.
c <cctype>
.
b <ioinput>
.
d <cstdlib>
.
15
15. Functions that do not have a data type are called _____ functions.
a zero
.
c void
.
b null
.
d empty
.
16
16.Which statement 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.
17
17. A variable listed in a function call is known as a(n) _____ parameter.
A variable list in a header is known as a(n) _____ parameter.
a actual; actual
.
c actual; formal
.
b formal; formal
.
d formal; actual
.
18
18. If an & is attached after the data type of a formal parameter,
then the formal parameter is a _____.
a value parameter
.
c global variable
.
b reference parameter
.
d default variable
.
19
19. What are the values of x and y after the statements above execute?
(Assume that variables are properly declared.)
a x = 10; y = 10
.
c x = 15; y = 10
.
b x = 10; y = 15
.
d x = 15; y = 15
.
20
20.What are the values of one and letter after the statements above execute?
a one = 5; letter = 'A'
.
b one = 10; letter = 'A'
.
c one = 10; letter = 'B'
.
d one = 12; letter = 'B'
.
21
21. parameters are useful when you want to return more than one value from a function.
a Default
.
c Reference
.
b Value
.
d Automatic
.
22
22.Suppose that printHeading is a function without any parameters.
Which of the following is a valid function heading?
a void
.
b void
.
c void
.
d void
.
printHeading()
printHeading(noParameters)
printHeading();
printHeading(void);
23
23. A void function accomplish has three parameters:
a parameter u of the type int,
a parameter v of the type double,
and a parameter letter of the type char.
The parameters u and letter need to pass their values out of the function
and the parameter v is to only receive the value from the calling environment.
Which of the following is a correct function heading?
a void accomplish(int& u, double v, char& letter)
b. void accomplish(int u, double& v, char letter)
c. void accomplish(int& u, double v, char& letter);
d. void accomplish(int u, double& v, char letter);
24
24. Suppose that you are given the function definition above.
What is the output of the following statements?
printSomeThing(1);
printSomeThing(2);
printSomeThing(3);
a ******
.
b *
. * *
* * *
c
.
*
* *
* * *
d
.
*
* *
* * *
* * * *
25
25. What is the output of the program shown above?
a 1 1
. 3 1
c 1 2
. 2 3
b 1 2
. 1 3
d 2 2
. 2 3
26
26. Which of the following is a legal C++ function definition?
a void funcTest(int& u, double& v)
{
cout<<u<<" "<<v<<endl;
}
b void funcTest(int& u, double& v);
. {
cout<<u<<" "<<v<<endl;
}
c void funcTest(int& u, double& v)
. (
cout<<u<<" "<<v<<endl
)
d void funcTest(int& u, double& v)
. [
cout<<u<<" "<<v<<endl;
]
27
27. What is the output of the C++ code above?
a 4 5
.
c 6 5
.
b 6 4
.
d 6 6
.
28
28. Based on the function definition above, which of the following statements is valid?
a one is a value parameter and two is a reference parameter.
.
b one is a reference parameter and two is a value parameter.
.
c one and two are reference parameters.
.
d one and two are value parameters.
.
29
29. Which of the following is a legal C++ function definition?
a void funcAlpha(int u, double v &)
{
cout<<u<<" "<<v<<endl;
}
b void funcAlpha(int #, double #)
. {
cout<<u<<" "<<v<<endl;
}
c void funcAlpha(int &, double &)
. {
cout<<u<<" "<<v<<endl;
}
d void funcAlpha(int u, double& v)
. {
cout<<u<<" "<<v<<endl;
}
30
30. In C++, the scope resolution operator is _____.
a |
.
c :
.
b .
.
d ::
.
31
#include <iostream>
void CalcRectangle(double length, double width, double& circum, double& area);
void PrintResult(double length, double width, double circum, double area);
using namespace std;
int main()
{
double length, width, circumference, area;
cout<< “This program will calculate the circumference and area of the rectangle.”
cout << “Please input the length and width of the rectangle: ” << endl;
cin>>length >> width;
CalcRectangle(length, width, circum, area);
PrintResult(length, width, circum, area);
return 0;
}
void CalcRectangle(double length, double width, double& circum, double& area);
{
circum = 2*(length+width);
area = length * width;
}
void PrintResult(double length, double width, double circum, double area);
{
cout << “Length = ” << length <<endl;
cout << “ Width = ”<< width <<endl;
cout << “ Circumference = ” << circum <<endl;
cout << “ Area = ”<< area <<endl;
}
32
Download