This will also leave time for everyone to arrive and be ready to start the exam.
Log out of your regular account after completing the myExperience survey.
Your tutors will log your lab machine into the exam environment,
When all machines are logged into the exam environment tutors will give you further instructions.
At this stage turn off your phone, put it and laptops out of reach.
You will have 5 minutes reading time after that the exam runs 60 minutes.
Part 1 has to be submitted in the first 5 minutes and during that time you are not permitted to run xterms, shells, editors, etc. You can view online documentation.
You run "Enter Part 1 Answers" from the right mouse button menu to enter the answers to part 1.
In the final exam you will have 30 minutes to complete part 1.
You run "View Part 2 Questions" from the right mouse button menu to see part 2 questions.
Part 2 answers are entered into the file specified by each question and submitted using the "give" command. The questions include submission instructions.
The practice exam will be conducted under simulated exam conditions. which means you can't communicate with other people, can not use your phone/tablet/laptop, ...
You tutor can clarify questions and fix any problems with the exam environment.
They can not help you solve the tasks.
Some later lab sessions may have the same questions as yours. Please don't tell people what questions you had. And equally don't try to find out beforehand what questions were used in other labs. You'll get most value, if this practice exam is as real as possible.
This work you submit in the exam environment will be automarked and used to calculate your last lab mark.
You can not submit answers outside the exam environment.
You can only submit answers during the hour of the exam.
There should be time after the exam if you need help with assignment 3.
The file question.c contains this C Code:
#include <stdio.h> int main(void) { int x = 11; int y = 3; printf("%d\n", x / y); return 0; }
question.c is compiled with dcc on a CSE machine like this:
dcc question.c -o question
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./question
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
The file q2.c contains this C Code:
#include <stdio.h> int main(int argc, char *argv[]) { printf("%d\n", argc); return 0; }
q2.c is compiled with dcc on a CSE machine like this:
dcc q2.c -o q2
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q2 hello world
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
The file q3.c contains this C Code:
#include <stdio.h> #include <string.h> int main(void) { char *s = "hello"; char i = strlen(s); printf("%c%d\n", s[0], i); return 0; }
q3.c is compiled with dcc on a CSE machine like this:
dcc q3.c -o q3
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q3
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
The file question.c contains this C Code:
#include <stdio.h> int main(void) { int x = 11; int y = 3; printf("%d\n", x % y); return 0; }
question.c is compiled with dcc on a CSE machine like this:
dcc question.c -o question
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./question
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
The file q2.c contains this C Code:
#include <stdio.h> int main(int argc, char *argv[]) { printf("%s\n", argv[1]); return 0; }
q2.c is compiled with dcc on a CSE machine like this:
dcc q2.c -o q2
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q2 hello world
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
The file q3.c contains this C Code:
#include <stdio.h> #include <string.h> int main(void) { char *s = "hello"; printf("%d\n", strcmp(s, s)); return 0; }
q3.c is compiled with dcc on a CSE machine like this:
dcc q3.c -o q3
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q3
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
Write a C program product_odd.c
that reads 2 positive integers and calculates the product of the odd integers between the first and second integers.
For example, if the two integers entered are 10 and 16 then 2145 should be printed
because 11 * 13 * 15 = 2145
.
If there are no odd integers between the first and second integers, your program should print 1.
Your program should behave exactly like these examples:
dcc product_odd.c -o product_odd ./product_odd Enter lower: 10 Enter upper: 16 2145 ./product_odd Enter lower: 4 Enter upper: 8 35 ./product_odd Enter lower: 5 Enter upper: 7 1 ./product_odd Enter lower: 5 Enter upper: 9 7
You can assume the user supplies 2 positive integers.
You can assume the first integer is smaller than the second.
You can assume that the product will fit in an ''int''. In other words you can assume overflow does not occur.
You do not have do any error checking.
You do not have to check the return value from scanf.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest product_odd
give cs1511 wk13_product_odd product_odd.cYou must run give before Thursday 12 April 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
cp -n /web/cs1511/18s1/activities/array_count_odd/array_count_odd.c .Your task is to add code to this function:
// return the number of odd values in an array.
int count_odd(int length, int array[]) {
// PUT YOUR CODE HERE (you must change the next line!)
return 42;
}
Add code so that count_odd returns the number of odd values in the array.
For example if the array contains these 8 elements:
16, 7, 8, 12, 13, 19, 13, 12
Your function should return 4, because these 4 elements are odd:
7, 13, 19, 13
Your count_odd function will be called directly in marking. The main function is only to let you test your count_odd function
count_odd should return a single integer.
count_odd should not change the array it is given.
count_odd should not call scanf (or getchar or fgets).
count_odd can assume the array only contains positive integers.
count_odd can assume the array contains at least one integer.
count_odd function should not print anything. It should not call printf.
Your submitted file may contain a main function. It will not be tested or marked.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest array_count_odd
give cs1511 wk13_array_count_odd array_count_odd.cYou must run give before Friday 1 June 18:00:00 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
cp -n /web/cs1511/18s1/activities/array_count_small/array_count_small.c .Your task is to add code to this function:
// return the number of small values in an array.
int count_small(int length, int array[]) {
// PUT YOUR CODE HERE (you must change the next line!)
return 42;
}
Add code so that count_small returns the number of small values in the array.
For example if the array contains these 9 elements:
16, 7, 8, 12, 13, -9, -3, 12, -9
Your function should return 5, because these 5 elements are small:
7, 8, -9, -3, -9
Your count_small function will be called directly in marking. The main function is only to let you test your count_small function
count_small should return a single integer.
count_small should not change the array it is given.
count_small should not call scanf (or getchar or fgets).
count_small can assume the array contains at least one integer.
count_small function should not print anything. It should not call printf.
Your submitted file may contain a main function. It will not be tested or marked.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest array_count_small
give cs1511 wk13_array_count_small array_count_small.cYou must run give before Friday 1 June 18:00:00 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
You may assume that the program's input will contain only integers, in other words you can assume scanf succeeds.
You can assume a negative integer will always be read.
You can assume at most 1000 integers are read before a negative integer is read.
Match the the example below EXACTLY.
./odd_even_negative 1 2 3 2 -42 Odd numbers were: 1 3 Even numbers were: 2 2 ./odd_even_negative 1 2 4 16 32 64 128 256 512 1024 2048 4096 -8192 Odd numbers were: 1 Even numbers were: 2 4 16 32 64 128 256 512 1024 2048 4096Hint: use odd_even_ten.c as a starting point.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest odd_even_negative
give cs1511 wk13_odd_even_negative odd_even_negative.cYou must run give before Wednesday 18 April 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
It should then print the even integers on a single line, in the order they occurred.
Match the the example below EXACTLY.
dcc eof_even.c -o ./eof_even ./eof_even 1 4 1 5 6 2 6 9 4 6 6Explanation: given the input 1 4 1 5 6 2 6 9, your program should print 4 6 6, as those are the even values.
You can assume the input will only only contain positive integers, one per line.
You can assume each line will contain one and only one integer.
You can assume your input contains at least one integer.
You can assume your input contains no more than 10000 integers.
You can assume no integer will be smaller than 1.
You are free to write this program in any way you wish: there is no specific function that you need to implement. Note that your program will need to have a `main` function.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest eof_even
give cs1511 wk13_eof_even eof_even.cYou must run give before Friday 1 June 18:00:00 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
It should then print the number of times the last integer read occurred in in its input.
Match the the examples below EXACTLY.
dcc eof_count_last.c -o ./eof_count_last ./eof_count_last 1 4 1 5 6 2 6 1 3Explanation: given the input 1 4 1 5 6 2 6 1, your program should print 3, as the last number read was 1 and it occurred 3 times in its input.
./eof_count_last 10 20 30 40 1 ./eof_count_last 10 20 10 20 10 3 ./eof_count_last 42 42 42 42 42 42 42 7
You can assume the input will only only contain positive integers, one per line.
You can assume each line will contain one and only one integer.
You can assume your input contains at least one integer.
You can assume your input contains no more than 10000 integers.
You can assume no integer will be smaller than 1.
You are free to write this program in any way you wish: there is no specific function that you need to implement. Note that your program will need to have a `main` function.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest eof_count_last
give cs1511 wk13_eof_count_last eof_count_last.cYou must run give before Friday 1 June 18:00:00 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
cp -n /web/cs1511/18s1/activities/count_even_list/count_even_list.c .Note count_even_list.c uses the following familiar data type:
struct node { struct node *next; int data; };Your task is to add code to this function:
// return the number of even values in a linked list
int count_even(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
count_even is given one argument, head, which is the pointer to the first node in a linked list.
Add code to count_even so that its returns the number of even values in the linked list.
For example if the linked list contains these 8 elements:
16, 7, 8, 12, 13, 19, 21, 12
count_even should return 4, because these 4 elements are even:
16, 8, 12, 12
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your count_even function will be called directly in marking. The main function is only to let you test your count_even function
Here is how you use main function allows you to test count_even:
cp -n /web/cs1511/18s1/activities/count_even_list/count_even_list.c . dcc count_even_list.c -o count_even_list ./count_even_list 16 7 8 12 13 19 21 12 4 ./count_even_list 2 4 6 2 4 6 6 ./count_even_list 3 5 7 11 13 15 17 19 23 29 0 ./count_even_list 2 4 8 16 32 64 128 256 8 ./count_even_list 0
count_even should return a single integer.
count_even should not change the linked list it is given. Your function should not change the next or data fields of list nodes.
count_even should not use arrays.
count_even should not call malloc.
count_even should not call scanf (or getchar or fgets).
You can assume the linked list only contains positive integers.
count_even should not print anything. It should not call printf.
Do not change the supplied main function. It will not be tested or marked.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest count_even_list
give cs1511 wk13_count_even_list count_even_list.cYou must run give before Friday 25 May 23:59:59 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
cp -n /web/cs1511/18s1/activities/list_increasing/list_increasing.c .Your task is to add code to this function in list_increasing.c:
int increasing(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
increasing is given one argument, head, which is the pointer to the first node in a linked list.
Add code to increasing so that its returns 1 if the list is in increasing order - the value of each list element is larger than the element before.
For example if the linked list contains these 8 elements:
1, 7, 8, 9, 13, 19, 21, 42
increasing should return 1 because is is increasing order
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your list_increasing function will be called directly in marking. The main function is only to let you test your list_increasing function
Here is how you use main function allows you to test list_increasing:
dcc list_increasing.c -o list_increasing ./list_increasing 1 2 4 8 16 32 64 128 256 1 ./list_increasing 2 4 6 5 8 9 0 ./list_increasing 13 15 17 17 18 19 0 ./list_increasing 2 4 1 ./list_increasing 42 1 ./list_increasing 1
increasing should not change the linked list it is given. Your function should not change the next or data fields of list nodes.
increasing should not use arrays.
increasing should not call malloc.
increasing should not call scanf (or getchar or fgets).
You can assume the linked list only contains positive integers.
increasing should not print anything. It should not call printf.
Do not change the supplied main function. It will not be tested or marked.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest list_increasing
give cs1511 wk13_list_increasing list_increasing.cYou must run give before Friday 1 June 18:00:00 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.
cp -n /web/cs1511/18s1/activities/list_second_last/list_second_last.c .Note list_second_last.c uses the following familiar data type:
struct node { struct node *next; int data; };Your task is to add code to this function:
int second_last(struct node *head) {
// PUT YOUR CODE HERE (change the next line!)
return 42;
}
second_last is given one argument, head, which is the pointer to the first node in a linked list.
Add code to second_last so that its returns the second last element of the list.
For example if the linked list contains these 8 elements:
1, 7, 8, 9, 13, 19, 21, 42
second_last should return 21 because this is the second last element.
second_last can assume the list has at least two elements.
This main function:
Do not change this main function. If you want to change it, you have misread the question.
Your list_second_last function will be called directly in marking. The main function is only to let you test your list_second_last function
Here is how you use main function allows you to test list_second_last:
cp -n /web/cs1511/18s1/activities/list_second_last/list_second_last.c . dcc list_second_last.c -o list_second_last ./list_second_last 1 2 4 8 16 32 64 128 256 128 ./list_second_last 2 4 6 5 8 9 8 ./list_second_last 13 15 17 17 18 19 18 ./list_second_last 2 4 2
second_last should return a single integer.
second_last should not change the linked list it is given. Your function should not change the next or data fields of list nodes.
second_last should not use arrays.
second_last should not call malloc.
second_last should not call scanf (or getchar or fgets).
You can assume the linked list only contains positive integers.
second_last should not print anything. It should not call printf.
Do not change the supplied main function. It will not be tested or marked.
When you think your program is working you can use autotest
to run some simple automated tests:
1511 autotest list_second_last
give cs1511 wk13_list_second_last list_second_last.cYou must run give before Friday 1 June 18:00:00 to obtain the marks for this lab exercise. Note, this is an individual exercise, the work you submit with give must be entirely your own.