Finalexam A6
Finalexam A6
Signature: __________________________
Section: A6
1. Print your name and ID number in the space provided above, then sign the test.
2. Wait until you are told to start working on the exam (don’t flip the pages yet).
3. Write your ID number on top of all the remaining pages, only then start answering
the questions. Put all your answers on the exam paper, no additional sheets of
paper can be handed in. You can use the back of the pages for your scratch
notes and calculations. Remember to read all instructions carefully.
4. When you are told that the time is up, stop working on the test.
Good luck!
20 11 16 8 7 38 100
CMPUT101 Section A6 Final Exam Page 2 of 10 ID#:_____________
Part I (Multiple choice) Circle the letter of the best choice (only one)
1. (2 mark) Which of the following statements comes closest to describing the
discipline of computer science? Computing science is the study of
a. how to program computers
b. algorithms and their properties
c. how to use computers
d. how to build computers
e. how to design programming languages
2. (2 marks) How many name comparisons, in the worst case, does it take for a
sequential search algorithm to locate a name in a list of n names?
a. 1
b. n/2
c. n
d. 2n
e. n2
3. (2 marks) For how many of the names does binary search require more than two
comparisons to locate in the list: Ann, Bob, Garry, Jill, Kim, Mary, Sid
a. 1
b. 2
c. 3
d. 4
e. 5
4. (2 marks) The following graph demonstrates the relationship between the input size
and the amount of work done by 3 different algorithms: A, B, and C.
140
120
A
100 B
Work
80 C
60
40
20
0
10 20 30 40 50 60 Input size n
5. (2 marks) Which of the following are considered main subsystems in the Von
Neumann architecture?
a. memory, ALU, control unit, system software
b. memory, ALU, cache
c. memory, ALU, cache, control unit
d. memory, ALU, control unit
e. ALU, cache, control unit
6. (2 marks) Which of the following properties is NOT true for random access memory:
a. each memory cell has a unique address
b. the time it takes to fetch or store a memory cell is the same for all cells
c. the maximum memory size is called address space
d. a part of a memory cell can be fetched or stored
e. information can be both fetched and stored
7. (2 marks) A decoder with N input lines has how many output lines?
a. 1
b. N
c. 2N-1
d. 2N
e. N2-1
f. N2
8. (2 marks) Which of the following services is typically NOT provided as a part of the
operating system:
a. an user interface
b. compilation of programs
c. deadlock avoidance and detection
d. access control to the computer and its resources
e. multiprogramming support
10. (2 marks) The operating system uses various methods to ensure the security of the
computer system. Which of the following is NOT a system security mechanism:
a. encryption
b. deadlock prevention
c. authorization lists
d. user access control
e. login ids and passwords
CMPUT101 Section A6 Final Exam Page 4 of 10 ID#:_____________
2. (7 marks) Use bubble sort to order the following list of numbers in an ascending
order (the algorithm is given below): 5, 4, 2, 3
a) Show the list after each exchange of elements (not necessary to show the markers):
b) How many comparisons of the elements in the list did the algorithm do in total?
c) How many exchanges of the elements in the list did the algorithm do in total?
CMPUT101 Section A6 Final Exam Page 5 of 10 ID#:_____________
2. (4 marks) Show how the decimal number -17.75 is stored in a computer that uses 16
bits to represent real numbers (10 for the mantissa and 6 for the exponent, both
including the sign bit). Show your work as indicated below.
c) Show how the binary number will be stored in the 16 bits below
3. (2 marks) Are these Boolean expressions True or False, when X=1, Y=5, Z=10?
a
+ + x = _________________________
b
• y = b•c
c
a) The Boolean expression that describes the output value of y is shown above.
Similarly, write in the space above the expression that describes the value of x.
b) For the two rows shown in the truth-table below, fill in the correct output values for x
and y:
Input Output
a b c x y
0 0 0
1 0 1
CMPUT101 Section A6 Final Exam Page 6 of 10 ID#:_____________
Input Output
a b x Y
0 0 1 0
0 1 0 1
1 0 0 1
1 1 1 0
x = ___________________ y = ____________________
When storing a value in RAM, prior to issuing the store signal the data value needs
to be placed in the _________________, whereas the address where the value will
be stored is placed in the _________________.
CMPUT101 Section A6 Final Exam Page 7 of 10 ID#:_____________
2. (4 marks) What does the following assembly program output when executed?
.BEGIN
LOAD B
ADD Two
STORE B
COMPARE A
JUMPLT Else
LOAD A
SUBTRACT Two
STORE A
OUT A
JUMP Endif
Else: LOAD A
ADD Two
STORE A
OUT A
Endif: OUT B
HALT
A: .DATA 5
B: .DATA 2
Two: .DATA 2
.END Answer: _______ _______
i = 0;
while ( i <= MaxData ) {
cout << “Enter a number:”;
cin >> n;
Data[i] = n;
i = i + 1;
}
}
Answer:
a) (3 marks) b) (3 marks)
#include <iostream.h> #include <iostream.h>
void main() void main()
{ {
int a, b, c; int i, location, b, A[4];
a = 2;
b = 4; A[0] = 0;
c = a + b; A[1] = 10;
if ( c >= (b + 1) ) { A[2] = 20;
b = b - 1; A[3] = 30;
cout << b << “,” << c;
} b = 20;
else { location = 0;
b = b + 1; i = 0;
cout << b << “,” << c; while ( i <= 3 ) {
} if ( b == A[i] ) {
} location = i;
}
i = i + 1;
}
cout << “ i= ” << i;
cout << “ loc= “ << location;
}
Answer: Answer:
CMPUT101 Section A6 Final Exam Page 9 of 10 ID#:_____________
3. (4 marks) Write a C++ program that inputs an integer number and displays its
absolute value (i.e., if the input value is negative then the value would be displayed
as positive and if the input value is positive or 0 then the output should coincide with
the input. For example, if the input is –3 the output value will be 3).
#include <iostream.h>
void main()
{
#include <iostream.h>
void main()
{
}
CMPUT101 Section A6 Final Exam Page 10 of 10 ID#:_____________
5. (16 marks) Write a C++ program that prompts the user to enter 5 exam marks
(design your program such that it would be easy to change if we wanted it to work
for more than 5 exams) The program then displays the average mark, the highest
mark, and number of marks entered that are less than the average mark. For
example, when executing the program and inputting the numbers 20, 30, 10, 40, 50
the running session will look as follows:
Enter a mark: 20
Enter a mark: 30
Enter a mark: 10
Enter a mark: 40
Enter a mark: 50
#include <iostream.h>
void main()
{