COPPIN STATE UNIVERSITY

COSC 199.002: FALL 2005

TEST 1

True/False (1pt each): Indicate by "T" for true and "F" for false statements

1. True or False? All computer programs are algorithms. ___T ___________

2. True or False? In a computer, data is represented electronically by pulses of electricity. ______ T__

3. True or False? The compiler is a program that translates a high-level language program into machine code. _____T _______

4. True or False? Every C++ program must have a function named main. __ T ____

5. True or False? The C++ compiler considers the identifier CanOfWorms to be the same as the identifier canofworms. ____ F _

6. True or False? Some C++ reserved words can also be used as programmer-defined identifiers. ______F _

7. True or False? In C++, a block (compound statement) is not terminated by a semicolon. ______T ___

8. True or False? If a program compiles successfully, it is guaranteed to execute correctly. _____F ______

9. True or False? A literal string can continue onto more than one line, as long as it is enclosed in double quotes. _____ T _____

10. True or False? The statement

const char INITIAL = 'G';

is an example of an assignment statement. ______F ___

Multiple Choice (2pts each)

11. Which of the following statements about the C++ main function is false?

a. Every program must have a function named main.

b. Program execution begins with the first executable statement in the main function.

è c. The main function must call (invoke) at least one other function.

d. The word int in the function heading means that the main function returns an integer value (to the operating system).

12. Which is /or are not a valid identifier(s) in C++?

a. Hi_There b. top 40 c. &UpAnDdOwN d. _BlindMice e. CAPS

13. Which is /or are not valid identifier(s) in C++?

a. my-Name b. 9littles c. X123Y d. GoHome e. IdEnTiFiEr

14. Which of the following is a legal string assignment?

a. name = "Jones"; b. "name" = Jones;

c. name = 'D' + "Jones"; d. a and c above

15. Which assignment statement could be used to store the letter A into the char variable someChar?

a. someChar = "A"; b. someChar = 'A'; c. someChar = A;

d. a and c above e. a, b, and c above

16. In C++, the phrase "standard output device" usually refers to:

a. the display screen b. a floppy disk drive c. the keyboard

d. a CD-ROM drive e. none of the above

17. Which of the following statements prints Happy Birthday on first output line?

a. cout << "Happy "

<< "Birthday" << endl;

b. cout << "Happy " << "Birthday" << endl;

c. cout << "Happy Birthday" << endl;

d. b and c above e. a, b, and c above

18. Which of the following is the first step in the problem-solving phase of a computer program's life cycle?

a. Write a general solution for the problem. b. Translate the general solution into code.

c. Analyze the problem. d. Test the general solution.

e. Test the solution on a computer.

19. Which of the following is the second step in the problem-solving phase of a computer program's life cycle?

a. Write a general solution for the problem. b. Translate the general solution into code.

c. Analyze the problem. d. Test the general solution.

e. Test the solution on a computer.

20. Which of the following is the first step in the implementation phase of a computer program's life cycle?

a. Write a general solution for the problem. b. Translate the general solution into code.

c. Analyze the problem. d. Test the general solution.

e. Test the solution on a computer.

21. Which of the following is the second step in the implementation phase of a computer program's life cycle?

a. Write a general solution for the problem. b. Translate the general solution into code.

c. Analyze the problem. d. Test the general solution.

e. Test the solution on a computer.

22. The following series of steps is not an algorithm. How would you correct it?

Shampooing your hair.

Step 1. Wet your hair.

Step 2. Lather.

Step 3. Rinse.

Step 4. Repeat .

a. Exchange steps 1 and 2. b. Change step 4 to "Repeat steps 2 and 3".

c. .Exchange steps 2 and 3. d. Change step 4 to "Repeat steps 2 and 3 for twice".

23. Inside a computer, a single character such as the letter A usually is represented by a:

a. bit b. byte c. nibble d. word

24. Which of the following translates a program written in a high-level language into machine code?

a. an assembler b. a compiler c. an operating system d. an editor

25. Which of the following most closely resembles human language?

a. an assembly language b. a machine language c. a high-level language

26. Which of the following terms describes the repetition of statements (instructions) while certain conditions are met?

a. looping b. selection c. sequence d. subprogram

27. Which of the following terms describes the execution of different statements (instructions) depending on certain conditions?

a. sequence b. looping c. selection d. subprogram

28. Of the following components of a computer, which one performs computations?

a. input device b. output device c. arithmetic/logic unit

d. control unit e. memory unit

29. Of the following components of a computer, which one assures that program instructions are executed in the proper sequence?

a. input device b. output device c. arithmetic/logic unit

d. control unit e. memory unit

30. Of the following components of a computer, which one presents the results of the processing to the outside world?

a. input device b. output device c. arithmetic/logic unit

d. control unit e. memory unit

31. Which problem-solving technique involves integrating existing solutions on a step-by-step basis into a complete solution?

a. divide and conquer b. means-ends analysis c. solving by analogy

d. the building-block approach e. merging solutions

OTHER QUESTIONS

32. Match the left hand with right hand statements (1pt each)

a. A scanner ------1------------ 1. an input device

b. Central Processing Unit ------3----------------- 2. an output device

c. Printer ------2--------------- 3. a processing unit

d. CD-ROM drive -------5-------------- 4. memory

e. RAM --------4-------------- 5. an auxiliary storage device

f. Mouse --------1---------------

g. Monitor screen --------2----------------

h. hard drive --------5---------------

i. keyboard --------1---------------

j. floppy-disk drive ---------5--------------

33. (5pts) Show precisely what is the output by the following statement. Write "b" to indicate the blank line(s), if any.

cout << "A rolling" << endl << “stone" << endl << endl

<< “gathers" << endl << endl << endl << "no"

<< “moss" << endl;

cout << "This is the end." << endl;

OUTPUT (Results)

A rolling

stone

gathers

no

moss

This is the end.

34. (5pts) Identify the Syntax errors of the following program and write the program correctly. After the corrections, write the output of the program.

// Preprocessor Directives

include (iostream.h) ; ç

int main { }ç

cout >> “Magic Bullet; << endl; ç

Cout << Thank you. ç

return 0 ç

] // end of Main function ç

// Preprocessor Directives

include (iostream.h)

int main ( )

{

cout >> “Magic Bullet” << endl; ç

cout << “thank you.”;

return 0;

} // end of Main function ç

Questions 35 to 41 (2pts each)

35. What is printed by the following statement?

cout << "My dog's name is" << "Maggie" << endl;

My dog’s name isMaggie

36. What is printed by the following statement?

cout << "My dog's name is" << " Maggie" << endl;

My dog’s name is Maggie

37. What is printed by the following statements, if the variable, dogName is string data type?

string dogName = “Maggie”;

cout << "My dog's name is" << dogName;

cout << "I also have a cat named Senatra" << endl;

cout << ".";

My dog’s name isMaggie

I also have a cat named Senatra

.

38. What is printed by the following statements, if the variable, dogName is string data type?

string dogName = “Maggie”;

cout << "My dog's name is" << ‘ ’ << dogName << endl

<< '.';

cout << "I also have a cat named Senatra.";

My dog’s name is Maggie

.

I also have a cat named Senatra.

39. Write a declaration statement of the character variable initial.

___________________char initial; _________________________

40. Write a statement to assign the letter G to the character variable initial.

__________________initial = ‘G’;_____________________________________________________

41. Write a declaration statement to assign the letter G to the named constant INITIAL.

___________________const char INITIAL = ‘G’ ; ___________

42. (2pts each) Write a declaration statement for the following:

a. A named constant, called ANSWER, of type string with the value “True”

___________________const string ANSWER = “True” ;_____________________

b. A char variable with the name middleInitial.

___________________char middleInitial ; _______

c. A string variable with the name courseTitle.

___________________string corseTitile; _______________

d. A named char constant, called PERCENT, with the value “%”

_________________const char PERCENT = ‘%’; _____

43. (10 pts.) Reorder the following lines of codes to make a working program. Write your newly arranged codes separately.

{

}

#include <iostream>

const string TITLE = “Dr.”;

cout << “Hello ” + TITLE + “ Stroustrup!”;

int main()

#include <string>

return 0;

using namespace std;

{

}

#include <iostream>

#include <string>

using namespace std;

const string TITLE = “Dr.”;

int main()

{

cout << “Hello ” + TITLE + “ Stroustrup!”;

return 0;

}

6

sray/csc/cosc199/test1/fall05