159.101 Computer Science Fundamentals - Massey - Exam - S1 2015
159.101 Computer Science Fundamentals - Massey - Exam - S1 2015
101
ALBANY
Internal
CP
MASSEY UNIVERSITY
ALBANY CAMPUS
EXAMINATION FOR
159.101 PROGRAMMING FUNDAMENTALS
Total: 55 marks
Page 1 of 5
1501/159.101
ALBANY
Internal
1. Write down exactly what the following program will display on the screen.
Note that this is a correct program and it will display something on the screen.
It is a good idea to do a walkthrough and show all the variables.
#include <stdio.h>
int main(){
letter = 'a';
for (row = 0; row < 3; row++ ) {
count = 0;
while (count < row) {
printf("?");
count++;
}
exam(row, letter);
}
}
2. (a) Write the prototype for a function that has two characters passed
to it and returns the difference between their ASCII codes.
[2 marks]
(c) Give the decimal and binary values of the ASCII code that
represents the character ‘3’
[2 marks]
Page 2 of 5
1501/159.101
ALBANY
Internal
Note: it does not matter if letters are upper case or lower case. For example,
levEL should still be recognised as a palindrome.
[10 marks]
(b) Assume a computer that uses twos complement arithmetic with a 6-bit
word length. Show how the calculation 4 – 8 would be performed.
Show how to check your answer. Include all working.
[6 marks]
Page 3 of 5
1501/159.101
ALBANY
Internal
5. A university has a CSV file called student.csv that contains data about the
students. Each line in the file uses the format:
For example, the first four lines in the file could look like this:
Mouse Minnie,2010936,BSc
Uphill Pippin,1998148,BSc
Presley Elvis,1958072,BA
Duck Donald,2001375,BSc
The first 4 digits of the id number are the year that the student first enrolled in
the university. Eg. Student with id 2008291 first enrolled in 2008.
Write a C program that reads all the data from the file and displays the names
of all students who enrolled in the university before 2005 and are studying for
a BSc degree. Display the names in alphabetical order.
For example, the output of your program should look something like this:
[10 marks]
Page 4 of 5
1501/159.101
ALBANY
Internal
6. A hospital uses the following program to calculate which is the biggest group
of patients – based on the age of the patients. Ages are collected in groups of
10, for example there is a group for patients with ages 20 to 29 and another
group for patients with ages 30 to 39 and so on.
There are ten (10) errors in the program. Write down each error and how to
correct it. Do not rewrite the whole program.
#include <stdio.h>
int main(){
counting();
maxindex = 0;
for (i = 1; i < 15; i++) {
if (count[i] > max) {
max = count[i];
i = maxindex;
}
}
printf("The age of the biggest group is %d to\n",
maxindex*10, maxindex*10 + 9);
printf("There were %d patients in this group.\n",
count[i]);
}
void counting() {
// function counts how many patients in each age group
int i, age;
++++++++
Page 5 of 5