SOLUTION_3

# SOLUTION_3 - CS 31 Introduction to Computer Science I...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 31: Introduction to Computer Science I: Winter 2010: Project 3 Solution Page 1 // UCLA Winter 2010 // CS 31 Project 3 // John A. Rohr // February 4, 2010 // // // String Encoder // // This program generates coded output strings from uncoded input strings. // // The program use a single key character in the coding algorithm to alter the // string characters. A numeric checksum is attached to the end of each message. // // For simplicity, the key character is prepended as the first character of // both the original message string and the coded message string. // // The program reads input strings and generates and output strings until // an empty line of is input. // // The following algorithm is used to encode each string of text where the // first character of the string is the key character. // // Input: A key character followed by the characters of a string to be encoded. // // Output: The key character, the characters of the encoded message, and a // four-decimal-digit checksum that is the sum modulo 10000 of the // output encoded characters. (The key character is not included // in the checksum.) // // Algorithm: (Used separately on each character) // // 1. Get a character. // // 2. If the character code is zero or greater than 126, terminate // encoding, generate the checksum, and append it to the output. // // 3. If the character code is in the range 1 through 32, output a // caret (^) followed by a second character. Initially, the code // for the second character is the code of the input character plus // the code of the key character. If the resulting code value is // greater than 126, then 32 is added modulo 126 to the initial // value of the code for the second character. // // 4. If the code is anything else, generate the output character(s) // as follows: // 1. Subtract 33 from the character. // 2. Add the code of the key character, modulo 94. // 3. Reflect that value in the range 0 through 93. // 4. Add 33. // 5. Use the result as the output character code. // 6. If the resulting code is the code for the caret character (^), // also output the key character after the generated character....
View Full Document

## This note was uploaded on 03/08/2010 for the course COM SCI 31 taught by Professor Kinsey during the Spring '98 term at UCLA.

### Page1 / 9

SOLUTION_3 - CS 31 Introduction to Computer Science I...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online