COMP(1511|1911) 26T3 Lab Exam

Time allowed: 1 hours and 5 minutes (5 minutes reading time, 1 hours working time)

Total number of questions: 4

Total number of marks: 34

Questions are NOT worth the same amount of marks

The distribution of marks is as follows:

Attempt all questions

You should keep this paper confidential. Sharing it, DURING or AFTER the exam is prohibited.


Paper Information

Exam Condition Summary

Deliberate violation of these exam conditions will be referred to Student Integrity Unit as serious misconduct, which may result in penalties up to and including a mark of 0 in COMP(1511|1911) and exclusion from UNSW.

Exam Hurdle Requirement

COMP1911 Assessment Students

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.

COMP1511 Assessment Students

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.

Exam Environment

Language Restriction

Fit to Sit

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.

Technical Issues

If you experience a technical issue, you should raise your hand and wait for an invigilator to assist.

Questions

Question 1
(●◌◌◌)
:

This question is of similar style to the first array hurdle question in the final exam.
(12 marks)
You can fetch the starter code for this question here or by running 1511 fetch-labexam labexam_q1

The function sum_between_negatives takes in a one-dimensional array of integers, array, with exactly size number of elements.

Your sum_between_negatives function should find the first negative number and the last negative number in the array, and return the sum of all values between them.

The first and last negative numbers should not be included in the sum.

Examples

For example, given the array:

{3, -2, 4, 5, -1, 6, -3, 8}

The function should return 14, since:

  • The first negative number is -2.
  • The last negative number is -3.
  • The values between them are 4, 5, -1 and 6.
  • The sum of these values is 4 + 5 + -1 + 6 = 14.

For example, given the array:

{1, 2, -3, 4, 5}

The function should return 0, as there is only one negative number in the array.

For example, given the array:

{-4, -7, 3, 2}

The function should return 0, as there are no values between the first negative number and the last negative number.

Testing

labexam_q1.c also contains a simple main function which allows you to test your sum_between_negatives function. This function will not be marked.

Your sum_between_negatives function will be called directly in marking.

Assumptions/Restrictions/Clarifications

  • The parameter size will have a value between 1 and 100, inclusive.
  • Your sum_between_negatives function should return a single integer.
  • Your sum_between_negatives function should not modify the array.
  • Your sum_between_negatives function should not print anything (e.g., no printf).
  • Your sum_between_negatives function should not call scanf or perform any input.
  • Your sum_between_negatives function should return 0 if there are fewer than two negative numbers in the array.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-labexam labexam_q1

Question 2
(●●◌◌)
:

This question is of similar style to the second array hurdle question in the final exam.
(12 marks)
You can fetch the starter code for this question here or by running 1511 fetch-labexam labexam_q2

first_balanced_row, given a two-dimensional array of characters, should return the index of the first row which has an equal count of vowels and consonants. If no rows are balanced, the function should return -1.

first_balanced_row will be passed a two-dimensional array with:

  • num_rows rows, and
  • NUM_COLS (#define'd to 6) columns.

Examples

For example, if the 2D array contains these rows:

{'a', 'b', 'e', 'f', 'i', 'j'},
{'a', 'e', 'i', 'o', 'u', 'a'},
{'b', 'c', 'd', 'f', 'g', 'h'}

Your function should return 0 because the first row contains:

  • 3 vowels: 'a', 'e', and 'i'
  • 3 consonants: 'b', 'f', and 'j'

For example, if the 2D array contains these rows:

{'a', 'e', 'i', 'o', 'u', 'a'},
{'b', 'c', 'd', 'f', 'g', 'h'}

Your function should return -1 because neither row contains an equal number of vowels and consonants.

For example, if the 2D array contains these rows:

{'a', 'e', 'i', 'o', 'u', 'a'},
{'a', 'b', 'c', 'd', 'e', 'i'},
{'b', 'c', 'd', 'f', 'g', 'h'}

Your function should return 1 because the second row is the first row with an equal number of vowels and consonants.

Testing

The supplied file contains a sample main function that you can use to test first_balanced_row. During marking, first_balanced_row will be called directly; the sample main function will not be tested or marked.

Assumptions/Restrictions/Clarifications

  • You may assume that the array will only include lowercase letters. It will not contain uppercase letters or special characters.
  • The vowels are the lowercase letters 'a', 'e', 'i', 'o' and 'u'.
  • first_balanced_row should return a single integer (the row index).
  • first_balanced_row should not change the array it is given.
  • first_balanced_row should not call scanf (or getchar or fgets).
  • first_balanced_row can assume the array will always contain at least one row.
  • first_balanced_row should not print anything. It should not call printf.
  • Do not change the supplied sample main function. It is provided only for testing and will not be marked.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-labexam labexam_q2

Question 3
(●◌◌◌)
:

This question is of a similar style to a debugging question in the final exam.
(5 marks)
You can fetch the starter code for this question here or by running 1511 fetch-labexam labexam_q3

You have been provided with a file called labexam_q3.c.

The code in labexam_q3.c is meant to do the following:

  • Scan in the leaving time in hours and minutes in the form HH MM (two separate integers).
  • Scan in 3 days with their wake up time (in hours and minutes) and getting ready time (in minutes) into an array of type struct day.
  • Determine which days were late. A day is late if the wake up time plus getting ready time is later than the leaving time.
  • Print the total count of late days.

Unfortunately, there are some problems with the provided program. Once fixed, your program should match the following examples exactly:

Examples

dcc labexam_q3.c -o labexam_q3
./labexam_q3
Enter leaving time: 09 00
Enter wake up time and time it took to get ready for 3 days:
Day 1
Enter wake up time: 07 30
Enter how long it took to get ready (minutes): 63
Day 2
Enter wake up time: 08 01
Enter how long it took to get ready (minutes): 59
Day 3
Enter wake up time: 07 54
Enter how long it took to get ready (minutes): 80
Checking if you were late...
You were late for 1 day(s).
./labexam_q3
Enter leaving time: 09 00
Enter wake up time and time it took to get ready for 3 days:
Day 1
Enter wake up time: 07 30
Enter how long it took to get ready (minutes): 20
Day 2
Enter wake up time: 07 45
Enter how long it took to get ready (minutes): 25
Day 3
Enter wake up time: 08 06
Enter how long it took to get ready (minutes): 25
Checking if you were late...
Great! You were not late!
./labexam_q3
Enter leaving time: 15 34
Enter wake up time and time it took to get ready for 3 days:
Day 1
Enter wake up time: 11 11
Enter how long it took to get ready (minutes): 273
Day 2
Enter wake up time: 14 00
Enter how long it took to get ready (minutes): 95
Day 3
Enter wake up time: 17 12
Enter how long it took to get ready (minutes): 3
Checking if you were late...
Late every day!

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.

Assumptions/Restrictions/Clarifications.

  • You may assume that all getting ready times entered will be a non-negative integer.
  • Wake up and leaving time is given in HH MM format (two separate integers) and converted to minutes since midnight. All times are in 24-hour format.
  • You may assume that all wake up and leaving times are valid 24-hour times.
  • A day is considered late if the wake up time plus getting ready time is later than the leaving time.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-labexam labexam_q3

Question 4
(●◌◌◌)
:

This question is of a similar style to a debugging question in the final exam.
(5 marks)
You can fetch the starter code for this question here or by running 1511 fetch-labexam labexam_q4

You have been provided with a file called labexam_q4.c.

The code in labexam_q4.c is meant to do the following:

  • Scan in a string.
  • Replace each uppercase letter in the string with the total count of uppercase letters in the string, up to and including the current character.
  • Print the resulting string to the terminal.
  • If the string does not contain uppercase letters, the string should be printed unchanged.

Testing

Once fixed, your program should match the following examples exactly:

dcc labexam_q4.c -o labexam_q4

./labexam_q4
Enter a string: Hello World
Result: 1ello 2orld
There are 2 capital letters in the string.

./labexam_q4
Enter a string: smALL
Result: sm123
There are 3 capital letters in the string.

./labexam_q4
Enter a string: Hi
Result: 1i
There are 1 capital letters in the string.

./labexam_q4
Enter a string: all lowercase
Result: all lowercase
There are 0 capital letters in the string.

./labexam_q4
Enter a string: UPPERCASE
Result: 123456789
There are 9 capital letters in the string.

./labexam_q4
Enter a string: AlTeRnAtInG lEtTeRs
Result: 1l2e3n4t5n6 l7t8e9s
There are 9 capital letters in the string.

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.

Assumptions/Restrictions/Clarifications

  • The input string will always contain at least 1 character.
  • The input string will never include more than 9 uppercase letters.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-labexam labexam_q4