Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Repeat Paper No
No. of Pages 5
Department(s) Information Technology
Page 1 of 5
C Programming
A.
i. What output would the following code produce?
#include <stdio.h>
void main()
{
int x = 23;
int y = 6;
int num;
float res, res2;
res = x/y;
num = x%y;
res2 = x/4.0;
}
ii. Write a function in C that takes one argument, an array of 40
elements. Your function should print out average of the elements
in the array. It should also print out the values in the array that are
less than this average.
[10 Marks]
C. Write a program in C that reads in 300 integers that represent the exam
results of students. Once the 300 numbers have been read in your code
should do the following:
PTO
Page 2 of 5
2. Answer any 2 of the 3 parts to this question. All parts carry equal marks.
A.
Figure 1
1. A function to request a user for the dimensions of the yard and the
pond.
2. A function to determine the area of the yard without including the
pond.
[10 Marks]
5 3 4 2 7 99 100 101
[10 Marks]
A. Write a function in C that reads 20 numbers from the console and stores
these values in an array. The function should return the average of those
number to main where they can be displayed. Show the full program and
how the function would be called from main.
[10 Marks]
PTO
Page 3 of 5
Arduino Section
Answer Question 3 OR 4
Q3
a. Write a program for Arduino that controls a set of two traffic lights at a
crossroads. Assume that when the east-to-west traffic lights are green or amber,
the north-to-south traffic lights are red. Green lights must stay on for 2 minutes
and the amber lights for 6 seconds (remembering that in all other cases the light
must be set to red). You can assume that the Arduino is wired to the traffic lights
in the following pin configuration.
b. Write a program for Arduino that reads the analog input from a temperature
sensor and uses this value to control a light emitting diode (LED). The purpose of
this system is to warn the user of an increasing temperature by varying the output
of the LED as the temperature passes two separate thresholds. The system is
outlined as follows:
Temperature sensor attached to analog input 0 of the Arduino; LED
attached from digital pin 9 of the Arduino to ground
For the sensor, as temperature increases the analogue readings increase
(range 0 to 1023). The max temperature which can be read is 80 degrees;
the min temperature which can be read is 0. Use a function to re-map the
range to represent the real world values.
The first threshold should be at roughly 30 degrees, the next should be at
roughly 50 degrees. If the first threshold is reached, the LED should turn
ON, if the second threshold is reached, the LED should start BLINKING.
Other than that, the LED should be OFF.
[7 marks]
c. Outline two positives and two negatives of the kind of ‘hard’ thresholding
outlined in part b.
[3 marks]
PTO
Page 4 of 5
Q4
a. To smooth the accelerometer output from a games controller such as the Nintendo
Wii, an analogue smoothing filter is often required. You have a plan to build a
similar game controller and have written all the necessary code except for the
smoothing function. Write the required function which takes in the accelerometer
data as an input and outputs a smoothed version of the signal.
Your function should use a buffer which takes in 4 samples and returns an
average (such as a mean or median) without introducing a significant lag (i.e. a
moving average).
[10 marks]
END
Page 5 of 5