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.submit command: submit labexam_qX (where X is the question number)..c file. Multi-file programs will not be accepted in submission.autotest labexam_qXsystem()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.
The starter files for this exam will be automatically placed in your home directory.
Programs (including your terminal and text editor) are available via the desktop menu
(accessible by right-clicking the desktop).
A copy of the course website has been made available. You can access this via the desktop menu also (accessible by right-clicking the desktop).
To test your code (for example, for question 1), run the command:
autotest labexam_q1
To submit your code (for example, for question 1), run the command:
submit labexam_q1 labexam_q1.c
The function count_alphabetical_pairs takes
in a one-dimensional array of characters, array,
with exactly size number of elements.
Your count_alphabetical_pairs function should
count the number of consecutive elements in the array that are in alphabetical
order. Character comparisons should be case-sensitive, meaning 'a'
and 'b' form an alphabetical pair while 'a' and
'B' do not.
If the array does not have sufficient size to test any elements (i.e. has a
size less than 2), your count_alphabetical_pairs
function should return -1.
For example, given the array:
{'z', 'a', 'b', 'e', 'c', 'f', 'g', 'h'}
The function should return 3, since:
Therefore, the array contains a total of 3 alphabetical pairs, from the pairs {'a', 'b'}, {'f', 'g'} and {'g', 'h'}.
For example, given the array:
{'l', 'M', 'N', 'o'}
The function should return 1, since:
Therefore, the array contains a total of 1 alphabetical pair, from the pair {'M', 'N'}.
For example, given the array:
{'m'}
The function should return -1, since the array has a size less than 2 and therefore cannot have a pair present.
labexam_q1.c also contains a simple
main function which allows you to test your
count_alphabetical_pairs function. This function will not be marked.
Your count_alphabetical_pairs function will be called directly in marking.
size will have a value between 1 and 100, inclusive.count_alphabetical_pairs function should return a single integer.count_alphabetical_pairs function should not modify the array.count_alphabetical_pairs function should not print anything (e.g., no printf).count_alphabetical_pairs function should not call scanf or perform any input.count_alphabetical_pairs function should return -1 if the array has a size less than 2.'a' and 'b' form an alphabetical pair while 'a' and 'B' do not.'z' followed by 'a' is not considered an alphabetical pair).array will only contain alphabetical characters, either lowercase ('a'-'z') or uppercase ('A'-'Z').1511 autotest-labexam labexam_q1
Your max_consec_row_diff function should look at every pair of adjacent rows in a given
2-dimensional array, and return the largest absolute difference between the sum of one row and the sum of the row directly below it.
max_consec_row_diff will be passed a two dimensional array with
num_rows rows andNUM_COLS (#define'd to 5) columns. For each pair of consecutive rows, work out the sum of each row, then take the absolute difference between those two sums. Compare every consecutive pair and return the maximum difference between any two adjacent rows. If the array has only one row, there is no pair of adjacent rows, so your function should return -1.
For example, if the 2D array contains these 25 elements, across 5 rows:
[3, 5, 1, 2, 0], [6, 1, 5, 4, 3], [1, 6, 2, 3, 7], [19, 0, 0, 0, 0], [0, 5, 1, 2, 3],
The absolute differences between the sums of each pair of adjacent rows are:
For example, if the 2D array contains these 5 elements, across 1 row:
[3, 5, 1, 2, 0]
Your function should return -1 as there is only 1 row so there are no consecutive pairs of rows to compare.
For example, with two rows:
[1, 1, 1, 1, 1], [2, 2, 2, 2, 2],The first row sums to 5 and the second to 10, so the only consecutive difference is |5 - 10| = 5, and your function should return 5.
labexam_q2.c also contains a simple main
function which allows you to test your max_consec_row_diff function.
Your max_consec_row_diff function will be called directly in marking.
The main function is only to let you test your max_consec_row_diff
function.
max_consec_row_diff should not change the array it is given.max_consec_row_diff should return a single integer.max_consec_row_diff should not call scanf (or getchar or fgets).max_consec_row_diff can assume the array always has at least 1 row and exactly 5 columns.max_consec_row_diff should not print anything. It should not call printf.1511 autotest-labexam labexam_q2
You have been provided with a file called labexam_q3.c.
The code in labexam_q3.c is meant to do the following:
Unfortunately, there are some problems with the provided program. Once fixed, your program should match the following examples exactly:
dcc labexam_q3.c -o labexam_q3 ./labexam_q3 Enter movie start hour: 20 Enter movie start minute: 15 Enter movie length in minutes: 90 Movie will finish at hour: 21, minute: 45. You can watch the movie! ./labexam_q3 Enter movie start hour: 21 Enter movie start minute: 30 Enter movie length in minutes: 45 Movie will finish at hour: 22, minute: 15. Movie finishes too late!
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 labexam_q3
You have been provided with a file called
labexam_q4.c.
The code in labexam_q4.c is meant to do
the following:
"Character not found in string.\n" to the
terminal.
Once fixed, your program should match the following example exactly:
dcc labexam_q4.c -o labexam_q4 ./labexam_q4 Enter a string: simple Enter a character to split the string: m Before: si After: ple ./labexam_q4 Enter a string: simple Enter a character to split the string: z Character not found in string. ./labexam_q4 Enter a string: AbcdaBCD Enter a character to split the string: a Before: Abcd After: BCD ./labexam_q4 Enter a string: abcdeabcde Enter a character to split the string: b Before: a After: cdeabcde ./labexam_q4 Enter a string: porcupine Enter a character to split the string: p Before: After: orcupine ./labexam_q4 Enter a string: porcupine Enter a character to split the string: e Before: porcupin After:
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 labexam_q4