FIRST EXAMINATION IN ENGINEERING Programme Codes: ENBDF0002, ENBDF0003, ENBDF0004, ENBDF0005, ENBDF0008, ENBDF0011 COMP1604 COMPUTER SCIENCE, SUMMER EXAMINATIONS 2003 SOLUTIONS 1.(a) True (b) False (e.g. could have run-time errors) (c) The most widely used tools for developing algorithms are flowcharts and __pseudo-code__ . (d) value of w is -3 (e) value is 1.7321 (f) exceptional case (g) condition is true (h) i is 12 i is 3 i is 0 (i) default 2 3 default default (j) correct answer is (j-2) it does not return a value (k) correct answer is (k-3) fname() takes 1 argument of type pointer-to-double and returns a value of type int. (l) result is 19 (m) correct answer is (m-3) arr[0]+arr[2] (n) False (compiles ok, up to programmer to not access memory locations that are not part of the array) (o) x[0] is 2.00 x[1] is 1.00 x[2] is 0.67 y[0] is 2 y[1] is 1 y[2] is 0 (p) correct answer is (p-2) *ptr1 = y; (q) x is 5 and y is 5 (r) True (s) vowels=YYYou (t) correct answer is (t-1) open datafile.txt for appending, creating the file if it doesn't already exist. 2.(a) int i; /* could be: int i=0; */ char string[100]; /* assume string[] is somehow filled with letters, digits, etc */ i=0; while (string[i]!='\0'){ if ((string[i] >= '0') && (string[i] <= '9')){ printf("%c", string[i]); } i++; } (b) switch(mark){ case 10: case 9: case 8: case 7: printf("Excellent\n"); break; case 6: case 5: case 4: printf("Satisfactory\n"); break; case 3: case 2: case 1: case 0: printf("Fail\n"); break; default: } (c) void nonneg(int array[], int size){ int i; /* local loop counter */ for (i=0; i void main(void) { FILE *fptr1, *fptr2; int inp; fptr1 = fopen("input2.dat", "r"); fptr2 = fopen("output2.dat", "w"); while (fscanf(fptr1, "%d", &inp)==1){ if ((inp%2)==0){ fprintf(fptr2, "%d,", inp); } } fclose(fptr1); fclose(fptr2); }