_________________________
Spring 2011 CIS115 Introduction to Programming and Logic Midterm Exam
____________________________________________________________
_________________________
ANSWERS
[Please do not share these answers with anybody]
Question 1 to 15: Choose the best answer. Four points for each question.
1. An algorithm is __________.
a) a type of software that analyzes a problem b) a graphical representation of the steps in a program c) a chart that lists input, output and processing items of a program d) a set of step-by-step instructions that is designed to accomplish a task
Correct answer: (d). Answer (b) is flowchart. Answer …show more content…
The goal of the program is to calculate the weighted total score.
7. The date of birth of the student is
(a) an input item (b) a processing item c) an output item (d) none of the above
Correct answer: (d). The date of birth is not entered nor used in the program. It is irrelevant information.
8. When we create a desk-checking table to test an algorithm, we
(a) create a column for every unique input item only (b) create a column for every unique output item only (c) create a column for every unique input and output item (d) create a column for every unique input, processing and output item
Correct answer: (d)
9. A compiler
(a) checks for syntax errors in your C++ instructions (b) translates your C++ instructions into machine code c) does everything described in (a) and (b) d) does nothing described in (a) and (b)
Correct answer: (c)
10. The following statement is used to declare and initialize a variable in a C++ program:
double height = 0.0;
Which of the following is true?
(a) This statement has a syntax …show more content…
Suppose a variable g is used to store course grade, which is one of the following letters: A, B, C, D or F. What type should be used for variable g?
(a) int (b) double (c) char (d) var
Correct answer: (c)
12. Which of the following is NOT a valid C++ variable name?
a) sec_test b) secondTest c) second-Test d) None of the names above is invalid
Correct answer: (c). We cannot have “-“ in a variable name
13. Suppose x is an integer variable in a C++ program. Which of the following statements does NOT have a syntax error?
a) x = 4; b) 4 = x; c) x + 2 = 6; d) None of the statements above has syntax error
Correct answer: (a). Answers (b) and (c) have syntax errors because the left hand side of an assignment statement must be a variable name but nothing else.
14. int x = 0; int y = 0; cin >> x; if (x < 10 || x > 20) { y = 6; }
Which of the following statements is true?
a) If the user enters 5 for variable x, then y will equal 6 b) If the user enters 10 for variable x, then y will equal 6 c) If the user enters 15 for variable x, then y will equal