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:
|
|
|
|
|
|
T |
T |
F |
T |
|
T |
F |
F |
T |
|
F |
T |
F |
T |
|
F |
F |
F |
T |
| Address: |
|
|
|
|
|
|
|
|
|
|
|
|
| Contents: |
|
|
|
|
|
|
|
|
|
|
|
|
| Address: |
|
|
|
|
|
|
|
|
|
|
|
|
| Contents: |
|
|
|
|
|
|
|
|
|
|
|
|
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 |
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);
}
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.
[10 marks]