Menu

[solved]-Assignment Comprises Problems Dealing String Array Manipulation Solution Assignment Due Ju Q39002391

This assignment comprises problems dealing with string and array manipulation. The solution to this assignment is due July 14

The main function is as follows. int main (void) MAP_WDT_A_holdTimer (); initUART(; writeString (Established communication w

(20 points) The Luhn formula is a simple checksum formula used to validate credit card numbers. It was designed to protect ag

digit value that makes the overall sum equal to 30. Recall that the checksum of the final number should be divisible by 10; i

This assignment comprises problems dealing with string and array manipulation. The solution to this assignment is due July 14, 2019, 11:59 pm, via BBLearn. Please submit original work. You can find detailed submission instructions towards the end of this document. Your C code must be clearly written, properly formatted, and well commented for full credit. Do not use any in-built string handling functions supplied by the standard C library such as strcmp, strstr, strlen, etc. Use pointers whenever possible. String Comparison A skeleton project called string compare is available on BBLearn that you can use a starting point to develop your code. (15 points) Complete functions within the string operations.c file which: 1. Accept two strings as inputs from the terminal and compare them for equality. If they are equal, 0 is returned, otherwise the difference in value between the first two non-matching characters is displayed on the terminal. 2. Accept a string and a character as inputs from the terminal. Find the first occurrence of a specific character in a given string. Display the location of the occurrence within the string, or – 1 if it is not found. 3. Take two strings as arguments. If the first exists in the second as a substring, display the starting location of the first occurrence, otherwise – 1. The terminating ” characters are not compared The main function is as follows. int main (void) MAP_WDT_A_holdTimer (); initUART(; writeString (“Established communication with the board”); int choice; uint8_t status, ch; char strl (BUFFER_SIZE), str2 [BUFFER_SIZE]; while (1) { writeString (“n r Function to execute (1 for string compare, 2 for character search, 3 for sub-string search, or -1 to exit”); readint (Echoice); if (choice == -1) break; switch (choice) { case 1: /* FIXME: Read and store strings in strl and str2 +/ status = compareStrings (stri, str2); break; / case 2: /* FIXME: Read string strl; character in ch status – searchForChar (stri, ch); writeInt (status); break; case 3: /* FIXME: Read strl and substring in str2+/ status – search SubString (stri, str2); writeInt (status); break; default: writeString (“n r Erroneous entry. Try again”); writeString (“n r All done. Idling CPU.”); while (1); (20 points) The Luhn formula is a simple checksum formula used to validate credit card numbers. It was designed to protect against accidental errors: most credit cards and many other government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers. The formula works as follows. Using the original num- ber, double the value of every other digit. Then add the values of the individual digits together (if a doubled value now has two digits, add the digits individually). The identification number is valid if the resulting sum is divisible by 10. Check digit QDQDqDQ (a) Computing the check digit. ooooooo….. QqO (b) Luhn checksum validation Fig. 1: The process of creating and validating Luhn checksums. Let’s now walk through both ends of the checksum creation and validation process: computing a check digit and validating the result. Figure 1(a) illustrates the steps involved in computing the check digit. The original number, 176248, is shown in the dashed-line box. Every other digit, starting from the rightmost digit of the original number (which after the addition of the check digit, will be the second rightmost) is doubled. Then each digit is added together. Note that when doubling a digit results in a two-digit number, each of these digits is considered separately. For example, when 7 is doubled to produce 14, it is not 14 that is added to the checksum, but 1 and 4 separately. In our example, the generated checksum is 27; so the check digit is 3 because that’s the digit value that makes the overall sum equal to 30. Recall that the checksum of the final number should be divisible by 10; in other words, the checksum should end in 0. Figure 1(b) illustrates the process of validating the number 1762483, which now includes the check digit. As before, we double every second digit starting with the digit immediately to the left of the check digit, and add the values of all digits, including the check digit, to determine the checksum. Since the checksum is divisible by 10, this number validates. As another example, 79927398713 is valid as well. You have been provided with a skeleton project called luhn.checksum. Complete the function called calculateLuhn that takes as input an identification number and calculates the checksum. The identification number should be provided by the user via the terminal and the result-1 if the number is a valid Luhn checksum, 0 otherwise-must be displayed on the terminal as well. To check that your code is working correctly, 79927398713 is valid. Moreover, note that any credit card number should result in a valid Luhn checksum. Submission Instructions Your C code must be clearly written, properly formatted, and well commented for full credit. A good synopsis of the classic book, Elements of Programming Style by Kernighan and Plauger, is available at en.wikipedia.org/wiki/The_Elements_of_Programming_Style. Another good reference is Rob Pike’s notes on Programming in C, available at www.maultech. com/chrislott/resources/cstyle/pikestyle.html. Once you have implemented all of the required features described in this document submit your code by doing the following: • Run Clean Project on both projects to remove the executable and object files from the project folders. We must be able to build your projects from source and we don’t require your pre-compiled executables or intermediate object files. If your code does not at the very least compile, you will receive a zero. • Zip up your projects and upload them as two separate zip files using the Blackboard Learn submission link found on the course website. Show transcribed image text This assignment comprises problems dealing with string and array manipulation. The solution to this assignment is due July 14, 2019, 11:59 pm, via BBLearn. Please submit original work. You can find detailed submission instructions towards the end of this document. Your C code must be clearly written, properly formatted, and well commented for full credit. Do not use any in-built string handling functions supplied by the standard C library such as strcmp, strstr, strlen, etc. Use pointers whenever possible. String Comparison A skeleton project called string compare is available on BBLearn that you can use a starting point to develop your code. (15 points) Complete functions within the string operations.c file which: 1. Accept two strings as inputs from the terminal and compare them for equality. If they are equal, 0 is returned, otherwise the difference in value between the first two non-matching characters is displayed on the terminal. 2. Accept a string and a character as inputs from the terminal. Find the first occurrence of a specific character in a given string. Display the location of the occurrence within the string, or – 1 if it is not found. 3. Take two strings as arguments. If the first exists in the second as a substring, display the starting location of the first occurrence, otherwise – 1. The terminating ” characters are not compared
The main function is as follows. int main (void) MAP_WDT_A_holdTimer (); initUART(; writeString (“Established communication with the board”); int choice; uint8_t status, ch; char strl (BUFFER_SIZE), str2 [BUFFER_SIZE]; while (1) { writeString (“n r Function to execute (1 for string compare, 2 for character search, 3 for sub-string search, or -1 to exit”); readint (Echoice); if (choice == -1) break; switch (choice) { case 1: /* FIXME: Read and store strings in strl and str2 +/ status = compareStrings (stri, str2); break; / case 2: /* FIXME: Read string strl; character in ch status – searchForChar (stri, ch); writeInt (status); break; case 3: /* FIXME: Read strl and substring in str2+/ status – search SubString (stri, str2); writeInt (status); break; default: writeString (“n r Erroneous entry. Try again”); writeString (“n r All done. Idling CPU.”); while (1);
(20 points) The Luhn formula is a simple checksum formula used to validate credit card numbers. It was designed to protect against accidental errors: most credit cards and many other government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers. The formula works as follows. Using the original num- ber, double the value of every other digit. Then add the values of the individual digits together (if a doubled value now has two digits, add the digits individually). The identification number is valid if the resulting sum is divisible by 10. Check digit QDQDqDQ (a) Computing the check digit. ooooooo….. QqO (b) Luhn checksum validation Fig. 1: The process of creating and validating Luhn checksums. Let’s now walk through both ends of the checksum creation and validation process: computing a check digit and validating the result. Figure 1(a) illustrates the steps involved in computing the check digit. The original number, 176248, is shown in the dashed-line box. Every other digit, starting from the rightmost digit of the original number (which after the addition of the check digit, will be the second rightmost) is doubled. Then each digit is added together. Note that when doubling a digit results in a two-digit number, each of these digits is considered separately. For example, when 7 is doubled to produce 14, it is not 14 that is added to the checksum, but 1 and 4 separately. In our example, the generated checksum is 27; so the check digit is 3 because that’s the
digit value that makes the overall sum equal to 30. Recall that the checksum of the final number should be divisible by 10; in other words, the checksum should end in 0. Figure 1(b) illustrates the process of validating the number 1762483, which now includes the check digit. As before, we double every second digit starting with the digit immediately to the left of the check digit, and add the values of all digits, including the check digit, to determine the checksum. Since the checksum is divisible by 10, this number validates. As another example, 79927398713 is valid as well. You have been provided with a skeleton project called luhn.checksum. Complete the function called calculateLuhn that takes as input an identification number and calculates the checksum. The identification number should be provided by the user via the terminal and the result-1 if the number is a valid Luhn checksum, 0 otherwise-must be displayed on the terminal as well. To check that your code is working correctly, 79927398713 is valid. Moreover, note that any credit card number should result in a valid Luhn checksum. Submission Instructions Your C code must be clearly written, properly formatted, and well commented for full credit. A good synopsis of the classic book, Elements of Programming Style by Kernighan and Plauger, is available at en.wikipedia.org/wiki/The_Elements_of_Programming_Style. Another good reference is Rob Pike’s notes on Programming in C, available at www.maultech. com/chrislott/resources/cstyle/pikestyle.html. Once you have implemented all of the required features described in this document submit your code by doing the following: • Run Clean Project on both projects to remove the executable and object files from the project folders. We must be able to build your projects from source and we don’t require your pre-compiled executables or intermediate object files. If your code does not at the very least compile, you will receive a zero. • Zip up your projects and upload them as two separate zip files using the Blackboard Learn submission link found on the course website.

Expert Answer


Answer to This assignment comprises problems dealing with string and array manipulation. The solution to this assignment is due Ju… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *