CS 1MD3 T2 2003
Bonus Assignment #1
- Due: Monday January 20, before class, by email
- Write a readable C program that
- Takes an integer N on the command line
- Outputs a file rotN.c where the N should be the input
integer
- The program contained in rotN.c should:
- Take as input any ASCII file on stdin
- Rotate any alphabetic character by N positions (see
definition of 'rotate' below, and leave every other
character intact.
- Output the results on stdout
- Further details:
- The integer N should be a signed 32 bit integer
- The C file, not counting comments, should be at most
50 lines long
- The output C file should also be at most 50 lines long
- The C file(s) will be formatted using standard formatting
rules (by the instructor if need be) before counting lines
- Using 1 (very) long line for a string containing the
(inner) C program is not acceptable - that makes the program
unreadable.
- To rotate (a very weak means of encryption) means
to replace every character by the one N positions to the
right. In other words, to rotate by 1 position means
'a' goes to 'b', 'b' goes to 'c', ..., 'w' to 'z' and
finally 'z' to 'a'. Same for upper-case letters.
- Rotating by a negative number means to go left instead
of right.
- Rotating by 0 (or a multiple of 26) should be equivalent
to a no-op
- Deliverables:
- This assignment is worth
up to5 bonus points.
- Writing this assignment, under the same conditions, in the
languages Ocaml or
Haskell is worth
up to10 bonus points.
- Writing this assignment, under the same conditions,
except for a line limit of 70, in the
languages Ocaml or
Haskell, and the
output program also one of the above, is worth
up to12 bonus points.
Discussion :
If your program is called bonus1 then to run it (where > is
the command line prompt)
> bonus1 5
would produce a file called rot5.c. When compiled like
> gcc -o rot5 rot5.c
this produces a program executable rot5 (or rot5.exe on Windows).
Assuming one has an ascii file foo, one could run
> rot5 < foo > foo.out
to get a rotated output. A good test:
> bonus1 -5
> gcc -o rot-5 rot-5.c
> rot5 < bonus1.html | rot-5 > bb.html
> diff bonus1.html bb.html
should produce no output (ie that last 'diff' command should
produce no output), where bonus1.html is the name of this HTML file
you are currently reading.
Back to main page