COMP1511 Week 7 Practice Exam
September 2017
Time allowed: 1 Hour
Total number of questions: 3
Total number of marks: 10
Questions are not worth equal marks
Answer all questions
Answer each question in a SEPARATE file. Each question specifies the
name of the file to use. These are named after the corresponding
question number, i.e. Question 1 is in a file called q1.c
Make sure you use EXACTLY this file name.
Submit these files using the submit
command as described in each
question. You may submit your answers as many times as you like. The
last submission ONLY will be marked.
If you have only a partial solution and the exam is about to end, submit it anyway.
The exam environment allows you to run a limited set of commands so you can test and debug your answers.
The exam environment logs all your actions.
The exam environment does not allow access to files in your CSE account or any other CSE account. It does not allow access to the web or other network access
A C reference sheet is available on-line. Manual entries are also available. No other documents or files will be available to you.
Question 1 (2.5 marks)
Count Favourite
Write a C function which counts the number of values in the array that are multiples of my favourite number: seventeen.
Place your answer to this question in a file named q1.c
Your function should take two parameters: the length of the array, and the array. It must have this prototype:
Your function should return a single integer: the number of values in the array that are multiples of seventeen.
For example if the array contains these 8 elements:
Your function should return 2
, because these 2 elements are
multiples of seventeen:
Assumptions
You can assume the array contains only positive integers.
Your function should not print anything.
Your submitted file must only contain one function: countFavourite
.
Your submitted file must not contain a main function. The autotest
script will supply its own main function to test your countFavourite
function.
If you do write a main function to do your own testing, make sure you
comment it out or delete it before running autotest
or submitting
your file.
Testing and Submission
You can test your program using the autotest
command: Make sure you
also do your own testing, as your code will be run through more tests
after the exam.
If you compile a program without a main function dcc will give you an error. You can use the -c flag to stop this error message, e.g.:
Once you are satisfied with your solution, submit it by running
Question 2 (3.5 marks)
Contains Uppercase
Write a C function that determines whether a string contains uppercase letters. Your function should return TRUE if the string contains uppercase letters, and FALSE if it does not.
Place your answer to this question in a file named q2.c
Your function should take one parameter: the string to check. It must have this prototype:
Your function should return either TRUE or FALSE, depending on whether the string contains uppercase letters.
For example, if the input string was: Your function should return TRUE, as the string contained an uppercase letter: ‘H’.
Assumptions
Your function should not print anything.
Your submitted file must only contain one function:
containsUppercase
.
Your submitted file must not contain a main function. The autotest
script will supply its own main function to test your
containsUppercase
function.
If you do write a main function to do your own testing, make sure you
comment it out or delete it before running autotest
, or submitting
your file.
Testing and Submission
You can test your program using the autotest
command:
Make sure you also do your own testing, as your code will be run through more tests after the exam.
If you compile a program without a main function dcc will give you an error. You can use the -c flag to stop this error message, e.g.:
Once you are satisfied with your solution, submit it by running
Question 3 (4 marks)
Find Duplicate
Write a C function that finds the duplicate value in array, if one exists.
The array will either contain no duplicate values, or a single value in the array will be duplicated, i.e will occur more than once.
Place your answer to this question in a file named q3.c
Your function should take two parameters: the length of source array, and the source array itself. It must have this prototype:
Your function should return a single integer: the value in the array that occurs more than once. if one exists. If there are no values that occur more than once, your function should return NO_DUPLICATE.
For example, if the source
array contained the following 6 elements:
Your function should return the integer 1
, as this is the element
that occurred more than once.
For example, if the source
array contained the following 6 elements:
Your function should return the integer 1
, as this is the element
that occurred more than once.
As another example, if the source
array contained the following 6
elements:
Your function should return NO_DUPLICATE, as none of the elements in the array occurred more than once.
Assumptions
You can assume the array only contains positive integers.
You cannot assume anything about the number of duplicates, i.e. there may not be any duplicates, or conversely, the entire array may be duplicates.
Your function should not print anything.
Your submitted file must only contain one function: findDuplicate
.
Your submitted file must not contain a main function. The autotest
script will supply its own main function to test your findDuplicate
function.
If you do write a main function to do your own testing, make sure you
comment it out or delete it before running autotest
, or submitting
your file.
Testing and Submission
You can test your program using the autotest
command:
Make sure you also do your own testing, as your code will be run through more tests after the exam.
If you compile a program without a main function dcc will give you an error. You can use the -c flag to stop this error message, e.g.:
Once you are satisfied with your solution, submit it by running