COMP1511 18s1 Test Conditions Week 10

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 Thursday 17 May 23:59:59
  • 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 then must 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 COMP1511 course materials except for language documentation linked 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.

Line Character

Write a C program line_char.c which reads a line from its input then reads an integer n from its input.It should write the character in position n from the line in the format given in the examples below.

Your program should then exit – it should not read more lines.

For example:

dcc -o line_char line_char.c
./line_char
abcdefghijklmnopqrstuvwxyz
0
The character in position 0 is 'a'
./line_char
abcdefghijklmnopqrstuvwxyz
13
The character in position 13 is 'n'
./line_char
abcdefghijklmnopqrstuvwxyz
25
The character in position 25 is 'z'
./line_char
Andrew Rocks!
6
The character in position 6 is ' '
./line_char
Andrew Rocks!
7
The character in position 7 is 'R'
./line_char
Andrew Rocks!
12
The character in position 12 is '!'

No error checking is necessary.You can assume a line can be read.

You can assume the line will contain at mnost 256 characters.

You can assume a positive integer n can be read.

You can assume the line read has at least n characters.

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

1511 autotest line_char

Autotest Results

98% of 761 students who have autotested line_char.c so far, passed all autotest tests.

  • 98% passed test 0
  • 98% passed test 1
  • 98% passed test 2
  • 98% passed test 3
  • 98% passed test 4

When you are finished working on this exercise you must submit your work by running give:

give cs1511 test10_line_char line_char.c

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

Autotest Results

86% of 735 students who have autotested reverse_lines.c so far, passed all autotest tests.

  • 92% passed test 0
  • 92% passed test 1
  • 87% passed test 2
  • 86% passed test 3

When you are finished working on this exercise you must submit your work by running give:

give cs1511 test10_reverse_lines reverse_lines.c

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 occurance 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

Autotest Results

86% of 503 students who have autotested remove_repeated_lines.c so far, passed all autotest tests.

  • 90% passed test 0
  • 87% passed test 1
  • 87% passed test 2
  • 87% passed test 3
  • 87% passed test 4

When you are finished working on this exercise you must submit your work by running give:

give cs1511 test10_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 Thursday 17 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

Ask for help

 

发表评论

%d 博主赞过: