ECE175 Computer Programming for Engineering Applications Homework Assignment 6
- Kmgina
- Rating : 186
- Grade : A+
- Questions : 0
- Solutions : 462
- Blog : 1
- Earned : $47433.48
ECE175 Computer Programming for Engineering Applications
Homework Assignment 6 complete solutions correct answers key
Conventions: Name your C programs as hwxpy.c
where x corresponds to the homework number and y corresponds to the problem number.
Write comments to your programs. Programs with no comments will receive PARTIAL credit. For each program that you turn in, at least the following information should be included
- 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 unique identifier 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 compare the IMEI’s last digit, called Luhn digit, with a check digit. If the Luhn digit is equal to the check 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 adding
a) 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 a two-digit number, we add each digit separately. For example, suppose that the value of 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 the last 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 get
ð 3 + (2x5) +7 + (2x6) + 8 + (2x3) + 0 + (2x3) + 6 + (2x2) + 5+ (2x7) + 3+ (2x7)
ð 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)
= 62
ð Then the check digit = 10 – 2 = 8.
Since the check digit (=8) is equal to the Luhn digit (=8), this IMEI is valid. 2
Write a C program that
- Prompt the user to enter the 15 digits of IMEI separated by spaces. The program should 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 user
Enter 15-digit barcode (separate each digit by space)
3 5 7 6 8 3 0 3 6 2 5 7 3 7 8
total sum of 14 digits = 62
check digit = 8
IMEI is valid
Enter 15-digit barcode (separate each digit by space)
3 5 7 6 1 3 0 0 4 4 4 8 4 8 5
total sum of 14 digits = 55
check digit = 5
IMEI is valid
Enter 15-digit barcode (separate each digit by space)
4 9 0 1 5 4 2 0 3 2 3 7 5 1 9
total sum of 14 digits = 52
check digit = 8
IMEI is invalid
Enter 15-digit barcode (separate each digit by space)
0 1 2 6 4 6 0 0 0 8 2 7 7 6 2
total sum of 14 digits = 38
check digit = 2
IMEI is valid
Enter 15-digit barcode (separate each digit by space)
3 5 2 2 5 5 0 1 0 1 3 2 8 3 7
total sum of 14 digits = 41
check digit = 9
IMEI is invalid 3
Problem 2 (35 pts): A two-dimensional array of size mn, X[m][n], can be used to represent a terrain of land where each element is elevation information (i.e. height in feet). For this problem, we want to determine number and location of peaks in the terrain, where a peak is a point that has lower elevations all around. We also want to determine the highest peak and its 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), has exactly 8 neighboring cells (e.g. Above, Below, Left, Right, and four Diagonals). Diagonal #1 11al1)
Above
Diagonal #2
Left
(i, j)
Right
Diagonal #3
Below
Diagonal #4
[Solved] ECE175 Computer Programming for Engineering Applications Homework Assignment 6
- This solution is not purchased yet.
- Submitted On 18 Mar, 2016 01:53:49
- Kmgina
- Rating : 186
- Grade : A+
- Questions : 0
- Solutions : 462
- Blog : 1
- Earned : $47433.48