Week 08 Weekly Test Questions
Test Conditions
These questions must be completed under self-administered exam-like conditions. You must time the test yourself and ensure you comply with the conditions below.
- You may complete this test in CSE labs or elsewhere using your own machine.
- You may complete this test at any time before Wednesday 01 January 00:00.
- The maximum time allowed for this test is 1 hour + 5 minutes reading time.
- You may first use 5 minutes to read the questions (no typing).
- You must then complete the test within 1 hour and submit your answers with give.
- You must complete the questions alone: you can not get help in any way from any person.
- You can not access your previous answers to lab or tut questions.
- You can not access web pages or use the internet in any way.
- You can not access books, notes or other written or online materials.
- You can not access your own files, programs, code ...
- You can not access COMP1521 course materials, except for language documentation linked below.
You may access this language documentation while attempting this test:
You may also access manual entries (the man
command).
Any violation of the test conditions will results in a mark of zero for the entire weekly test component.
Set up for the test by creating a new directory called
test08
, changing to this directory, and fetching the
provided code by running these commands:
mkdir test08 cd test08 1521 fetch test08
Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.
You should not write any code. Test in Progress — working time You have just over minutes left in the test. Test Complete! Your time for this test has finished. You may submit your work. You may choose to keep working, but you should not submit further work. You should reflect on how you went in this hour, and discuss with your tutor if you have concerns.
weekly test question:
Check a File for non-ASCII Bytes
We need to check whether files contain non-ASCII bytes.
Write a C program, non_ascii.c
, which takes one
argument, a filename.
It should print one line of output.
If the file contains a non-ASCII byte,
non_ascii.c
should print the location of the first
non-ASCII byte. Use the same format as the example below.
If the file contains no non-ASCII byte
non_ascii.c
should print a message indicating this.
Again use the same format as the example below.
Assume a byte is non-ASCII if it contains a value between 128..255 inclusive.
dcc non_ascii.c -o non_ascii echo hello world >file1 ./non_ascii file1 file1 is all ASCII echo -e 'hello\xBAworld' >file2 ./non_ascii file2 file2: byte 5 is non-ASCII ./non_ascii non_ascii.c non_ascii.c is all ASCII echo -e '\x80\x81' >file3 file2: byte 0 is non-ASCII
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest non_asciiWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test08_non_ascii non_ascii.c
weekly test question:
Compare the Bytes of Two Files
We need to check whether 2 files contain identical bytes
Write a C program, compare_file.c
, which takes two
arguments, both filenames.
compare_file.c
should print one line of output.
If the two files are different compare_file.c
should
print the location of the first byte whether they differ. Use the
same format as the example below.
If the one file is shorter than the other but the bytes it
contains are identical to the other file,
compare_file.c
should print a message indicating
this. Use the same format as the example below.
If the 2 files contain exactly the same bytes
compare_file.c
should print a message indicating
this. Again use the same format as the example below.
dcc compare_file.c -o compare_file echo hello world >file1 echo hello world >file2 ./compare_file file1 file2 Files are identical echo -n hello >file3 ./compare_file file1 file3 EOF on file3 echo help me >file4 ./compare_file file1 file4 Files differ at byte 3
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest compare_fileWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test08_compare_file compare_file.c
weekly test question:
Delete non-ASCII characters from a file
We need to remove the non-ASCII bytes from files.
Write a C program, leave_only_ascii.c
, which takes
one argument, a filename.
leave_only_ascii.c
should remove all non-ASCII bytes
from the file.
After it is run the file should contain only a ASCII bytes.
It should print nothing on stdout. It should only change the file.
Assume a byte is non-ASCII if it contains a value between 128..255 inclusive.
dcc leave_only_ascii.c -o leave_only_ascii echo -e 'hello\xBAworld' >file2 ls -l file2 -rw-r--r-- 1 z5555555 z5555555 12 Nov 8 08:18 file2 ./non_ascii file2 file2: byte 5 is non-ASCII ./leave_only_ascii file2 ls -l file2 -rw-r--r-- 1 z5555555 z5555555 11 Nov 8 08:18 file2 ./non_ascii file2 file2 is all ASCII
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest leave_only_asciiWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test08_leave_only_ascii leave_only_ascii.c
Submission
You can run give multiple times. Only your last submission will be marked.
Don't submit any exercises you haven't attempted.
If you are working at home, you may find it more convenient to upload your work via give's web interface.
Remember you have until Wednesday 01 January 00:00 to complete this test.
Automarking will be run by the lecturer several days after the
submission deadline for the test, using test cases that you haven't
seen: different to the test cases
autotest
runs for you.
(Hint: do your own testing as well as running
autotest
)
Test Marks
After automarking is run by the lecturer you can view it here the resulting mark will also be available via via give's web interface or by running this command on a CSE machine:
1521 classrun -sturec
The test exercises for each week are worth in total 1 marks.
The best 6 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 9.