This part of the lab is worth 5 marks.
Every handphone is assigned a unique 15-digit number known as the "International Mobile Equipment Identity" or IMEI. If you own a handphone and would like to check the IMEI, simply key in *#06#. If the number displayed is more than 15 digits, simply take the first 15 digits. This 15-digit sequence comprises of the following:
Write a C program imei.c that repeatedly accepts the following input:
We shall assume that the user obeys instructions and you do not have to explicitly check the validity of the input. For each set of three numbers entered, the TAC and SNR will be used to compute the correct check digit, which will then be compared with CD to determine the validity of the IMEI. The program terminates as soon as a negative number is entered for any of the three input.
The algorithm for determining the check digit is given in the next section. The skeleton code and sample output are also provided. Remember to submit your program before the stipulated deadline for your lab session. The file that you submit must be named imei.c, any other name is not allowed.
Note that you are NOT to use any form of arrays in your
program.
However, you may define functions to assist in making your
code more modular.
Consider the example:
TAC | SNR | ||||||||||||
d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9 | d10 | d11 | d12 | d13 | d14 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1 | 2 | 3 | 4 | 5 | 6 |
TAC | SNR | ||||||||||||
d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9 | d10 | d11 | d12 | d13 | d14 |
1 | 4 | 3 | 8 | 5 | 12 | 7 | 16 | 1 | 4 | 3 | 8 | 5 | 12 |
1 + 4 + 3 + 8 + 5 + (1 + 2) + 7 + (1 + 6) + 1 + 4 + 3 + 8 + 5 + (1 + 2) = 62
70 - 62 = 8so the correct check digit should be 8.
#include <stdio.h> /* Function to read input from the user. Do not modify */ int readInput(char *prompt) { int value; printf("%s (-ve to exit): ", prompt); scanf("%d", &value); return value; } /** Include other functions if you feel it is necessary... Marks will NOT be deducted even if you do not define functions **/ /* Main function */ int main() { int TAC, SNR, CD; /** Declare other variables here */ while ( ( (TAC = readInput("Enter the 8-digit TAC")) >= 0) && ( (SNR = readInput("Enter the 6-digit SNR")) >= 0) && ( (CD = readInput("Enter the 1-digit CD ")) >= 0) ) { /** You need only modify the loop body to achieve your task **/ printf("The IMEI entered is %d-%d-%d\n\n", TAC, SNR, CD); } /* Terminating Program */ printf("\nProgram Terminated...\n"); return 0; }
The following is a sample session. User input is denoted in bold.
Enter the 8-digit TAC (-ve to exit): 12345678 Enter the 6-digit SNR (-ve to exit): 123456 Enter the 1-digit CD (-ve to exit): 8 This is a valid IMEI. Enter the 8-digit TAC (-ve to exit): 12345678 Enter the 6-digit SNR (-ve to exit): 123456 Enter the 1-digit CD (-ve to exit): 0 This is an INVALID IMEI! Enter the 8-digit TAC (-ve to exit): 35007752 Enter the 6-digit SNR (-ve to exit): 323751 Enter the 1-digit CD (-ve to exit): 3 This is a valid IMEI. Enter the 8-digit TAC (-ve to exit): 20450035 Enter the 6-digit SNR (-ve to exit): 385709 Enter the 1-digit CD (-ve to exit): 0 This is a valid IMEI. Enter the 8-digit TAC (-ve to exit): 12345678 Enter the 6-digit SNR (-ve to exit): -1 Program Terminated...