The distribution of marks is as follows:
You should keep this paper confidential. Sharing it, DURING or AFTER the exam is prohibited.
man
pages) during the exam.The course has ONE hurdle in the final exam that you must meet to pass the course:
Please note, you are NOT required to pass the Linked list hurdle to pass COMP1911.
The course has TWO hurdles in the final exam that you must meet to pass the course:
submit
command: submit prac_qX
(where X
is the question number)..c
file. Multi-file programs will not be accepted in submission.autotest prac_qX
system()
By sitting or submitting an assessment on the scheduled assessment date, a student is declaring that they are fit to do so and cannot later apply for Special Consideration.
If, during an exam you feel unwell to the point that you cannot continue with the exam, you should raise you hand and inform an invigilator, who will provide advice as to the best course of action.
If you experience a technical issue, you should raise your hand and wait for an invigilator to assist.
1511 fetch-prac prac_q1
Note prac_q1.c uses the following familiar data type:
struct node { struct node *next; int data; };
The function first_prime
takes one argument, head
, where head
is a pointer to the first node of a linked list.
The function should return the first prime number in the list, if there is one. If there are no prime numbers in the list, the function should return -1.
A prime number is a whole number that is only exactly divisible (leaving no remainder) by 1 and the number itself.
For example, suppose the linked list contains the following values:
4 -> 11 -> 7 -> 9 -> XThe function
first_prime
should return the value 11 in the linked list, which is the first prime number in the list.
For example, suppose the linked list contains the following values:
4 -> 4 -> 4 -> XThe function
first_prime
should return the value -1, as there are no prime numbers in the list.
prac_q1.c
also contains a main
function which allows you to test your first_prime
function.
This main function:
head
,
first_prime(head)
,
Do not change this main function. If you want to change it, you have misread the question.
Your first_prime
function will be called directly in marking. The main function is only to let you test your first_prime
function
Here is how the main function allows you to test first_prime
:
dcc prac_q1.c -o prac_q1 ./prac_q1 10 4 15 17 17 ./prac_q1 5 64 15 99 25 5 ./prac_q1 1 9 -1 ./prac_q1 16 -1 ./prac_q1 2 3 5 2
first_prime
should return -1 if the list is empty.first_prime
should return only a single integer.first_prime
should not change the linked list it is given.first_prime
should not change the next or data fields of list nodes.first_prime
should not use arrays.first_prime
should not call malloc.first_prime
should not call scanf (or getchar or fgets).first_prime
should not print anything. It should not call printf.first_prime
does not need need to consider integer overflow in its calculations.main
function. It will not be tested or marked.1511 autotest-prac prac_q1
1511 fetch-prac prac_q2
min_lowercase
will be passed in a character array with exactly
size
columns. Add code so that the
min_lowercase
function returns the lowercase letter with the lowest
ASCII value.
If the array contains these elements:
{'c', 'A', 'e', 'P', '!'}
Your function should return the character 'c' because it is lowercase and has the lowest ASCII value compared to all other characters in the array.
For example if the array contains these elements:
{'O', '@', 'g'}
Your function should return the character 'g' because it is lowercase and has the lowest ASCII value compared to all other characters in the array.
Your min_lowercase
function will be called directly in marking.
The main function is only to let you test your
min_lowercase
function.
min_lowercase
should not modify the array it is provided.
min_lowercase
should not call scanf (or getchar or fgets).
min_lowercase
should not print anything, i.e. It should
not call printf
.
1511 autotest-prac prac_q2
1511 fetch-prac prac_q3
Note prac_q3.c
uses the following familiar data type:
struct node { struct node *next; int data; };
delete_nth_even is given two arguments, head
and
n
. head
is a pointer to the first node in a linked
list, and n
is the position of the node from the start of the list, that you need to delete,
counting only even data values.
Add code to delete_nth_even so that it deletes the n
th node in the list that contains an even number,
counting only the nodes with even values from the start of the list.
n > length
where length is the number of nodes in the
list or n
is greater than the number of even nodes in the
list, the first even node in the list should be deleted.
For example, if the original list was: 4, 3, 7, 2, 35, 4, 3
and
n
was 2
The final list should be: 4, 3, 7, 35, 4, 3
2
was removed because 2
was the
second even node from the start of the list.
delete_nth_even
should return a pointer to the head of the list.
delete_nth_even
should free the node it deletes.
prac_q3.c
also contains a main
function
which allows you to test your delete_nth_even
function.
This main function:
head
,
delete_nth_even(head, n)
,Do not change this main function. If you want to change it, you have misread the question.
Your delete_nth_even
function will be called directly in marking. The main
function is only to let you test your delete_nth_even
function.
dcc prac_q3.c -o prac_q3 ./prac_q3 2 4 3 7 2 35 4 3 [4, 3, 7, 35, 4, 3] ./prac_q3 1 2 3 4 [3, 4] ./prac_q3 9 1 2 3 4 5 6 [1, 3, 4, 5, 6] ./prac_q3 5 10 20 30 40 50 [10, 20, 30, 40] ./prac_q3 3 10 20 30 40 50 [10, 20, 40, 50] ./prac_q3 1 1 [1] ./prac_q3 11 1 3 5 7 9 [1]
n
.
n
will always be 1 or greater.
n >= length
where length is the number of nodes in the list or n
is greater than the number of even nodes in the list, the first even node in the list should be deleted.
delete_nth_even
should not delete any nodes and leave the list unchanged.
delete_nth_even
should return the (possibly changed) head of the list.
delete_nth_even
should call free to free the memory for the node
it deletes.
delete_nth_even
should not change the data fields of list nodes.delete_nth_even
should not use arrays.
delete_nth_even
should not call malloc.
delete_nth_even
should not call scanf
(or getchar
or fgets
).
delete_nth_even
should not print anything. It should not call printf.
struct node
.
main
function. It will not be tested or
marked.
If you get this autotest message:
Error: free not called for memory allocated with malloc in ...
You have not freed a node you have deleted.
1511 autotest-prac prac_q3
1511 fetch-prac prac_q4
vowels_exactly_balanced
will be passed an array of strings, with
exactly size
strings. Each row contains a string terminated by the
null terminator ('\0'
) character. Write the
vowels_exactly_balanced
function which returns 1 if each string
contains exactly the same number of vowels, or 0 if they do not.
If the array contains these elements:
{'a', 'a', 'a', 'a', '\0'}, {'c', 'o', 'm', 'p', '\0'}, {'o', 'o', 'o', 'h', '\0'}, {'y', 'a', 'y', 'a', '\0'},
Your function should return false (0), since each string does not have the same number of vowels.
For example if the array contains these elements:
{'a', 'b', 'c', '\0'}, {'!', 'e', '\0'}, {'a', 'c', '\0'},
Your function should return true (1), since each string contains 1 vowel.
For example if the array contains these elements:
{'f', 'g', 'h', '\0'}, {'j', '\0'}, {'z', 'x', 'c', 'v', 'b', 'n', 'm', '\0'},
Your function should return true (1), since each string contains 0 vowels.
prac_q4.c
also contains a simple
main
function which allows you to test your
vowels_exactly_balanced
function.
Your vowels_exactly_balanced
function will be called directly in
marking. The main function is only to let you test your
vowels_exactly_balanced
function.
vowels_exactly_balanced
can assume there will be at least one
string
vowels_exactly_balanced
will always have a null
terminator character at the final position
vowels_exactly_balanced
contains at most 100
characters
vowels_exactly_balanced
should not print anything. It should
not call printf.
1511 autotest-prac prac_q4
1511 fetch-prac prac_q5
prac_q5.c
is meant to do the following:
Once fixed, your program should match the following example exactly:
dcc prac_q5.c -o prac_q5 ./prac_q5 Enter the month number (1-12): 0 Invalid month entered. ./prac_q5 Enter the month number (1-12): 12 It's summer in Australia. ./prac_q5 Enter the month number (1-12): 5 It's autumn in Australia.
There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, adding lines, or removing lines. Submit your working version of the code.
1511 autotest-prac prac_q5
1511 fetch-prac prac_q6
extract_evens
is given one arguments:
head
: a pointer to the first node of a linked list.
extract_evens
should create a new list containing only the nodes with even values from the input list.
The relative order of the even values in the new list must match the order **in which** they appeared in the original list.
For example, if the list contains the following values:
After calling extract_evens(head)
, the list evens
should contain:
The file prac_q6.c
contains a main
function that allows you to test your implementation.
This main function:
extract_evens(head)
.Do not change this main function. It does not contain any bugs.
dcc prac_q6.c -o prac_q6 ./prac_q6 3 2 5 8 6 7 2 8 6 ./prac_q6 1 3 5 No even nodes ./prac_q6 0 -2 -10 -8 0 -2 -10 -8 ./prac_q6 No even nodes
struct node
.main
function.extract_evens
must not read from input or print to output.1511 autotest-prac prac_q6
1511 fetch-prac prac_q7
You have been provided with a file called prac_q7.c
.
The code in prac_q7.c
is meant to do the following:
n
, as input from the user.find_sum_of_square()
to calculate the sum of
squares from 1 to n
.
result
pointer variable.
dcc prac_q7.c -o prac_q7 ./prac_q7 Enter n: 4 The sum of squares from 1 to 4 is: 30 ./prac_q7 Enter n: 1 The sum of squares from 1 to 1 is: 1 ./prac_q7 Enter n: 6 The sum of squares from 1 to 6 is: 91
There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, adding lines, or removing lines. Submit your working version of the code.
find_sum_of_square
function should not print anything.
1511 autotest-prac prac_q7
1511 fetch-prac prac_q8
prac_q8.c
is meant to do the following:
This program should create and scan in the elements of a 3x3 2d array, then multiply all the odd numbers in the 2d array by 100.
However, it has some issues that you need to fix.Once fixed, your program should match the following example exactly:
dcc prac_q8.c -o prac_q8 ./prac_q8 Enter your numbers: 1 2 3 4 5 6 7 8 9 Converted: 100 2 300 4 500 6 700 8 900 ./prac_q8 Enter your numbers: 1 2 3 1 2 3 1 2 3 Converted: 100 2 300 100 2 300 100 2 300 ./prac_q8 Enter your numbers: 1 1 1 2 2 2 3 3 3 Converted: 100 100 100 2 2 2 300 300 300
There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, moving lines, or removing lines. Submit your working version of the code.
1511 autotest-prac prac_q8
1511 fetch-prac prac_q9
Write a C program prac_q9.c
which reads a single line of input (a string).
The program should then modify the string according to the following rules and print the modified string.
b
is greater than a
).z
or Z
(depending on their starting case). For example, yZzz
becomes zZzz
since y
can only increment once before hitting the limit.For example:
dcc prac_q9.c -o prac_q9 ./prac_q9 Original String: aBc New String: cCc ./prac_q9 Original String: zyx New String: zyx ./prac_q9 Original String: ProgrammingFUNdamentals New String: UussupssqqnMUPjgpiptcms
\n
).a-z
and A-Z
.main
function.1511 autotest-prac prac_q9
1511 fetch-prac prac_q10
You have the goal of determining the minimum number of trains needed to travel from a source train stop to a target train stop.
In this task, you will be given input through the command line consisting of:
n
- the number of train routes.
n
train routes, where each route i
consists of:
mi
- the number of stops on route i
.
mi
integers representing the stops on that route.
src
- the source train stop.
dest
- the destination train stop.
Once the minimum number of trains is determined, the program should print
The minimum number of trains to travel from stop [src] to stop [dest] is [min_num_stops].
If there is no route from src
to dest
, the program should print
Stop [dest] from stop [src] is not reachable.
For example, if the command-line arguments provided were:
2 3 1 2 7 3 3 6 7 1 6
You would interpret this as:
n
= 2m1
number of stops = 3m1
route = 1, 2, 7m2
number of stops = 3m2
route = 3, 6, 7src
= 1dest
= 6The minimum number of trains to travel from stop 1 to stop 6 is 2.
In another example, if the command line arguments provided were:
3 3 1 2 3 3 3 4 5 2 6 7 1 7
You would interpret this as:
n
= 3m1
number of stops = 3m1
route = 1, 2, 3m2
number of stops = 3m2
route = 3, 4, 5m3
number of stops = 2m3
route = 6, 7src
= 1dest
= 7Stop 7 from stop 1 is not reachable.
as there is no route from stop 1 to stop 7.
dcc prac_q10.c --leak-check -o prac_q10 ./prac_q10 3 3 1 2 3 3 3 4 5 2 6 7 1 7 Stop 7 from stop 1 is not reachable. ./prac_q10 3 2 1 2 2 2 2 3 2 3 4 1 4 The minimum number of trains to travel from stop 1 to stop 4 is 2. ./prac_q10 2 3 1 2 3 3 3 4 5 1 8 Stop 8 from stop 1 is not reachable.
--leak-check
with no memory leaks.
m1
m2
m3
... mi
m1
and so on.
1511 autotest-prac prac_q10
1511 fetch-prac prac_q11
Given the coordinates and heights of all the mountains, your task is to determine the skyline formed by these mountains, which is the outline formed when all the mountains are viewed together from a distance.
The information of each mountain is provided as command line arguments in the
format:
left1 right1 height1 left2
right2 height2 ...
lefti
is the x-coordinate of the left edge of the
ith mountain.
righti
is the x-coordinate of the right edge of the
ith mountain.
heighti
is the height, or y-coordinate, of the
ith mountain.
The skyline should be represented as a collection of "key point" pairs
comprising of x and y-coordinates, sorted by their x-coordinate. Your program
should print these points in the format
[[x1, y1], [x2, y2], ...]
. Here, each key point pair is the left endpoint of some horizontal segment
in the skyline,
except for the last key point pair, which always has a y-coordinate of 0.
This last point is used to mark the end of the skyline, corresponding to where
the rightmost mountain ends.
The ground between the leftmost and rightmost mountains should also be included as part of the skyline's outline.
For example if you were provided the following input
2 9 10 3 7 15 5 12 12 15 20 10 19 24 8
You would interpret this as:
Meaning that
Therefore, the final key points are:
[[2, 10], [3, 15], [7, 12], [12, 0], [15, 10], [20, 8], [24, 0]]
dcc prac_q11.c --leak-check -o prac_q11 ./prac_q11 2 9 10 3 7 15 5 12 12 15 20 10 19 24 8 Skyline: [[2, 10], [3, 15], [7, 12], [12, 0], [15, 10], [20, 8], [24, 0]] ./prac_q11 1 2 1 2 3 2 3 4 3 4 5 4 Skyline: [[1, 1], [2, 2], [3, 3], [4, 4], [5, 0]] ./prac_q11 0 2 3 2 5 3 Skyline: [[0, 3], [5, 0]]
You may find the following interactive helpful for visualising skylines:
lefti
is the
same as righti
--leak-check
with no memory leaks.
1511 autotest-prac prac_q11