Test 1 CS111 Solution Ver 1
Test 1 CS111 Solution Ver 1
Paper Version 1
Name: ________Solution__________________
The test is composed of two sections with an overall test score of 30 Marks. You will have 50
minutes to complete the test.
There are 5 multiple choice questions with one point awarded for each correct choice.
Use the grid provided on the following page to circle the answer corresponding to correct choice.
Each question has exactly one correct answer.
Write C++ code for the problem given. Answers written with pencils will not be accepted.
NOTE:
This test covers two learning outcomes:
1. Examine code for its syntax and semantic validity.
2. Identify the functionality of existing codes.
Page 1
Multiple Choice Answering Grid
1 A B C D E 16 A B C D E
2 A B C D E
17 A B C D E
3 A B C D E
18 A B C D E
4 A B C D E
19 A B C D E
5 A B C D E
20 A B C D E
6 A B C D E
7 A B C D E
8 A B C D E
9 A B C D E
10 A B C D E
11 A B C D E
12 A B C D E
Total Marks:
13 A B C D E
14 A B C D E
15 A B C D E
Page 2
Section A: Multiple Choice
Part 1: Introduction
A. (1) Analysis of the design, (2) Synthesis of thesis and antithesis, and (3) Dialysis of
an analgesic solution.
B. (1) Testing of the product, (2) Experimenting with input, (3) Checking of output and
(4) Wrapping the product.
C. (1) Editing the machine code, (2) Saving the left, (3) Compiling to pseudo code, and
(4) Running the source code.
D. (1) Understanding the problem, (2) Developing an algorithm, (3) Testing the
algorithm, (4) Translating the algorithm to a program, (5) Compiling and testing the
program.
E. (1) Creation of product specification (2) Review of product specification (3)
Selection of product developer (4) Development of prototype (5) Hardware review of
product (6) Manufacture of product.
Page 3
Part 2: Fundamentals of Data Types
6. Suppose you want to write a program that reads in body temperatures, like 36:9, 37:5, or
38:1. Which variable type do you take?
A. Type short
B. Type int
C. Variable body temperature
D. Type char
E. Type double
int x = 0;
int y;
cout << "Please enter x";
cin >> x;
if (x > 0)
x = y / 2;
8. Which of the following variable declarations is syntactically correct, i.e. it will compile:
A. long number = 5 ;
B. float return = 6;
C. unsigned string firstname;
D. int score == 7;
E. real diameter = 3.14;
9. How many lines of output will the following program code print?
cout << " This program statements demonstrate the use of \n and << endl "
"in C++ programs." << endl << " In \\n the ’\\’ means the next character"
" has a special meaning hence \n means a newline. \n The command ’endl’ on the ";
cout << " other hand also means newline.\n When used it instructs the computer"
<< "to print the second\n "
"instruction on a newline. Therefore any string after \"<< endl\" "
"or \n written within the string will be printed on a new line.";
A. 2
B. 5
C. 8
D. 10
E. 12
Page 4
10. What is the output of this code snippet:
int number = 2;
int counter = 3;
int result = number/counter;
cout << "The result is " << result << endl;
Part 3: Decisions
A. B.
if(volume == 100){ if(number = 100){
apx = volume * 3.14; average = number / NUM_ENTRIES;
} number --;
else{ }
apy = volume / 2.79; else
} average = number / (NUM_ENTRIES +1);
volume++; number = 101;
C. D.
if(degree =< MAX_DEGREE;){ if(volume > MIN_VOLUME){
temperature = degree * FACTOR; length = volume / diameter;
}; }
else{ else{
temperature = degree; length = diameter;
degree = MAX_DEGREE; }
} cout << "The length is " << length;
Page 5
12. Suppose you want to check if score is not equal to 42, which condition is correct?
A. score !== 42
B. score >= 42
C. score =! 42
D. !score == 42
E. score != 42
13. Assuming that a user enters 10, 20, and 30 as input values one after another, what is the
output of the following code snippet?
int main()
{
int num1, num2, num3;
int result=0;
system("pause");
return 0;
}
A. The result is 10
B. The result is 20
C. The result is 30
D. The result is 40
E. The result is 50
Page 6
14. Consider the following code snippets:
I. II.
int mark = 20; int mark = 20;
int score = 30; int score = 30;
15. Suppose you defined bool is_student = true; and bool is_local = true;
Page 7
Part 4: Loops
B. C.
C. D.
Iteration 0
Iteration 1
Iteration 2
int number = 3;
while(number < 5){
if(number > 2){
break;
}
number = 7;
}
Page 8
What is the output?
A. The number is 2
B. The number is 3
C. The number is 5
D. The number is 6
E. The number is 7
(I) (II)
int element = 0; int element = 0;
while (element < 3) while (element <= 3)
{ {
element = element + 3; element = element + 3;
} }
cout << "This is element " << element; cout << "This is element " << element;
(III) (IV)
int element = 0; int element = 0;
do{ do{
element = element + 3; element = element + 3;
} }
while(element < 3); while(element <= 3);
cout << "This is element " << element;
cout << "This is element " << element;
19. Considering the three types of Loops; while loop, for loop and do while loop, Which of the
following statements is incorrect?
A. All three types of loops { while, for, and do } continue with the loop body, if the
condition is true.
B. The body of a do loop will be executed at least once.
C. The body of a while loop may not be executed at all.
D. A for loop first initializes, then checks the condition, then updates, and then
executes the body.
E. The for loop will update at the end of a loop, and then check the condition.
Page 9
20. A programmer wants to ask if the user is male or female. For male the user type “M" for
male, and “F" for female. The programmer wants to validate the input, which means, ask
again if the user does not type “M" or “F". What is wrong with the following program?
#include <iostream>
int main()
{
char response;
Page 10
Section B. Short Answer Questions - Alice and Bob (10 marks)
Alice and Bob play a number guessing game. Bob thinks of a number between 1 and 15.
a. Has Alice good reasons to call Bob a cheat? What is a good reason? (2 marks)
b. Assuming that you want to create a computer program that will play the role of Bob
without cheating. The program will randomly choose a number between 1 and 15 and ask
the user to guess that number. The user will be given 5 tries at guessing the number.
i. What will be the input(s) to this program? Declare appropriate variable(s) for the
input(s) identified. (2 marks)
int number = 0
Page 11
ii. Draw a flow chart that will model the program that you have to create. (6 marks)
Page 12
//extra sheet
End of Exam
Page 13