0% found this document useful (0 votes)
8 views10 pages

Finalexam A6

This document is a final exam for CMPUT 101, administered on December 15, 2000, with various sections including multiple choice questions, algorithms, binary numbers, circuits, Von Neumann architecture, assembly language, and C++ programming. It contains instructions for completing the exam, including rules about aids and how to submit answers. The exam is structured to assess knowledge in computer science fundamentals and programming skills.

Uploaded by

reza goldaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Finalexam A6

This document is a final exam for CMPUT 101, administered on December 15, 2000, with various sections including multiple choice questions, algorithms, binary numbers, circuits, Von Neumann architecture, assembly language, and C++ programming. It contains instructions for completing the exam, including rules about aids and how to submit answers. The exam is structured to assess knowledge in computer science fundamentals and programming skills.

Uploaded by

reza goldaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CMPUT 101

Final Exam (2 hours)


December 15, 2000

Last Name: __________________________

First Name: __________________________

Student ID: ____________

Signature: __________________________

Section: A6

Instructor: Yngvi Bjornsson

Instructions: Read carefully before proceeding.


No calculators, books or other aids are permitted for this test.

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!

Marks: (don’t write anything below)


I II III IV V VI Total

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

What order of magnitude would you expect algorithm C to be?


a. O(log2(n))
b. O(n)
c. O(n2)
d. O(n3)
e. O(2n)
CMPUT101 Section A6 Final Exam Page 3 of 10 ID#:_____________

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

9. (2 marks) In an operating system a deadlock describes a situation where two or


more programs
a. lock up the keyboard and the screen
b. are waiting for the processor to become idle
c. are waiting for a resource to become available that never will
d. are printing and accessing the hard-drive at the same time
e. are waiting for the other program to terminate

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#:_____________

Part II: Algorithms


1. (4 marks) Given the following algorithm:

Get value for n


Set value of x to 5
Repeat until n < 1
If the value of x is greater than n then
Subtract 2 from x
Print the value of n and x
Decrease n by 1
End loop
Print the value of n and x
Stop

a) What does the algorithm print out when the input n is 3?

b) What does the algorithm print out when the input n is 0?

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

1. Get values for n and the n list items


2. Set the marker U for the unsorted section at the end of the list
3. Repeat steps 4 through 8 until the unsorted section of the list has just one element
4. Set the current element marker C at the second element of the list
5. Repeat steps 6 and 7 until C is to the right of U
6. If the item at position C is less than the item to its left then exchange the items
7. Move C to the right one position
8. Move the marker U for the unsorted section forward (left) one position
9. Stop

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#:_____________

Part III: Binary Numbers and Circuits


1. (1 mark) Convert the binary number 11011 to decimal. Show your work.

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.

a) Show the binary representation of the number:

b) Show the binary number in normalized scientific notation:

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) (Z>5) AND (NOT (Y>X)) _____ (T/F)

b) (NOT ((X<Y) OR (Y<Z))) AND (Y<Z) _____ (T/F)

4. (4 Marks) The following circuit is given:

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#:_____________

5. (5 Marks) Use the sum-of-products circuit construction algorithm to design a circuit


using AND, OR, and NOT gates that implements the following truth table.

Input Output
a b x Y
0 0 1 0
0 1 0 1
1 0 0 1
1 1 1 0

a) Write the expressions that describe the outputs

x = ___________________ y = ____________________

b) Draw the circuit diagram.

Part IV: Von Neumann Architecture


1. (2 marks) The following action shows what happens when a particular machine
instruction is being executed: IRaddr à PC
Which machine instruction is being executed: ________________

2. (6 marks) Fill in the blanks.

The task of the ___________________ is to fetch, decode, and execute machine


language instructions. The ________________ holds the address of the next
instruction to be fetched and executed.

Disc access time consists of several components. The ____________________ is


the time needed to position the read/write head over the correct track, whereas
_________________ is the time it takes the beginning of the desired sector to get
under the read/write head.

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#:_____________

Part V: Assembly language


1. (3 marks) Assuming that memory locations X and Y store the values 2 and 3
respectively, what values will they and the register R store after the following
assembly program fragment is executed?
LOAD X
INCREMENT X
ADD Y
STORE Y Answer: X = ____ Y = ____ R = ____

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: _______ _______

Assembly Language Instructions


INSTRUCTION MEANING
LOAD X CON(X) à R
STORE X R à CON(X)
CLEAR X 0 à CON(X)
ADD X R + CON(X) à R
INCREMENT X CON(X) + 1 à CON(X)
SUBTRACT X R – CON(X) à R
DECREMENT X CON(X) – 1 à CON(X)
COMPARE X If CON(X) > R then GT = 1 (EQ=0, LT=0)
If CON(X) = R then EQ = 1 (GT=0, LT=0)
If CON(X) < R then LT = 1 (GT=0, EQ=0)
JUMP X Transfer to memory location X
JUMPGT X Transfer to location X if GT = 1
JUMPEQ X Transfer to location X if EQ = 1
JUMPLT X Transfer to location X if LT = 1
JUMPNEQ X Transfer to location X if EQ = 0
IN X Input an integer value from the standard input device and store it in memory cell X.
OUT X Output, in decimal notation, the value stored in memory cell X.
HALT Stop program execution.
CMPUT101 Section A6 Final Exam Page 8 of 10 ID#:_____________

PART VI: C++ programming (38 marks)


1. (4 marks) Name two things that are wrong with the following C++ program:
// This program reads in 5 integers and stores them in an array.
#include <iostream.h>
void main()
{
const int MaxData = 5;
int i, Data[MaxData];

i = 0;
while ( i <= MaxData ) {
cout << “Enter a number:”;
cin >> n;
Data[i] = n;
i = i + 1;
}
}

Answer:

2. (6 marks) What do the following two programs output when executed?

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()
{

4. (8 marks) Implement the following algorithm in C++:


Set the value of MAXVALUE to 20
Set the value of i to 0
While i is less than MAXVALUE do
Get values for A and B
If B is not equal to 0 then
Set the value of C to A / B
Print the value of C
Increase i by 1
Else
Print the message, “B cannot be zero”
End loop
Stop

#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

Average mark is: 30.0


Highest mark is: 50
Number of marks less than the average: 2

#include <iostream.h>
void main()
{

You might also like