Assignment 2: Learn to C
Due Friday, January 30, before midnight
The goals for this assignment are:
-
Work with strings
-
Work with structs
-
Work with arrays
1. Update your repository
Do a git pull to obtain the basecode for this assignment.
Your repository should now contain a new folder named A02.
2. Bad password
Write a program, password.c, that asks the user for a word and creates a bad password from it.
You can assume that all characters are lowercase.
$ make password
gcc password.c -o password
$ ./password
Enter a word: elephant
Your bad password is 313ph@nt
$ ./password
Enter a word: hello
Your bad password is h311o
$ ./password
Enter a word: rhythm
Your bad password is rhythm
Your bad password algorithm should
-
Replace 'e’s with '3’s
-
Replace 'l’s with '1’s
-
Replace 'a’s with '@'s
3. Shift Cypher
Write a program, cypher.c, that asks the user for a word and then encodes it
using a shift cypher. A shift cypher replaces each letter with a letter that is
X positions from it in the alphabet. For example, is the letter is 'a' and the
shift is 2, we replace 'a' with a 'c'. You can assume that all inputs are
lowercase and do not contain special characters.
$ make cypher
gcc cypher.c -o cypher
$ ./cypher
Enter a word: elephant
Enter a shift: 2
Your cypher is gngrjcpv
$ ./cypher
Enter a word: gngrjcpv
Enter a shift: -2
Your cypher is elephant
$ ./cypher
Enter a word: hello
Enter a shift: 7
Your cypher is olssv
$ ./cypher
Enter a word: a
Enter a shift: -2
Your cypher is y
$ ./cypher
Enter a word: z
Enter a shift: 2**
Your cypher is b
Hints:
-
Recall that characters as represented as digits in ASCII. A straight-forward implementation can add offsets to each character of the word.
4. Submit your Work
Push you work to Github to submit your work.
$ cd A02
$ git add *.c
$ git commit -m "assignment 2 complete"
$ git push
5. Grading Rubric
Assignment rubrics
Grades are out of 4 points.
-
(2 point) password
-
(0.1 points) style and header comment
-
(0.4 points) correct behavior: asks the user for input and creates the new string
-
(0.5 points) no memory errors
-
-
(2 point) cypher
-
(0.1 points) style and header comment
-
(0.4 points) correct behavior: asks the user for input and creates the new string
-
(0.5 points) no memory errors
-
Code rubrics
For full credit, your C programs must be feature-complete, robust (e.g. run without memory errors or crashing) and have good style.
-
Some credit lost for missing features or bugs, depending on severity of error
-
-12.5% for style errors. See the class coding style here.
-
-50% for memory errors
-
-100% for failure to checkin work to Github
-
-100% for failure to compile on linux using make