Upload
sunnyopg
View
12
Download
5
Embed Size (px)
DESCRIPTION
Intro to programming
Citation preview
25/02/2013
1
Midterm Exam Jeopardy
Feb 25, 2013
Today’s Categories…
Computer Systems
Introduction to C++
Selection Control Structures
Repetition Control Structures
Word Puzzle
25/02/2013
2
Computer Systems
RepetitionControl
Word Puzzle
1 1 1
2 2 2
3 3 3
4 4 4
5
Selection Control
4
1
2
3
5
Intro to C++
1
2
3
4
5 5 5
Computer Systems – 1 pt
Convert the binary number
1010110001010111to hexadecimal
1 0 1 0 | 1 1 0 0 | 0 1 0 1 | 0 1 1 1
A C 5 7
AC5716
Back to Board
25/02/2013
3
Computer Systems – 2 pts
The Central Processing Unit is primarilyresponsible for
A. Performing program control and data processing
B. Ensuring data persists when electrical power is turned off
C. Enabling a human user to interact with the computer
D. Interconnecting computers that are separated by distance
A. Performing program control and dataprocessing
Back to Board
Computer Systems – 3 pts
Which of the following languages is unique to acomputer design where the instructions arebinary strings?
A. assembly language
B. Java
C. C++
D. machine language
D. machine language
Back to Board
25/02/2013
4
Computer Systems – 4 pts
What is the equivalent decimal value for thehexadecimal number A3?
163
Back to Board
Computer Systems – 5 pts
What is the equivalent decimal value for the octalnumber 67?
55
Back to Board
25/02/2013
5
Intro to C++ – 1 pt
Back to Board
High level programming languages A. Are made up primarily of ones and zeros
B. Are independent of the underlying hardware
C. Are not standardized
D. Use syntax that is close to the underlying hardware’s instruction set
B. Are independent of the underlying hardware
Intro to C++ – 2 pts
Characters that are grouped togetherbetween double quotes (quotation marks) inC++ are called
A. keywords
B. syntax
C. symbols
D. strings
d. strings
Back to Board
25/02/2013
6
Intro to C++ – 3 pts
What is the output of this code snippet?
int sum = 22;sum = sum + 2;cout << sum++; cout << sum;
Back to Board
2425
Intro to C++ – 4 pts
What is the output of this code snippet?
double average;int grade1 = 87;int grade2 = 94;// cout << "The average is " << (grade + grade2) / 2.0 << endl;cout << "The average is " << average << endl;
Unpredictable result
Back to Board
25/02/2013
7
Intro to C++ – 5 pts
What is the output of the following C++ expression
y = 2 * 5 / 5 + 3 * (5 + 2)
23
Back to Board
Selection Control Structures – 1 pt
What is a conditional expression?
Back to Board
A conditional expression is a Boolean expression that evaluates to true or false
Relational operators and logical operators are used to form conditional expressions.
25/02/2013
8
Selection Control Structures – 2 pts
Which of the following is the correct syntax for an if-else statement? A. if (x < 10) { size = "Small"; }
else (x < 20) { size = "Medium"; }
B. if (x < 10); { size = "Small"; }
else (x < 20) { size = "Medium"; }
C. if (x < 10) { size = "Small"; }
else { size = "Medium"; }
D. if { size = "Small"; }
else (x < 20) { size = "Medium"; }
CBack to Board
Selection Control Structures – 3 pts
DAILY DOUBLE!!!DAILY DOUBLE!!!
25/02/2013
9
Selection Control Structures – 4 pts
What is the problem with the following if statement?
double count = 15.0;if (count / 3.0) {
cout << "The value of count is " << count << endl;
}
The condition does not evaluate to a Boolean value
Back to Board
Selection Control Structures – 5 pts
When an if statement is nested inside anotherif statement, it creates the possibility of
The dangling else
Back to Board
25/02/2013
10
Repetition Control Structures – 1 pt
Which of the loops we studied executes the statements inside the loop before checking the condition?
do-while
Back to Board
Repetition Control Structures – 2 pts
Which common error is present in the code below, which is intended to calculate the average value from a sum of numbers?double total;int n;double input;while (cin >> input){
total = total + input;n++;
}if (n != 0){
double average = total / n;}
Uninitialized variablesBack to Board
25/02/2013
11
Repetition Control Structures – 3 pts
How many times will the following loop run?
int i = 0;while (i < 9){
cout << i << endl; i++;
}
9
Back to Board
Repetition Control Structures – 4 pts
What changes do you need to make in the following code snippet to display "Let us C" exactly 10 times?
int i = 0;while (i <= 10){
cout << "Let us C" << endl; i++;
}
int i = 1;
Back to Board
25/02/2013
12
Repetition Control Structures – 5 pts
How many times is the text "Let us C" printed if the code snippet given below is run?
2 timesBack to Board
int i = 0;do{
cout << "Let us C" << endl; i++; if (i % 2 == 0) {
i = 11; }
} while (i <= 10);
Word Puzzle – 1 pt
A special computer program that translates higher-level programs into machine instructions for a particular process
_ _ _ _ _ _ _ _
Compiler
Back to Board
25/02/2013
13
Word Puzzle – 2 pt
The _____________ combines machine code with library code into an executable program
_ _ _ _ _ _
Linker
Back to Board
Word Puzzle – 3 pt
Back to Board
Binary numbers can be stored in memory as a sequence of bits, called a ____________.
_ _ _ _
Word
Examples: 16-bit, 32-bit, and 64-bit
25/02/2013
14
Word Puzzle – 4 pt
DAILY DOUBLE!!!DAILY DOUBLE!!!
Word Puzzle – 5 pt
The ________ operator is a unary operatorthat requests that the value of the operandsbe changed to a new type for the nextcomputation.
_ _ _ _
cast
Back to Board
25/02/2013
15
Selection Control Structures – 3 pts
What can be done to improve the following code fragment?
int cost = 0;int counter = 0;while (counter < 10000) {
if ((counter % 10) == 0){
cout << "Counter is divisible by ten: " << counter << endl;counter++;
}else{
cout << "Counter is not divisible by ten: " << counter << endl;counter++;
}}
Move the duplicated code outside of the if statement Back to Board
Word Puzzle – 8 pt
A ____________ operator is used to increment avariable by 1, then use the new value of variable in theexpression in which the variable resides.
_ _ _ _ _ _ _ _ _ _ _ _
preincrement
Back to Board