本从此澳洲代写主要为programming的限时测试

SECTION A — SHORT ANSWER QUESTIONS
Attempt ALL questions available in Section A. All questions in Section A are of equal
value. Each question is worth 12 marks. This section is worth 48 marks, or 26.7% of the
examination.
Question 1. (Assessing ILOs: 1, 2, and 3)
Given the following inclusions and type definitions:
#include <stdlib.h>
#include <stdio.h>

struct node_int;
typedef struct node_int *node;

struct node_int
{
double height;
double weight;
node next;
};

struct group_int;
typedef struct group_int *group;

struct group_int
{
node first;
};

And the following function definition:
void f1(group g)
{
node c;

c = g->first->next;
while (c->next != NULL)
{
printf(“%lf\t%lf\n”, c->height, c->weight);
c = c->next;

}
}

a. What does the function f1() do?
[6 marks]
b. What possible situation(s) could cause the code to fail?
[6 marks]

Question 2. (Assessing ILOs: 1, 2, and 3)
A doubly-linked list may be defined as shown below on lines 4–20. The function declared
on lines 22–52 counts the distance from a given node back to the front of the list and
onwards to the back of the list. It returns ‘f’ if the given node is closer to the front of
the list and ‘b’ otherwise. There are, unfortunately, six lines in the program with
errors. Please identify the line number on which each error occurs and re-write the line
in your answer book in its corrected form. Do not rewrite lines that do not contain
errors.
#include <stdlib.h> 1
#include <stdio.h> 2
3
struct dnode_int; 4
typedef struct dnode_int *dnode; 5
6
struct dnode_int 7
{ 8
dnode prev; 9
void *data; 10
dnode next; 11
}; 12
13
struct list_int; 14
typedef struct list_int *list; 15
16
struct list_int 17
{ 18
dnode first; 19
}; 20
21
char closer_to(dnode h) 22
{ 23
dnode c; 24
int f, b; 25
26
f = 0; 27
b = 0; 28

29
h=c; 30
while (c = NULL) 31
{ 32
f–; 33
c = c->prev; 34
} 35
36
c = h; 37
while (c = NULL) 38
{ 39
b++; 40
c = c->prev; 41
} 42
43