COMP1511 18s1 (webcms)
COMP1511 18s1 (flask)

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:
Any violation of the test conditions will results in a mark of zero for the entire weekly test component.

Filtering Out the Digits

Write a C program digit_filter.c which reads characters from its input and writes character to its output.

Digits ('0' .. '9'), spaces and newline characters should be written unchanged.

All other characters should be replaced with a '.' character.

Your program should stop only at the end of input.

For example:

dcc -o digit_filter digit_filter.c
./digit_filter
This is week 9 of COMP1511.
.... .. .... 9 .. ....1511.
I paid $10.50 for 3 cups of coffee
. .... .10.50 ... 3 .... .. ......
i is the symbol for the square root of -1
. .. ... ...... ... ... ...... .... .. .1
0123456789abcdef
0123456789......

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

1511 autotest digit_filter

Autotest Results

97% of 832 students who have autotested digit_filter.c so far, passed all autotest tests.
  • 98% passed test 0
  • 98% passed test 1
  • 98% passed test 2
  • 97% passed test 3
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test09_digit_filter digit_filter.c

Replacing the Digits

Write a C program map_digits.c which reads characters from its input and writes the characters to its output with digit ('0' .. ''9) characters replaced by specified characters.

The mapping for digits will be given to your program as a single command line argument.

This command line argument will contain 10 characters. These are the characters the corresponding digit should be replaced with. For example, '0's should be replaced with the first character of the command line argument, '1' with the second character of the command line argument and so on.

Characters other than digits should not be changed.

Your program should stop only at the end of input.

For example:

dcc -o map_digits map_digits,c
./map_digits ABCDEFGHIJ
0123456789
ABCDEFGHIJ
Andrew rocks!
Andrew rocks!
6 * 7 = 42
G * H = EC
This is week 9 of COMP1511
This is week J of COMPBFBB

./map_digits andrewrock
two 4 eight 16 thirtytwo 64
two e eight nr thirtytwo re

./map_digits zyzuvtsrqp
1 2 4 8 16 32 64 128 256
y z v q ys uz sv yzq zts

You can assume that your program is given exactly one command line argument and it contains exactly 10 characters.

No error checking is necessary.

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

1511 autotest map_digits

Autotest Results

95% of 779 students who have autotested map_digits.c so far, passed all autotest tests.
  • 96% passed test 0
  • 95% passed test 1
  • 95% passed test 2
  • 95% passed test 3
  • 95% passed test 4
  • 95% passed test 5
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test09_map_digits map_digits.c

Counting Lines, Words, Characters

Write a C program word_count.c which reads characters from its input until the end of input and then prints a count of the characters, words and lines it read.

Assume the only non-word characters are space and newline.

All other characters should be considered word characters.

A word is defined as a maximal non-empty sequence of word characters.

Multiple spaces or newline characters may separate words.

Match the output format below exactly:

dcc -o word_count word_count,c
./word_count
The quick brown fox jumped over the lazy dog.

1 lines 9 words 46 characters
./word_count
only
    three
        words

3 lines 3 words 29 characters
./word_count
Are you saying 'Boo' or 'Boo-Urns'?

1 lines 6 words 36 characters
./word_count
 In this house,
we obey the laws of thermodynamics!

2 lines 9 words 52 characters
./word_count
Simpson, Homer Simpson
He's the greatest guy in history
 From the
  Town of Springfield
  He's about to hit a chestnut tree.

5 lines 21 words 125 characters

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

1511 autotest word_count

Autotest Results

70% of 732 students who have autotested word_count.c so far, passed all autotest tests.
  • 87% passed test 0
  • 85% passed test 1
  • 78% passed test 2
  • 85% passed test 3
  • 75% passed test 4
  • 88% passed test 5
  • 78% passed test 6
  • 80% passed test 7
  • 79% passed test 8
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test09_word_count word_count.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 Wednesday 9 May 23:59:59 to complete this test.

Automarking will be run several days after the submission deadline for the test. When complete you can view automarking here and you can view the the resulting mark via give's web interface