Homework 1, Let's Write Some Functions.
Short Description:
Write an interactive caesar cipher program. You must use functions.
Goals
When you finish this homework, you should have:
- Have a basic idea of how to work with functions.
- Have written a C++ program using functions.
Formal Description
We will work on this program jointly in class. I expect you to use the code that we develop in class when working on this program.
Implement a generic Caesar Cipher
The Caesar Cipher is a substitution cipher named after Julius Caesar. By default, to encode each letter is shifted by 3: ie A -> D, B->E and so forth. At the end of the alphabet X->A, Y->B and Z->C. This represents a shift of 3 ('A'+3 = 'D'). Decryption is done by subtracting 3. For more detail as well as a history of this cipher see Wikipedia.
In the modern area, rot13 is an equivalent cipher where 13, rather than 3 is added for encryption and subtracted for decryption.
For this program, we will write a version which the user may specify any value for the shift.
Specifically, the program should work as follows.
- Ask the user if they wish to encrypt a message. The answer should be yes or no.
- Prompt with "Do you wish to encrypt a message (yes/no)? "
- Read in the entire line of the response.
- Print a newline after you read in the line.
- Convert the input line to all lower case. (Yes, YeS and YES are all ok answers).
- Check the prompt
- For an answer of no, exit the program.
- For an answer of yes, continue.
- For all other answers ask again.
- If the user wishes to encrypt a message
- ask for the shift amount.
- Prompt the user with "Enter the shift amount => "
- Read in the integer, no error checking required.
- Do a cin.ignore to ignore the rest of the line.
- Return the equivelent of the nubmer between 0 and 25.
- Ask for the message, all on one line.
- Prompt with "Enter the message to encrypt on one line: "
- Read in the entire line of the response.
- Print a newline after the response.
- Encrypt the message as follows:
- Any alphabetic character should be shifted by the given amount.
- Upper/lower case should be preserved.
- Any non-alphabetic character should be preserved.
- Print out the encrypted message.
- Print the encrypted message on a line ending with a newline.
- Print a blank line (newline only)
- Return to step 1.
Notes on Makefile
Make is a utilitiy that builds an executable. It allows programmers to easly rebuild a project involving many files. We will be breaking our programs into multiple files this semester so we will learn to use make.
The key to make is a configuration file for each project called Makefile. No extensions, capatal M. This file contains the rules for building the executable.
For this project use this Makefile.
- Download the file to your directory.
- Call your source code caesar.cpp
- Compile with
make
Please note, makefiles are tricky, it is better if you download this file rather than try to retype it. A tab is required at the beginning of the last line.
Notes
- You must use functions.
- You must use the provided makefile.
- Your program MUST compile with the flags supplied in the makefile without errors or warnings on cslab103.
Required Files
A single tar file containing the source code and makefile for this program.
Submission
Submit the assignment to the D2L folder Homework 1 by the due date.