# ECE175 Computer Programming for Engineering Applications Homework Assignment

ECE175 Computer Programming for Engineering Applications Homework Assignment ECE175 Computer Programming for Engineering ApplicationsHomework Assignment 6Due Date: Tuesday March 8, 2016 11:59 PM, via D2LConventions: Name your C programs as hwxpy.cwhere x corresponds to the homework number and y corresponds to the problem number.Write comments to your programs. Programs with no comments will receive PARTIALcredit. For each program that you turn in, at least the following information should beincluded- Author:- Date created:- Brief (two lines) description of the program:Submission Instructions: Submit your .c files via D2L Dropbox.Problem 1 (35 pts): IMEI (International Mobile Equipment Identifier)Every mobile phone operating in wireless networks is characterized by a uniqueidentifier of 15 digits, called IMEI(https://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity)A method to check if the device is really made by the official manufacturer is to comparethe IMEIâs last digit, called Luhn digit, with a check digit. If the Luhn digit is equal to thecheck digit, the device is most probably authentic. Otherwise, it is not authentic for sure.The check digit is calculated as follows:1) First, we calculate the SUM of the first IMEIâs 14 digits by addinga) the digits in the odd positions (meaning even index for the array in C)b) the double of the digits in the even positions. But if the double of the digit is atwo-digit number, we add each digit separately. For example, suppose that the valueof the digit is 8, its double is 16. We therefore add to the SUM the result of 1+6 = 7(not 16).2) If the last digit of the calculated SUM is 0, that is the check digit. If not, we subtract thelast digit of the calculated SUM from 10 and that is the check digit.For example: letâs check the IMEI 357683036257378.Note: the last digit of the given IMEI above is 8 which is the Luhn digit.Apply the above algorithm (by hand) to the first 14 digits, we get3 + (2×5) +7 + (2×6) + 8 + (2×3) + 0 + (2×3) + 6 + (2×2) + 5+ (2×7) + 3+ (2×7)3 + (10) +7 + (12) + 8 + (6) + 0 + (6) + 6 + (4) + 5+ (14) + 3+ (14)3 + (1+0) +7 + (1+2) + 8 + (6) + 0 + (6) + 6 + (4) + 5+ (1+4) + 3+ (1+4)3 + (1) +7 + (3) + 8 + (6) + 0 + (6) + 6 + (4) + 5+ (5) + 3+ (5)= 62Then the check digit = 10 â 2 = 8.Since the check digit (=8) is equal to the Luhn digit (=8), this IMEI is valid.1Write a C program that- Prompt the user to enter the 15 digits of IMEI separated by spaces. The programshould store the digits in an integer array.- Display the sum of the first 14 digits using the algorithm on the previous page- Calculate and display the check digit, and- Compare it to the Luhn digit. If they match, output with the message âIMEI is valid.âIf not, output with the message âIMEI is invalidâ.Sample Code Execution: Digits are entered by a userEnter 15-digit barcode (separate each digit by space)357683036257378total sum of 14 digits = 62check digit = 8IMEI is validEnter 15-digit barcode (separate each digit by space)357613004448485total sum of 14 digits = 55check digit = 5IMEI is validEnter 15-digit barcode (separate each digit by space)490154203237519total sum of 14 digits = 52check digit = 8IMEI is invalidEnter 15-digit barcode (separate each digit by space)012646000827762total sum of 14 digits = 38check digit = 2IMEI is validEnter 15-digit barcode (separate each digit by space)352255010132837total sum of 14 digits = 41check digit = 9IMEI is invalid2Problem 2 (35 pts): A two-dimensional array of size mn, X[m][n], can be used to representa terrain of land where each element is elevation information (i.e. height in feet). For thisproblem, we want to determine number and location of peaks in the terrain, where a peak isa point that has lower elevations all around. We also want to determine the highest peak andits location.How to decide whether a location (i, j) is a peak:For 2-D array below, each element, except those on the boundaries (edges), hasexactly 8 neighboring cells (e.g. Above, Below, Left, Right, and four Diagonals).Diagonal#1 11al1)LeftDiagonal#3Above(i, j)BelowDiagonal#2 RightDiagonal#41) We decide that the value at (i, j) is a peak if the value at (i, j) is higher than thevalues at the âAboveâ, âBelowâ, âLeftâ and âRightâ locations of (i, j). In otherwords, if the values of all 4 neighboring points are less than the value at (i,j),then location (i,j) is considered a peak.2) The points on the edge cannot be a peak since we do not have elevationinformation on all 4 sides. In other words, you can ignore the elements at theboundary (edge) of the array. That is, start your element procession from row 1:elements (1,1) up to (1, n-2), continue until row m-2: elements (m-2, 1) to cell (m2, n-2).Hint: in your program, âAboveâ, âBelowâ, âLeftâ and âRightâ locations of (i, j) can bewritten in terms of i and j. For example, âAboveâ location of (i, j) is location (i-1, j)Write a C program thata) Read the terrain data from Prob2.txt (you will create this text file).See sample code executions on the next page.b) Determine and print all the peak values and the location of those peaks. Your programshould examine every location (i, j) starting from i=1 and j=1 and decide whether thatlocation is a peak using the criteria above.c) Determine and print the highest peak and its location.Note: (nested) loops MUST be used to read from the text file in order to create 2-D arrayused in your program and the loops should be used to access elements of 2-D array fordata processing. Otherwise, -20 pts.3Sample code execution #1:If the terrain data in Prob2.txt (again, you are to create this text file for your program) is5039 5127 5238 5259 5248 5310 52995150 5392 5410 5501 5320 5820 53215290 5560 5490 5421 5530 5831 52105110 5429 5430 5411 5459 5630 53194920 5129 4921 5821 4722 4921 51295023 5129 4822 4872 4794 4862 4245Display the following on the output screen:Terrain data5039 5127 5238 5259 5248 5310 52995150 5392 5410 5501 5320 5820 53215290 5560 5490 5421 5530 5831 52105110 5429 5430 5411 5459 5630 53194920 5129 4921 5821 4722 4921 51295023 5129 4822 4872 4794 4862 4245Explanation,1) Consider element[1][1] (=5392). Its 4neighbors are 5127, 5150, 5560, 5410.Since 5392 is not the maximum (amongthe 4 neighbors), this point is not a peak.Peak 5501 at row 1 col 3Peak 5560 at row 2 col 1Peak 5831 at row 2 col 5Peak 5821 at row 4 col 3The maximum peak is 5831 at row 2 col 52) Consider element[1][3] (=5501). Its 4neighbors are 5259, 5410, 5421, 5320.Since 5501 is the maximum (among the 4neighbors), this point is a peak.Sample code execution #2:If the terrain data in Prob2.txt (you are to create this text file for your program) is5039 5127 5238 5259 5248 5310 52995150 5392 5410 5401 5320 5750 53215290 5560 5990 5421 5530 5731 52105110 5429 5430 5411 5459 5830 53194920 5829 4921 5321 4722 5921 51295023 5129 4822 4872 4794 4862 4245Display the following on the output screen:Terrain data5039 5127 5238 5259 5248 5310 52995150 5392 5410 5401 5320 5750 53215290 5560 5990 5421 5530 5731 52105110 5429 5430 5611 5459 5830 53194920 5829 4921 5321 4722 5921 51295023 5129 4822 4872 4794 4862 4245Peak 5750 at row 1 col 5Peak 5990 at row 2 col 2Peak 5611 at row 3 col 3Peak 5829 at row 4 col 1Peak 5921 at row 4 col 5The maximum peak is 5990 at row 2 col 24