Docsity

University of Alabama in Huntsville - CPE 112 02 Final Exam, Exams of Engineering

Toggle sidebar
bg1
The University of Alabama in Huntsville
Electrical and Computer Engineering
CPE 112 02
Final Exam
December 6, 2001
Name: ________________________
Posting Code: __________________
True or False (1 point each)
1. _____ There is only one unique general solution (algorithm) for a given problem.
2. _____ The compiler is a program that translates a high-level language program into machine
code.
3. _____ Every C++ program must have a function named main.
4. _____ A(n) ____________________ is a location in memory, referenced by an identifier,
where a data value that cannot be changed is stored.
5. _____ In a C++ expression without parentheses, all operations are performed in order from
left to right.
6. _____ The single statement
cin >> alpha >> beta;
may be used in place of the two statements
cin >> alpha;
cin >> beta;
7. _____ The >> operator skips leading whitespace characters when looking for the next data
value in the input stream.
8. _____ If P and Q are logical expressions, the expression P AND Q is TRUE if either P or Q
is TRUE or both are TRUE.
9. _____ The code segment
if (speed <= 40)
cout << "Too slow";
if (speed > 40 && speed <= 55)
cout << "Good speed";
if (speed > 55)
cout << "Too fast";
could be written equivalently as
if (speed <= 40)
cout << "Too slow";
else if (speed <= 55)
cout << "Good speed";
else
cout << "Too fast";
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download University of Alabama in Huntsville - CPE 112 02 Final Exam and more Exams Engineering in PDF only on Docsity!

The University of Alabama in Huntsville

Electrical and Computer Engineering

CPE 112 02

Final Exam

December 6, 2001

Name: ________________________

Posting Code: __________________

True or False (1 point each)

1. _____ There is only one unique general solution (algorithm) for a given problem.

2. _____ The compiler is a program that translates a high-level language program into machine

code.

3. _____ Every C++ program must have a function named main.

4. _____ A(n) ____________________ is a location in memory, referenced by an identifier,

where a data value that cannot be changed is stored.

5. _____ In a C++ expression without parentheses, all operations are performed in order from

left to right.

6. _____ The single statement

cin >> alpha >> beta;

may be used in place of the two statements

cin >> alpha; cin >> beta;

7. _____ The >> operator skips leading whitespace characters when looking for the next data

value in the input stream.

8. _____ If P and Q are logical expressions, the expression P AND Q is TRUE if either P or Q

is TRUE or both are TRUE.

9. _____ The code segment

if (speed <= 40) cout << "Too slow"; if (speed > 40 && speed <= 55) cout << "Good speed"; if (speed > 55) cout << "Too fast";

could be written equivalently as

if (speed <= 40) cout << "Too slow"; else if (speed <= 55) cout << "Good speed"; else cout << "Too fast";

10. ______ An infinite loop is one in which the While expression always has the value false.

11. ______ It is possible to supply different argument names every time a function is called.

12. ______ Using global variables is better style than using local variables.

13. ______ If a loop containing a break statement is nested within a Switch statement, execution

of that break statement causes an exit from the loop but not from the Switch statement.

14. ______ In C++, the expressions beta++ and ++beta can always be used interchangeably.

15. _______ C++ allows an array to be a member of a struct.

16. _______ The components of an array are all of the same data type.

17. ______ Given the declaration

int beta[20];

the statement

beta = beta + 1;

adds 1 to all 20 elements of the array.

Fill in the Blank (1 point each)

18. Coding of an algorithm takes place during the ______________________________ phase of

a computer program’s life cycle.

19. A(n) ____________________ is a step-by-step procedure for solving a problem in a finite

amount of time.

20. A(n) ____________________ is a name associated with a function or data object and used to

refer to that function or data object.

21. The implicit (automatic) conversion of a value from one data type to another is called

____________________.

22 The C++ standard library defines a data type named ____________________ that represents a

stream of characters going to an output file.

23. __________________________________ is a technique for developing a program in which

the problem is divided into more easily handled subproblems, the solutions of which create a

solution to the overall problem.

24. Write a C++ logical expression that is false if either x or y is equal to 5:

______________________________________

25. A(n) __________________________ is an input statement located before the While loop that

processes its input data.

26. A(n) ____________________ is a variable declared in a function heading.

37. _____ Which one of the following is not a valid identifier in C++?

a.Hi_There

b.top

c.UpAnDdOwN

d.3BlindMice

e.CAPS

38. ______ After execution of the code fragment

int arr[5]; int i;

for (i = 0; i < 5; i++) { arr[i] = i + 2; if (i >= 3) arr[i-1] = arr[i] + 3; }

what is contained in arr[1]?

a.

b.

c.

d.

e.none of the above

39. ______ Given the nested For loops

for (i = 0; i < M; i++) for (j = 0; j < N; j++) cout << table[i][j];

what is the appropriate declaration for table?

a.int table[M][N];

b.int table[N][M];

c.int table[M+N];

d.int table[M+1][N+1];

e.int table[N+1][M+1];

40. _____ The value of the C++ expression 3 / 4 * 5 is:

a.0.

b.

c.3.

d.

e.0.

41. _____ What is the output of the following program fragment?

age = 29; cout << "Are you" << age << "years old?" << endl;

a.Are you29years old?

b.Are you 29 years old?

c.Are you29 years old?

d.Are you 29years old?

e.Are you age years old?

42. _____ Given the constant declaration

const int FACTOR = 95;

which of the following is not a valid use of FACTOR?

a.cout << FACTOR * 3;

b.FACTOR = 24;

c.cin >> FACTOR;

d.a and c above

e.b and c above

43. _____ If p is a Boolean variable, which of the following logical expressions always has the value false?

a. p && p b. p || p c. p && !p d. p || !p

e.b and d above

44. ______ What is the value of loopCount after control exits the following loop?

loopCount = 1; while (loopCount <= 145) { alpha = alpha + 7; loopCount++; }

a.

b.

c.

d.

45. ______ Parameter passage by value is used if a parameter’s data flow is

a.one-way, into the function.

b.one-way, out of the function.

c.two-way, into and out of the function.

d.a and b above

e.b and c above

50. ______ How many iterations does the following For loop execute? (count is of type int.)

for (count = 0; count <= 20; count++) DoSomething();

a.

b.

c.

d.

e.infinitely many

51. ______ What is the output of the following code fragment? (All variables are of type int.)

n = 2; for (loopCount = 1; loopCount <= 3; loopCount++) do n = 2 * n; while (n <= 4); cout << n << endl;

a.

b.

c.

d.

e.

52. ______ Given the declarations

enum Days {YESTERDAY, TODAY, TOMORROW}; Days day = TODAY;

what is the value of the expression int(day)?

a. TODAY

b.

c. TOMORROW

d.

e.none of the above

53. (4 points) Use correct C++ syntax to define a new type called player_t that consists of an

integer called assists, an integer called points, an integer called blocks, and an integer called

rebounds.

54. (10 points) Write a value-returning function named Array_Min that returns the smallest

value found in a one-dimensional integer array. The parameters are the array and its size.

55. (12 points) Given the following program segment, what is the output of each cout statement?

double x[5]; int y;

for (y = 0; y < 5; y++) x[y] = 2 * y - 1; y = 2;

a) cout << x[4] << endl ; ______________________________

b) cout << x[0] << endl; ______________________________

c) cout << x[1] + 2.0 << endl; ______________________________

d) cout << x[(1+1)*2] << endl; ______________________________

e) cout << x[int(x[2])] << endl ; ______________________________

f) cout << x[y++] << endl; ______________________________

58. (12 points) a. (8 points) Write a value-returning function named Count_Lines which takes a

file stream as input and returns the number of lines in the file. You know you have come to the

end of a file when you see a newline character. b. (4 points) Show all the necessary declarations

and the calling statement in the calling function for the user function in question 58a.