Some simple algorithms
- I'm probably going to use some math examples here.
- Write an algorithm to change temperature from Fahrenheit to Celsius and back.
- The input should be the current temperature and the current unit.
- The output should be the temperature in the desired unit.
- $c = \frac{5}{9}(f-32)$
- $f = \frac{9}{5}c + 32$.
- Try this 130 assignment.
- Can we write an algorithm to convert a bit string "10110101" to a decimal number?
- If we use an idea like
-
for each bit in the number from first to last
- we are using a counter controlled loop
- We know how many times we will execute the loop
- Let's write an algorithm for a program that will encode a message using the Caesar cipher.
- Let's extend this algorithm to one that will encode multiple messages.
- We should ask each time if they want to encode a message.
- We should ask for the shift amount.
- We should ask for the message.
- We should print the message.
- Another homework assignment.
- When we do a loop like
-
While the user wants to encode a message
- We are using an event controlled loop.
- We continue to loop until something happens.