Massey University

ALBANY CAMPUS

EXAMINATION FOR 59.102 COMPUTER SCIENCE FUNDAMENTALS

Supplementary Exam - February 1998

Time Allowed: THREE (3) Hours

INSTRUCTIONS

Answer ALL questions.

Calculators ARE allowed.

1. Consider the truth table:

 A B C Output T T T T T F T T T T F F T F F T F F T T T F T T F F F F T F F T
(a) Convert the truth table into a Boolean expression and then reduce the expression as much as possible. Show all steps in the reduction.

[5 marks]

(b) Draw a circuit which corresponds to the truth table. You should make use of the reduced expression from (a) above.

[5 marks]
2. Assume a computer using the 2?s complement system with a word size of 8 bits. Show how this computer would perform the operation 9 - 14. Show all working and show how to check the answer.
[5 marks]

3. Work through the following machine code program. Clearly show all changes to the program counter, the instruction register, the registers and any relevant memory locations. A list of instructions is provided.

 Address: 00 01 02 03 04 05 06 07 08 09 0A 0B Contents: 21 15 12 15 23 AB 54 12 95 23 34 0E Address: 0C 0D 0E 0F 10 11 12 13 14 15 16 17 Contents: 35 0F B2 16 B0 08 15 CA 71 AB C0 00

[10 marks]

List of Machine Instructions

 1RXY = Indirect Load 7RST = OR 2RXY = Direct Load 8RST = AND 3RXY = Store 9RST = XOR (Exclusive OR) 40RS = Copy R to S AR0X = Rotate to the right x times 5RST = Add integers BRXY = Jump if R = = R0 6RST = Add floats C000 = Halt
4. The following program has 10 errors in it. Copy the program into your answer book and clearly indicate each error. Explain why there is an error at each point and what should be done to correct it. Do NOT worry about the # include files at the top.

char first[99], second[99], result[99];

char menu (void);
void reverse (char r, char s);
void addnum (void);

main () {
printf ("Enter first number\n");
gets (first);
printf ("Enter second number\n");
gets (second);
}

void reverse (char r, char s) {
int i, j;
len = strlen(s); j = 0;
for (i = len-1; i >= 0; i++) {
r[j] = s[i]; j++;
}
}

void addnum (void) {
char s1, s2, s3;
int a, b, i = 0;

reverse (s1, first);
reverse (s2, second);
while (s1[i] != '\0') {
a = s1[i] - 48;
b = s2[i] - 48;
s3[i] = a + b;
}
s3[i] = '\0';
printf ("The result is %s\n", result);
}

[20 marks]

5. When the errors in the program in question 4 above have been fixed, the program will run. It will then read in two numbers - represented as strings - and add them together. However, the program has a serious logical problem and in some cases it will not add numbers together correctly. Explain what the problem is and give an example of two numbers that will not be added correctly. Note that this problem has nothing to do with the errors you found in question 4.

[5 marks]
6. Write a C program that reads in students? names and test marks from the screen. Assume there are less than 100 students in the class. Then print a list of names and marks of all students whose mark is above the average mark.
[10 marks]
7. There is a file called books.txt where each line contains the title of a book. Write a C program that reads in one letter and prints out all book titles which begin with that letter.

[10 marks]

+ + + + + + + + + +