EECS2031 Assignment 2: C Programming solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

In this assignment, you will be writing four C programs. The first program (triangle.c) draws triangle patterns of a given number of rows. The second program (caesar.c) implements a Caesar cipher, used to encrypt text messages. The third program (anagram.c) is a tool that tests whether two words are anagrams. The fourth program (rw.c) is a tool for generating a random walk across a 2D array.
Important Notes:
 You must use the submit command to electronically submit your solution by the due date.  All programs are to be written using C and compiled by gcc.  Your programs should be tested on the EECS labs before being submitted. Failure to test your programs on EECS labs will result in a mark of 0 being assigned.  To get full marks, your code must be well-documented.
What To Submit
When you have completed the assignment, move or copy your four C programs in a directory (e.g., assignment2), and use the following command to electronically submit your files within that directory:
% submit 2031M a2 triangle.c caesar.c anagram.c rw.c
You can also submit the files individually after you complete each part of the assignment– simply execute the submit command and give the filename that you wish to submit. You may submit your solutions as many times as you wish prior to the submission deadline. Make sure you name your files exactly as stated (including lower/upper case letters). Failure to do so will result in a mark of 0 being assigned. You may check the status of your submission using the command:
% submit -l 2031M a2

A. Triangle Patterns (25%)
Write a C program “triangle.c” that uses the “*” character to draw a triangle of a given number of rows. The program first prompts the user to enter the number of rows in the triangle. Your program may assume that the input is a valid integer from 1 to 20 (inclusive). Here are some sample outputs from the execution of the program. The output of your program should match the sample output.
$ ./triangle Enter the number of rows in the triangle: 1 *
$ ./triangle Enter the number of rows in the triangle: 2 * ***
$ ./triangle Enter the number of rows in the triangle: 3 * * * *****
$ ./triangle Enter the number of rows in the triangle: 10 * * * * * * * * * * * * * * * * * *******************
Example run
Hint: You may find it helpful to draw the required output on a piece of graph paper before writing your program.

B. Caesar’s Cipher (25%)
Write a C program “caesar.c” that encrypts a message using one of the oldest known encryption techniques, called Caesar cipher, attributed to Julius Caesar. It involves replacing each letter in a message with another letter that is a fixed number of positions later in the alphabet (shift). If the replacement would go past the letter Z, the cipher “wraps around” to the beginning of the alphabet. For example, if each letter is replaced by the letter two positions after it (shift by 2), then A would be replaced by C, Y would be replaced by A, and Z would be replaced by B. The user will enter the message to be encrypted and the shift amount as a valid integer from 1 to 25 (inclusive). Here’s an example of the desired output:
$ ./caesar Enter message to be encrypted: Hello World Enter shift amount (1-25): 3 Encrypted message: Khoor Zruog
$ ./caesar Enter message to be encrypted: Khoor Zruog Enter shift amount (1-25): 23 Encrypted message: Hello World
Example run
Notice that the program can also be used to decrypt a message if the user knows the original key by providing the encrypted message and using as shift amount 26 minus the original key (see example). You may assume that:
 The message does not exceed 80 characters.  Characters other than letters should be left unchanged.  Lower-case letters remain lower-case and upper-case letters remain upper-case.
Hint: You may wish to use operations on characters to handle the “wrap around” problem and to calculate the encrypted version of a lower-case or upper-case letter.

C. Anagrams (25%)
Write a C program “anagram.c” that tests whether two words are anagrams (permutations of the same letters). Your program should ignore any characters that aren’t letters and should treat upper-case letters as lower-case letters. You may wish to use functions from