159.102 Computer Science Fundamentals - Massey - Exam - S2 2019

You might also like

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

1902/159.

102 CP
AKLI

MASSEY UNIVERSITY
AUCKLAND CAMPUS

EXAMINATION FOR
159.102 COMPUTER SCIENCE FUNDAMENTALS

SEMESTER TWO 2019

Time allowed: THREE (3) Hours.


All students are required to answer all the questions.
Each question is worth 15 marks.

Write your answers in the Blue Answer Book supplied.


Calculators are permitted no restrictions.
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
1902/159.102 CP
AKLI

1. (a) Give approximate values for the following:

(i) The total size of a hard disk. [1]

(ii) The sector size of a hard disk. [1]

(iii) The size of system RAM. [1]

(iv) The size of an SD card. [1]

(v) The downstream data rate of a 4G connection. [1]

(vi) The resolution in dpi of a laser printer. [1]

(b) What does ADSL stand for? [1]

(c) Describe the use of the PATH environment variable. [2]

(d) Which header file contains the declaration of the function scanf? [1]

(e) Creating an executable file from a C source program involves three


steps, each a separate program. Name and describe the actions of
each of the steps. [3]

(f) Give an example of a command that uses output redirection. [1]

(g) Would you expect an executable file that uses static libraries to be
bigger or smaller than one that uses dynamic libraries? [1]

Page 2 of 5 CoS
1902/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 f (4 sectors), then g (4 sectors) are added. [1]
(ii) File f is reduced to 2 sectors. [1]
(iii) File e (4 sectors) is added. [1]

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


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

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


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

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


8.25 [1]

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

(f) Declare a C structure that can contain data describing a smartphone:


its make (a string), its model (a string), its price in dollars (an integer),
its screen size (an array of 2 integers e.g. 1920x1080) and
its battery capacity (an integer). [1]

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


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

(h) Assume that you already have a 15-element array a of the above structure,
which has been initialised with the data of 15 different smartphones.
Write a piece of C code that uses a loop to find the Huawei phone that has
the largest battery.

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

Page 3 of 5 CoS
1902/159.102 CP
AKLI

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

(i) How do you include a user-created header file as opposed to


a system header file? [1]
(ii) What is the name of the file that, by default, make will use to build
your project? [1]
(iii) What is the scope of a static function? [1]
(iv) Global variables can be declared multiple times, but can only
be defined once. True or False? [1]

(b) struct Node {


int data;
Node *next;
};

(i) What is the type of next? [1]

(ii) Draw a diagram of a linked list of 3 Nodes.


Give values and addresses for all parts of the list, and indicate which
are on the stack and which are on the heap. [2]

(iii) Write a piece of C code that deletes the first Node in the list. [2]

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

(i) char s[16] = "ACE"; [1]


(ii) char *p = s+1; [1]
(iii) char *q[5]; [1]
(iv) char (*r)[8]; [1]

(d) Assuming you have all the correct header files included and with the
variables defined in Question 3(c), which of the following statements are
correct?

(i) s[3] is initialised.


(ii) q[0] = &p; compiles ok.
(iii) *p == 'C' is true.
(iv) q[4] = (char *)malloc(10*sizeof(char)); compiles ok. [2]

Page 4 of 5 CoS
1902/159.102 CP
AKLI

4. (a) (i) What is the effect of these format specifiers when used with scanf?
%5s [1]
%[a-e] [1]

With these definitions:

char c;
int j = 1, result;
char t[32];
The following lines of a valid C program are executed:

result = scanf("%s %d", t, &j);


c = getchar();
The user types in the following (where [Enter] is the Enter Key):
Massey University[Enter]

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

(iii) Making all whitespace "visible", what is left in the input buffer? [1]

(b) The recursive function y has two integer arguments m and n and
returns an integer.

y obeys the following:

if m equals n, then y returns 0


if m is greater than n, then y returns
(m – n) + the function y called with arguments (m divided by 2) and n
if m is less than n, then y returns
(n – m) + the function y called with the arguments m and (n divided by 2)

Write the function y. [6]

(c) Using your function in Question 4(b) write a main function that prints
the value of y with the arguments of 26 and 7. [2]

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

+++++++

Page 5 of 5 CoS

You might also like