# Designing Homework 1

• Homework 1 statement.
• This is a little strange because
• The problem statement is fairly decomposed.
• There are examples of the decomposition in the previous notes.
• Let's start at the top.
• Other designs are possible.
• Will this work? Is it correct?
• Can you implement this?
• Is this Cohesive?
• Is this concrete or abstract?
• Are any of the steps concrete?
• I believe that every step here is abstract and should be turned into a new sub-procedure and eventually a function.
• One part of functional decomposition is how information is transferred
• What information needs to be sent from one module/function to another?
• In general, noting needs to be sent into main from the outside.
• But main may need to send/receive information from sub functions.
• Consider Ask if they want to encrypt a message.
• I dislike that name, can we think of something better.
• What does this procedure/function/sub-program do?
• What Does it need any information from the main routine?
• What is that information?
• Should it return any information to the main routine?
• What is that information?
• Can you come up with an algorithm for GetContinue?
• Others are possible.
• All the questions above
• Does it work and is it cohesive?
• Is it concrete or abstract?
• Can you implement it?
• In this case, I think I want at least one further function, something to turn a string into lower case.
• I would repeat this process with every function in the main routine.

ToLower:
Input: a string
Output: A string where all alphabetic characters are in lower case

for each letter in the string
convert that letter to lower case.

GetShiftAmount
Input: no input from main
Output: returns an integer between 0 and 26 to main
Assumes no errors on input.

Prompt for number
Convert the number to the proper range.
Return the number

Convert a number to the proper range.
Input: an integer
Output: an integer between 0 and 25

While the number is less than 0
return the number % 26

GetPlainText
Input: none
Output: A string

Prompt the user for the message
Return this line

Encode
Input: a string, the message
an int, the shift amount
Output:
The encrypted message;

for each letter in the string
encrypt that letter
return the encrypted string.

Encrypt Letter
Input: a character and a shift amount.
Output: the encrypted character.

If the letter is alphabetic
Note if the letter is upper case
Convert the letter to lower case
Shift the letter by the shift amount.
if the original was upper case
convert the shifted letter to upper case
else
shifted letter = original letter
return the shifted letter

Shift a letter
Input: a lower case character
a shift amount
Output: a shifted letter

find the position by subtracting 'a'
new position = position +   shift amount
convert the new position to the range 0-25
return 'a'+new position

• This is not the only design possible.
• But it is a working design.
• We will implement this next.