You should be able to complete these questions in less than fifteen minutes each.
In the file dotprod.c, you will find a function dotprod(), together with some main code to read arrays and print the result. Complete the function dotprod() so that it computes the dot product of a and b of dimension n.
| Speed limit | Recorded speed | ||
|---|---|---|---|
| 30 | 31-40 | 41-50 | 51- |
| 40 | 41-55 | 56-65 | 66- |
| Penalty | 3 points | 4-6 points | disqualify |
In the file speeding.c, you will find a main routine that reads a speed limit and recorded speed. Complete the program so that it prints out the penalty (exactly as described in the table).
You are provided with a template file drawing.c. Study the code and comments in this file.
Recall that to compile this program you should do
gcc drawing.c descartes.o -lSDL
(a) Your first task is to complete the routine void MarkPoint(point_t p), which marks the point on the screen. If the argument point p is at (x,y), then your code should draw a square (by constructing and drawing line segments) whose corners are (x ± c, y ± c), where c is the value of the program variable OFFSET. (5 marks)
(b) The second task is to complete the routine int FindPoint(point_t p). Given the argument p, your code should return the index i of the first point q = points[i] such that p is within OFFSET units of q in both coordinates. That is, qx − OFFSET ≤ px ≤ qx + OFFSET and similarly for the y coordinate. If there is no such point, your code should return -1. (10 marks)
(c) The final task is to complete the main routine. In the section marked for the answer to part (c), add code to do the following: use AskPoint to get the end point index from the user; clear the selection marker on the start point (by calling MarkSelected with second argument 0); set the finished flag if the user middle-clicked, and otherwise draw a line from the start point to the end point. (10 marks)
|
Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk Please contact our webadmin with any comments or corrections. Logging and Cookies Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh |