Nothing Special   »   [go: up one dir, main page]

159.102 Computer Science Fundamentals - Massey - Exam - S1 2017

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

1701/159.

102 CP
ALB
Internal

MASSEY UNIVERSITY
ALBANY CAMPUS

EXAMINATION FOR
159.102 COMPUTER SCIENCE FUNDAMENTALS

Semester One 2017

Time Allowed: THREE (3) hours

ANSWER ALL FOUR QUESTIONS.

Each question is worth 15 marks

Calculators are permitted no restrictions

The exam paper will be made available on the Massey University Library website
in due course website.
The examination question paper is not to be removed from the exam room.

Page 1 of 5
1701/159.102 CP
ALB
Internal

1. (a) Draw a diagram that shows how a disk is organised into sectors and
tracks. [2]

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

(c) What is:


(i) the typical capacity of a hard drive? [1]

(ii) the typical downstream data rate of a fibre connection? [1]

(iii) the resolution of a full HD display? [1]

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

(e) Which program handles #include <string.h>? [1]

(f) Explain the use of the PATH environment variable. [2]

(g) The function prototype for the main function of the program test.c is:
int main(int argc, char *argv[]);

If the following command is given to execute the program test:

test parameter1 "Programming Fundamentals" >output.txt

(i) What do the following contain:


argc [1]
argv[0] [1]
argv[2] [1]

(ii) What is the type of argv[1]? [1]

(iii) What will output.txt contain after the program has run? [1]

Page 2 of 5
1701/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) Files c (5 sectors), then a (2 sectors), then b (4 sectors) are
added. [
1]
(ii) File a is deleted. [1]
(iii) File c is extended by another 3 sectors. [1]

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


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

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


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

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


-3.75 [1]

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

(f) Declare a C structure that can contain data describing a sheet of paper.
Its height and width (both integers in millimetres), its colour (a string, e.g.
"red", "yellow" etc.) and whether it has lines (an unsigned char – 0 is false,
1 is true). [1]

(g) Write a C function area that has an element of the above structure
passed as an argument (via a pointer). The function returns the area of
the paper (height * width). [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 paper
types. Write a piece of C code that uses the function in Question 2(g) and
loops, to find and then print whether the "blue" paper with the largest area
has lines or not. There will be a unique answer. [5]

Page 3 of 5
1701/159.102 CP
ALB
Internal

3. (a) Write a makefile, that when used with the program make, automates the
creation of a program test.exe.
test.exe depends on two source files test.c and f.c.
A header file test.h is also included in both of the source files. [2]

(b) When a C program calls a function, a stack frame is created.


What items are stored in the stack frame? [1]

(c) Declare a C structure Node that describes a node in a linked list. The
linked list consists of one data item (an integer), and a single pointer to the
next node in the list. [1]

(d) Draw a diagram of a linked list of 2 nodes as described in Question 3(c).


Give values for all the pointers and data, and show which of the variables
are on the stack and which are on the heap. [3]

(e) Write a piece of C code that inserts a node (containing the number 45) at
the beginning of the linked list in Question 3(d). [4]

(f) Given the following local variables:

int n = 5;
char s[80] = "Massey";
char *p;
int *ip;

(i) What are the types of p and ip? [1]

(ii) Write a C statement that allocates n integers on the


heap to the variable ip. [1]

(iii) Write a C statement that points p to the character y of the


array s. [1]

(iv) Without using s, write a C statement that then changes the y


of "Massey" to a d. [1]

Page 4 of 5
1701/159.102 CP
ALB
Internal

4. (a) (i) What is the effect of these format specifiers when used with scanf?

%x [1]
%[aeiou] [1]

With these definitions:

char c;
char s[80];
int i, result;

the following lines of a valid C program are executed:


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

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

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

(b) The Q-sequence was proposed by Douglas Hofstadter in the 1980s.

For the whole number n>0, Q(n) is defined as:

Q(1) is 1
Q(2) is 1

For n>2, Q(n) is Q(n – Q(n–1)) + Q(n – Q(n–2))

Write the recursive function Q. [6]

(c) Using your function in Question 4(b) write a main function that prints the
value of Q(5), and by adding a comment to your program, state what the
answer will be.
[4]

+++++++

Page 5 of 5

You might also like