Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

1602/159.

102 CP
ALB
Internal

MASSEY UNIVERSITY
ALBANY CAMPUS

EXAMINATION FOR
159.102 COMPUTER SCIENCE FUNDAMENTALS

Semester Two 2016

Time Allowed: THREE (3) hours

ANSWER ALL FOUR QUESTIONS.

Each question is worth 15 marks

Calculators are permitted no restrictions

Page 1 of 5
1602/159.102 CP
ALB
Internal

1. (a) Give approximate typical sizes for the following:

A USB flash drive. [1]


A hard disk. [1]
A CDRom. [1]
System RAM. [1]

(b) Describe the term "seek time" when applied to a hard disk. [1]

(c) What is the typical sector size of a hard disk? [1]

(d) What is the approximate downstream rate of a household internet


connection using fibre? [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]

(b) What is the decimal value of the binary number 1.101


(where the '.' is a binary point)? [1]

(c) What is the binary value of the decimal number 12.75


(where the '.' is a decimal point)? [1]

(d) Write, in hexadecimal, the 32-bit floating point representation of:


-0.75 [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

3. (a) In a project with many source files:


(i) What is usually placed in header files: declarations or definitions? [1]
(ii) Do you get a compile or link error if you define a function in more
than one source file? [1]
(iii) Which program would you use to automate the project build? [1]

(b) In which area of memory are local variables stored? [1]

(c) Pointers can be assigned values either by pointing them at existing


variables or by pointing them to memory allocated on the heap. Write a
piece of C code that gives an example of each. [2]

(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]

(f) What are the types of the following 4 global variables?


(i) int m = 3; [1]
(ii) int *p = &m; [1]
(iii) int a[80]; [1]
(iv) int *q[80]; [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]

(b) The format specifier %[a-f] above is an example of a "scan set".


Describe how scanf reads input using this specifier. [1]

(c) Given the following piece of C code:

printf("%d", scanf("%d", &i));


c = getchar();
d = getchar();
gets(s);
The user types in the following (where [Enter] is the Enter Key):
123a Beach Road[Enter]

(i) What are the final values of i, c, d and s? [2]

(ii) What is printed? [1]

(d) The Female-Male sequence proposed by Douglas Hofstadter in the 1980s


can be programmed by creating two mutually recursive functions F and M.

F(n) and M(n) are defined as:

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

Write the recursive functions F and M. [6]

(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

You might also like