_________________________
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…
(c) is IPO chart.
2. What is the last step in the six-step model of creating computer solutions to problems?
(a) developing an algorithm to solve the problem (b) writing code to solve the problem (c) evaluate and modify (if necessary) the program (d) desk checking the program
Correct answer: (c). Answer (a) is step 2 in the six-step model. Answer (b) is step 4. Answer (d) is step 5.
3. What are the goals for desk-checking an algorithm?
(a) to verify that the algorithm is not missing any step (b) to verify that the steps are logical and in proper order c) both (a) and (b) are goals for desk-checking an algorithm d) neither (a) nor (b) is a goal for desk-checking an algorithm
Correct answer: (c)
4. What is pseudocode?
(a) An old programming language no longer used by programmers (b) A type of informal code that is used to show the steps in an algorithm a. (c) Programming code with syntax errors (d) Comments and notes inserted in program code
Correct answer: (b)
Read the following paragraph for questions 5, 6 and 7:
A teacher has the following information of each student in the class: name, ID, date of birth, midterm exam score, project score and final exam score. The teacher is writing a program to calculate a student's weighted total score, which is the sum of 30% of midterm exam score, 30% of project score, and 40% of final exam score. The teacher wants the program to display the ID and the weighted total score of the student but nothing else. He does not want to enter anything unnecessary into the program.
5. The midterm exam score of the student is
(a) an input item (b) a processing item c) an output item (d) none of the above
Correct answer: (a). The teacher has to enter midterm score into the program.
6. The weighted total score of the student is
(a) an input item (b) a processing item c) an output item (d) none of the above
Correct answer: (c).
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…
error. (b) This statement has a logical error but no syntax error. (c) This statement has no error. (d) None of the above is true
Correct answer: (c)
11.
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
6 d) If the user enters 20 for variable x, then y will equal 6
Correct answer: (a). Answers (b), (c) and (d) are wrong because the condition in the if statement is false with those values. Therefore, y is 0 in those cases.
15. Does the following code segment have a syntax error? If not, what is the output?
int x = 6; x = x + 2; cout grade; grade = toupper(grade);
switch(grade) { case 'A': case 'B': cout