Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Global Variable, Arrays and user Defined Functions are NOT ALLOWED. Thank you! Project 7 Description ) Using command line arguments for an input file and
Global Variable, Arrays and user Defined Functions are NOT ALLOWED. Thank you!
Project 7 Description ) Using command line arguments for an input file and output file name (see command line argument slides and page 3), print out the command line input file name (see the sample solution for the output to use) and open the input file provided. Verify that the file opened successfully (fle stream is valid). If it di d not open successfully, enter a while loop that outputs an error message, resets the input file stream being opened and prompts the user to enter another input file name. This file name is read, echo printed and opened. The loop continues until the input file is successfully opened. (same procedure as used in project 6). Be sure to test for correct number of arguments as the first action in main (2) If the input file is successfully opened, print out the command line output file name and open the output le provided. Verify that the output file opened successfully. If it did not open successfully, enter a while loop that outputs an error message, resets the output file stream being opened and prompts the use enter anoth er output file name. This file name is read, echo printed and opened. The loop continues until the output file is successfully opened. Use the filename Bad/file" to cause the open function to fail for the output file (3) The input file contains multiple lines the first line contains a single character E or D for encode or decode. After reading this character test the status of the file stream to see if the end-of-file has been reached. If it has, then the input file is empty. Print out an ermpty file message to the terminal only and temminate the program. If a character was successfully read, verify that it is E or D. If it is any other character, output an error message to the terminal and terminate the program (4) The next line in the file contains an integer offset value between 0 and 25 inclusive. There are two possible errors to check for after this read. The first error is if the input file does not contain an offset value or any other data after the E or D that was read from the first line. For this case output the appropriate error message to the terminal and terminate the program. The second error is if the offset present, but it is not an integer. In this case output the appropriate error message to the terminal and teminate the program. (5) After successfully reading the offset, the rest of the file is read character by character. For each character read, it is either (E)nooded or (Djecoded according to the following rules a. If the character read from the file is a letter(upper or lower case), it is changed based on the offset value read. For (E)ncoding the offset is added to the integer value of the character. For D)ecoding the offset is subtracted from the integer value of the character. A new letter is obtained from this value and written to the output file. See page 4 for more information on the character conversion. If the character read from the input fie is not a letter, then it is written to the output file as is (no modification by the offset) b. (6) Continue to read all characters from the input file until the end of the fle is reached which en program Project 7 Letter Encoding and Decodinge For this project letters will be encoded or decoded by using the Cesar Cipher algorthm. This algorithm adds an offset to a letter for encoding and subtracts an offset for decoding. If the offset value is 1, then for encoding. A B. B4C ..29A. It the offset value s 1, then for de coding, Az,A, C+8 29Y Note that the letters wrap around whien you reach either end of the alphabet To perform the encoding or decoding of letters, a lew functions from the cctype header file are needed These functions are isalpha(char), is lower(char) and isupper(char) (char here represents a character variable that must be used as the argument in the function call). All three of the se functions return a boolean value of talse if the character passed in is not a letter, not lower case or not upper case respectively. Likewise, these functions reurn a Boolean value of true if the char acter passed in is a letter, a lower case letter or an upper case letter respectively. These functions can be used to determine what is to be done with the character being tested. For characters that are leters, a simple algorithm is used to modily the letter to its new value. The algorithm has to be wrtten twice once for upper case leters and once for lower case letters a character read is a letter, the procedure for a lower case leter is as follo 1) Convert the character to an integer value between 0 and 25-0 representing 'a and 25 representing 2' (same can be done with upper case leters) To do this conversion, use intVar charRead-a: (you can use whatever variable names you want. intVar is an integer variable and charRead is a character variable) 2) For encoding the offset is added to intVar. For decoding the oftset is subtracted from intVar 3) This new integer value must then be converted to a number between 0 and 25 inclusive. For example if the offset is 2 and the letter to encode is then you have invar # 25+ 2-27. This value of 27 must be converted to a number that will represent the leter that z with an offset ot 2 Page 3 of 4 Spring 2019 CPE211 Project Assignment Project 7 should be converted to. in this case, the number to convert to is 1there are 2 ways to get this value) which will represent b 4) Once th e number has been obtained in step 3, it must be converted back to the corect integer value for the letter it is to represent. That is easily done by taking newCharvar 'a intVar Just add the integer value calculated which must be between 0 and 25) to the integer value represenang 5) Same procedure is done for encoding upper case letters except A is used instead of 'a 6) For decoding the offset is subr acted from intVar which can result in a negative number. For t hey need to be oonveted back to positive values that represent the end of negative numbers the alphabet (the 2 end not the a end) For example if the offset is 2 and the leter to decode is a, then we have intVarF02 2 This value of +2 must be converted to a number that to with an offset of 2. In this case that value is 24 which r represents the leter a decoded represents the leter y: Once the corrected integer value is obtained it is used to obtain the newCharVar as described in step 4 7) Encoding and decoding examples: using an ofset of S A FixC, Y->D, ZE Encoding: Encoding: Abcdefghyldmnopqrstuwvxyz Fghlinnopqrstuvwxyzabcde ABCDEFG HlJKLMNOPQRSTUvwxyz vwXYZABCDEFGHlJKLMNOPQRstu a. d. Decoding Project 7 Description ) Using command line arguments for an input file and output file name (see command line argument slides and page 3), print out the command line input file name (see the sample solution for the output to use) and open the input file provided. Verify that the file opened successfully (fle stream is valid). If it di d not open successfully, enter a while loop that outputs an error message, resets the input file stream being opened and prompts the user to enter another input file name. This file name is read, echo printed and opened. The loop continues until the input file is successfully opened. (same procedure as used in project 6). Be sure to test for correct number of arguments as the first action in main (2) If the input file is successfully opened, print out the command line output file name and open the output le provided. Verify that the output file opened successfully. If it did not open successfully, enter a while loop that outputs an error message, resets the output file stream being opened and prompts the use enter anoth er output file name. This file name is read, echo printed and opened. The loop continues until the output file is successfully opened. Use the filename Bad/file" to cause the open function to fail for the output file (3) The input file contains multiple lines the first line contains a single character E or D for encode or decode. After reading this character test the status of the file stream to see if the end-of-file has been reached. If it has, then the input file is empty. Print out an ermpty file message to the terminal only and temminate the program. If a character was successfully read, verify that it is E or D. If it is any other character, output an error message to the terminal and terminate the program (4) The next line in the file contains an integer offset value between 0 and 25 inclusive. There are two possible errors to check for after this read. The first error is if the input file does not contain an offset value or any other data after the E or D that was read from the first line. For this case output the appropriate error message to the terminal and terminate the program. The second error is if the offset present, but it is not an integer. In this case output the appropriate error message to the terminal and teminate the program. (5) After successfully reading the offset, the rest of the file is read character by character. For each character read, it is either (E)nooded or (Djecoded according to the following rules a. If the character read from the file is a letter(upper or lower case), it is changed based on the offset value read. For (E)ncoding the offset is added to the integer value of the character. For D)ecoding the offset is subtracted from the integer value of the character. A new letter is obtained from this value and written to the output file. See page 4 for more information on the character conversion. If the character read from the input fie is not a letter, then it is written to the output file as is (no modification by the offset) b. (6) Continue to read all characters from the input file until the end of the fle is reached which en program Project 7 Letter Encoding and Decodinge For this project letters will be encoded or decoded by using the Cesar Cipher algorthm. This algorithm adds an offset to a letter for encoding and subtracts an offset for decoding. If the offset value is 1, then for encoding. A B. B4C ..29A. It the offset value s 1, then for de coding, Az,A, C+8 29Y Note that the letters wrap around whien you reach either end of the alphabet To perform the encoding or decoding of letters, a lew functions from the cctype header file are needed These functions are isalpha(char), is lower(char) and isupper(char) (char here represents a character variable that must be used as the argument in the function call). All three of the se functions return a boolean value of talse if the character passed in is not a letter, not lower case or not upper case respectively. Likewise, these functions reurn a Boolean value of true if the char acter passed in is a letter, a lower case letter or an upper case letter respectively. These functions can be used to determine what is to be done with the character being tested. For characters that are leters, a simple algorithm is used to modily the letter to its new value. The algorithm has to be wrtten twice once for upper case leters and once for lower case letters a character read is a letter, the procedure for a lower case leter is as follo 1) Convert the character to an integer value between 0 and 25-0 representing 'a and 25 representing 2' (same can be done with upper case leters) To do this conversion, use intVar charRead-a: (you can use whatever variable names you want. intVar is an integer variable and charRead is a character variable) 2) For encoding the offset is added to intVar. For decoding the oftset is subtracted from intVar 3) This new integer value must then be converted to a number between 0 and 25 inclusive. For example if the offset is 2 and the letter to encode is then you have invar # 25+ 2-27. This value of 27 must be converted to a number that will represent the leter that z with an offset ot 2 Page 3 of 4 Spring 2019 CPE211 Project Assignment Project 7 should be converted to. in this case, the number to convert to is 1there are 2 ways to get this value) which will represent b 4) Once th e number has been obtained in step 3, it must be converted back to the corect integer value for the letter it is to represent. That is easily done by taking newCharvar 'a intVar Just add the integer value calculated which must be between 0 and 25) to the integer value represenang 5) Same procedure is done for encoding upper case letters except A is used instead of 'a 6) For decoding the offset is subr acted from intVar which can result in a negative number. For t hey need to be oonveted back to positive values that represent the end of negative numbers the alphabet (the 2 end not the a end) For example if the offset is 2 and the leter to decode is a, then we have intVarF02 2 This value of +2 must be converted to a number that to with an offset of 2. In this case that value is 24 which r represents the leter a decoded represents the leter y: Once the corrected integer value is obtained it is used to obtain the newCharVar as described in step 4 7) Encoding and decoding examples: using an ofset of S A FixC, Y->D, ZE Encoding: Encoding: Abcdefghyldmnopqrstuwvxyz Fghlinnopqrstuvwxyzabcde ABCDEFG HlJKLMNOPQRSTUvwxyz vwXYZABCDEFGHlJKLMNOPQRstu a. d. DecodingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started