Professional Documents
Culture Documents
159.102 Computer Science Fundamentals - Massey - Exam - S2 2016
159.102 Computer Science Fundamentals - Massey - Exam - S2 2016
102 CP
ALB
Internal
MASSEY UNIVERSITY
ALBANY CAMPUS
EXAMINATION FOR
159.102 COMPUTER SCIENCE FUNDAMENTALS
Page 1 of 5
1602/159.102 CP
ALB
Internal
(b) Describe the term "seek time" when applied to a hard disk. [1]
(e) Which header file contains the declaration of the function getchar? [1]
(f) When creating and running an executable file from a C source file, errors
can be discovered in each of the four phases: pre-processing, compiling,
linking and running. Give one example of an error from each phase. [4]
(g) What return value indicates that the main function has succeeded? [1]
(h) Describe the difference between a "static" and a "dynamic" library? [2]
Page 2 of 5
1602/159.102 CP
ALB
Internal
2. (a) In a simplified empty file system, the allocation table has 16 entries:
0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
The first two entries (each with a value of 0) are special and are where the
FAT and the directory are stored. A normal entry with a value of 1 means
that the corresponding sector on the disk is free. A normal entry with a
value of 0 signifies the end of a chain of sectors. When allocating a new
sector the lowest numbered free sector is always chosen. The directory,
which contains the filenames and initial sectors, is always sorted
alphabetically on the filename.
What do the FAT and directory contain after each of the following actions:
(i) File c (4 sectors) is added. [1]
(ii) File a (2 sectors) is added, and then c is truncated to 2 sectors. [1]
(iii) File b (4 sectors) is added. [1]
(e) Write, as a decimal, the value of the 32-bit floating point number that is
represented by the hexadecimal number:
c0b000016 [1]
(f) Declare a C structure that can contain data describing an Audio CD. The
album title, the performer, how many tracks there are (minimum 1,
maximum 30), the length of each track (in seconds) and the song title of
each track. [1]
(g) Write a C function print_CD that has an element of the above structure
passed as an argument (via a pointer). The function prints the details of
the CD in a suitable format. [2]
(h) Assume that you already have a 20-element array a of the above
structure, which has been initialised with the data of 20 different CDs.
Write a piece of C code that uses a loop to find and then print, using the
function in Question 2(g), the details of the CD that has the shortest track.
There will be a unique answer. [5]
Page 3 of 5
1602/159.102 CP
ALB
Internal
(d) Write a piece of C code that releases the memory on the heap allocated
in the second example of your answer to Question 3(c). [1]
(e) Which header file would have to be included for your answer to
Questions 3(c) and (d)? [1]
(g) With the variables defined in Question 3(f), which of the following
statements will generate a compile time error?
(i) a[0] = p;
(ii) q[0] = a;
(iii) *p = &m;
(iv) *q[0] = p[0]; [2]
(h) On a 32-bit computer what is the total size in bytes of the variable q in
Question 3(f)? [1]
Page 4 of 5
1602/159.102 CP
ALB
Internal
4. (a) The function scanf has a rule that means it will skip white-space before
reading the user input for some format specifiers. Which of the following
specifiers does this rule apply to:
(i) %c
(ii) %d
(iii) %s
(iv) %[a-f] [1]
F(0) is 1
M(0) is 0
For n>0,
F(n) is n – M(F(n-1))
M(n) is n – F(M(n-1))
(e) Using your function in Question 4(d) write a main function that prints F(3),
and by adding a comment to your program, state what the answer will be.
[4]
+++++++
Page 5 of 5