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

1802/159.

102 CP
AKLI

MASSEY UNIVERSITY
AUCKLAND CAMPUS

EXAMINATION FOR
159.102 COMPUTER SCIENCE FUNDAMENTALS

SEMESTER TWO 2018

Time allowed is THREE (3) Hours.

ANSWER ALL FOUR QUESTIONS.


Each question is worth 15 marks.
Calculators are permitted – no restrictions.

Write your answers to all applicable questions in the Blue Answer Book supplied.
Students may NOT remove any part of this question paper from the exam room.
The exam paper will be made available on the University Library website.

Page 1 of 5 CoS
1802/159.102 CP
AKLI

1. (a) Describe two different causes of delay while reading data from
a hard drive. [2]

(b) Describe one way of minimising the delays in Question 1(a). [1]

(c) eBooks are typically about 200KBytes in size. If an eBook reader has
2GBytes of storage space, approximately how many books can be
stored on the reader? [1]

(d) What does BIOS stand for? [1]

(e) List the sequence of steps that are performed by the BIOS when
a computer is switched on. [2]

(f) What does USB stand for? [1]

(g) What characters are used for end-of-line in a Windows text file? [1]

(h) What does the C pre-processor do? [1]

(i) What does the C compiler do? [1]

(j) What does the C linker do? [1]

(k) What value does main return if it is successful? [1]

(l) Describe the difference between a static and a dynamic library. [2]

Page 2 of 5 CoS
1802/159.102 CP
AKLI

2. (a) In a simplified empty file system, the file 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) Files t1 (5 sectors), then t2 (2 sectors) are added. [1]
(ii) File t1 is reduced to 3 sectors. [1]
(iii) File t2 is extended to 6 sectors in total. [1]

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


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

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


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

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


11.75 [1]

(e) Write, as a decimal, the value of the 32-bit floating point number that is
represented by the hexadecimal number:
c102000016 [1]

(f) Declare a C structure that can contain data describing an Electric car:
its make (a string), its model (a string), its price in dollars,
its number plate (a string!), its colour ("red", "blue" etc.) and
the maximum number of kilometres it can go on a full charge. [1]

(g) Write a C function print_car_details that has an element of the


above structure passed as an argument (via a pointer). The function
prints the details of the Electric car in a suitable format. [2]

(h) Assume that you already have a 10-element array a of the above structure,
which has been initialised with the data of 10 different Electric cars.
Write a piece of C code that uses a loop to find the green car that can
go the most kilometres on a full charge.

Print the details of this car using your function in Question 2(g).
There will be a unique answer. [5]

Page 3 of 5 CoS
1802/159.102 CP
AKLI

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) A stack of up to 100 integers can be created using an array and an index.
Name the three standard functions that are associated with stacks. [1]

(c) Allowing the user of the stack direct access to the index variable is not
considered good programming practice, and can be overcome if two extra
functions are provided to the user.

Implement the two functions:


is_empty() which returns 1 if the stack is empty and 0 otherwise
and is_full() which returns 1 if the stack is full and 0 otherwise. [2]

(d) A stack of integers, containing at least one integer, already exists.


Using only the functions from your answers to Questions 3(b) and 3(c),
write a piece of C code that removes all the numbers from the stack and
replaces them with a single number, the average of all the original numbers.

The average can be found by dividing the sum of all the numbers on the
stack by how many numbers were on the stack. [3]

(e) What are the types of the following 4 variables?

(i) char m = 'T'; [1]


(ii) char *p = &m; [1]
(iii) char a[80]; [1]
(iv) int *q[5]; [1]

(f) Assuming you have all the correct header files included and with the
variables defined in Question 3(e), which of the following statements will
generate a compile time error?

(i) a[0] = *p;


(ii) q[0] = &m;
(iii) *p = &m;
(iv) q[0] = (int *)malloc(10*sizeof(int)); [2]

Page 4 of 5 CoS
1802/159.102 CP
AKLI

4. (a) The following lines of a valid C program are executed:


result = scanf("%s %d", s, &i);
c = getchar();
The user types in the following (where [Enter] is the Enter Key):
Apollo 11[Enter]

(i) What are the types of result, s, i, and c? [2]

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

(iii) Why is there an & before the i in the call to scanf? [1]

(b) The permutations of a string, with no repeated letters, are all the different
strings that can be formed by interchanging the letters of the string.

The permutations of "abc" are:

"bca", "cba", "cab", "acb", "bac" and "abc"

Printing all the permutations of the first n characters of a string s can be


achieved by using a recursive function:
void print_permutations(char *s, int n);

The algorithm for the function is as follows:

If n is 1 then print the string s and return

otherwise start a for loop where an integer i runs from 0 to less than n.
Inside the loop:

swap the characters in positions i and (n-1) of the string s.


print all the permutations of the first (n-1) characters of the string s.
swap the characters in positions i and (n-1) of the string s.

Write the recursive function print_permutations. [6]

(c) Using your function in Question 4(b) write a main function that prints all
the permutations of the string "abcd" using the length of the string
as the initial value for n. [2]

(d) What is the first permutation printed by the above program? [2]

+++++++

Page 5 of 5 CoS

You might also like