Week 07 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 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.


weekly test question:
Printing Lines Reversed

Write a C program reverse_lines.c which reads lines and writes them out with the characters of each line in reverse order. It should stop when it reaches the end of input.

For example:

dcc -o reverse_lines reverse_lines.c
./reverse_lines
Two roads diverged in a yellow wood,
,doow wolley a ni degrevid sdaor owT
And sorry I could not travel both
htob levart ton dluoc I yrros dnA
And be one traveler, long I stood
doots I gnol ,relevart eno eb dnA
To where it bent in the undergrowth;
;htworgrednu eht ni tneb ti erehw oT
You don't make friends with salad.
.dalas htiw sdneirf ekam t'nod uoY


You can assume lines will contain at most 256 characters.

You can assume lines are terminated with a newline ('\n') character,

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest reverse_lines
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test07_reverse_lines reverse_lines.c

weekly test question:
Filtering Out Repeated Lines

Write a C program remove_repeated_lines.c which reads lines and prints them unless it has seen exactly the same line previously.

In other words it doesn't print repeated lines. It prints our only the first occurrence of any line.

It should stop when it reaches the end of input.

For example:

dcc -o remove_repeated_lines remove_repeated_lines.c
./remove_repeated_lines
one
one
hello world
hello world
two
two
one
hello world
two
hello
hello

./remove_repeated_lines
Na, na, na, na, na
Na, na, na, na, na
Na, na, na
Na, na, na
Na, na, na, na, na
Na, na, na
Do, do, do, do, do,
Do, do, do, do, do,
Do, do, do
Do, do, do
Do, do, do, do, do,
Do, do, do


You can assume lines will contain at most 256 characters.

You assume at most 256 lines will be read before end-of-input.

You can assume lines are terminated with a newline ('\n') character,

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest remove_repeated_lines
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test07_remove_repeated_lines remove_repeated_lines.c

Submission

When you are finished each exercise make sure you submit your work by running give.

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 Week 8 Thursday 17: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:

1511 classrun -sturec

The test exercises for each week are worth in total 1 marks.

The best 7 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 7.