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:
This exam contains example array hurdle questions only . Example linked list hurdle questions will be in the Week 10 Prac Exam.
submit
command: submit exam_qX
(where X
is the question number)..c
file. Multi-file programs will not be accepted in submission.autotest exam_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-labexam exam_q1
In this task, you will write a program that is given an array with exactly size
number of elements. unique_sum should return the sum of the unique integers in that array.
For every unique value in the array, your program should add it to the sum of unique values. If there are no unique values in the array, your program should return 0.
If the array contains these elements:
{1, 2, 3, 4, 5, 6, 7}
Your function should return 28 because each integer in that array is unique.
In another example, if the array contains these elements:
{2, 4, 2, 2}
Your function should return 4, as there is only one unique integer in the array.
exam_q1.c
also contains a simple
main
function which allows you to test your
unique_sum
function.
Your unique_sum
function will be called directly in marking.
The main function is only to let you test your
unique_sum
function.
unique_sum
should not modify the array it is provided.unique_sum
should not call scanf
(or getchar
or fgets
).
unique_sum
should not print anything, i.e. It should
not call printf
.
1511 autotest-labexam exam_q1
1511 fetch-labexam exam_q2
Your magic_square
function should compute the sum of each row, column and both diagonals in a given 2D array.
If all rows, columns and diagonals sum to the same number, then the array is a magic square, and you will return this sum.
magic_square
will be passed size
and a square two dimensional array with:
size
rows andsize
columns.
Add code so that the magic_square
function compares the sum of each column, row, and each
set of the diagonals to see if they are equal. Your magic_square
should return the sum you have found if the two dimensional
array is a magic square, and 0 if it is not.
For example, if the 2D array contains these 25 elements, across 5 rows:
{1, 1, 2, 2, 1}, {1, 0, 0, 0, 6}, {1, 6, 0, 0, 7}, {13, 0, 1, 1, 0}, {5, 5, 1, 2, 2},
This is not a magic square and your function should return 0.
For example, if the 2D array contains these 25 elements, across 5 rows:
{17, 24, 1, 8, 15}, {23, 5, 7, 14, 16}, { 4, 6, 13, 20, 22}, {10, 12, 19, 21, 3}, {11, 18, 25, 2, 9}
This is a magic square, as each row, column and diagonal sum to 65, and your function should return 65.
exam_q2.c
also contains a simple main
function which allows you to test your magic_square
function.
Your magic_square
function will be called directly in marking.
The main function is only to let you test your magic_square
function.
magic_square
should return a single integer.magic_square
should not change the array it is given.magic_square
should not call scanf
(or getchar
or fgets
).magic_square
can assume the array should always be a square.magic_square
should not print anything. It should not call printf.1511 autotest-labexam exam_q2
1511 fetch-labexam exam_q3
You have been provided with a file called exam_q3.c
.
The code in exam_q3.c
is meant to do the following:
This program should scan in a budget price, 3 grocery items and their costs into a struct array, and determine which individual items are over budget.
Unfortunately, there are some problems with the provided program. Once fixed, your program should match the following examples exactly:
dcc exam_q3.c -o exam_q3 ./exam_q3 Enter a budget: 6 Enter 3 grocery items and their costs: Apples 3.60 Bananas 4.50 Strawberries 7.20 Over budget items: Strawberries ./exam_q3 Enter a budget: 10 Enter 3 grocery items and their costs: Carrots 3.40 Lettuce 5.75 Tomato 2.80 Great work! All your items are within budget!
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-labexam exam_q3
1511 fetch-labexam exam_q4
You have been provided with a file called exam_q4.c
.
The code in exam_q4.c
is meant to do the following:
Once fixed, your program should match the following example exactly:
dcc exam_q4.c -o exam_q4 ./exam_q4 Enter a string: abcd Enter a position to remove: 1 Result: bcd ./exam_q4 Enter a string: abcd Enter a position to remove: 2 Result: acd ./exam_q4 Enter a string: abcd Enter a position to remove: 3 Result: abd ./exam_q4 Enter a string: abcd Enter a position to remove: 4 Result: abc ./exam_q4 Enter a string: The quick brown fox jumped over the lazy dog. Enter a position to remove: 4 Result: Thequick brown fox jumped over the lazy dog.
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-labexam exam_q4