Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction For faster sorting of letters, the United States Postal Service nco

ID: 3833671 • Letter: I

Question

Introduction For faster sorting of letters, the United States Postal Service ncourages companies that send large volumes of mail to use a bar code denoting the zip code. The encoding scheme for a five-digit zip code is shown in the below figure. There are full-height frame bars (I) one on each side to specify the inning and the end of a bar code for a zip code. In between are the encodings for the five zip code digits and a correction digit, in terms of their weights, 0's or 1's, where 0 is a half-height frame bar and 1 is a full-height frame bar I. For example, for the digit 2, its corresponding wei 00101, which can be represented as in the bar code The correction digit for a given zip code is computed as follows Add up all the digits of a given zip code, then choose the correction digit to make the sum a multiple of 10. For example, the zip code 46805 has a sum of digits of 23, so the correction digit is 7. (n another words, 23 7 30 which is a multiple of 10). Each digit of the zip code and the correction digit are translated into bar-codes according to its wei in the following table igit Weights These data are in an input file called digitWeights.bkt Each 1 denotes a full-height bar and each 0 denotes a half. height bar. Thus, each digit is encoded as a five full- and half-height bars. For example, a 6 is This project to construct a C program which generates a random sequence of 20 zip codes, using srand( creates and displays their corresponding bar-codes. Input Specifications Build an input file contains a data table which depicts the digits 9) and their co rrespond weights, as shown above. to, l Name of this input file as digitWeights.txt". This input file contains 10 rows and six columns. The first column is one of the decimal digits 0 9. The next five columns are the weights containing either 0 or 1

Explanation / Answer

Below is the code; I couldn't complete questions 6 & 7 due to time constraints but you should be able to get those looking at the functions that have been completed. However, if you require help with them, please do ket me know.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void generateZipcode()
{
int i;
long rnd; /*to hold the random numbers generated*/
FILE *fp;

if(!(fp=fopen("zipCodes.txt","w")))/*open file for writing*/
{/*if file could not be opened*/
printf("Unable to open file, zipCodes.txt ");
exit(1);
}
/*generate 20 5-digit random numbers and save to the file*/
for(i=0;i<20;i++)
{
rnd=rand()%90000+10000;
fprintf(fp,"%ld ",rnd);
}
fclose(fp);
}
/*it's not clear from the question which code is to be read from the file(1st , 2nd, last)
all it says is that a number is to be read from the file. But subsequent questions seem to
that this function will be called to decompose every code in the file, so rather than reading the
file within this function, the code will be read outside and be passed to it for decomposing.
Also nothing is mentioned about what the return value must be. It can't be an array of the
decomposed digits as the function prototype is of type int not int*. However, question 3 seems
to indicate that the output expected from this is an array of the separated digits, so*/
int* create5ZipcodeDigits(long code)
{
static int digits[5];
int i;
i=4;
while(code>0)
{/*fill array from right to left*/
digits[i--]=code%10; /*separate each digit and save to array*/
code/=10; /*get rid of the decomposed digit*/
}
return digits;
}

int correctionDigit(int zipcode[])
{
int i,sum,cDigit,lastDigit;
sum=0;
/*get sum of the digits*/
for(i=0;i<5;i++)
sum+=zipcode[i];
/*if the sum is not a multiple of 10(last digit is not 0), calculate the correction digit*/
lastDigit=sum%10;
cDigit=10-lastDigit;
if(cDigit>9) cDigit=0; /*correctiondigit-lastdigit will be single digit if correctiodigit is required*/
return cDigit;
}

int main()

{
FILE *fp;
int digitWeightTable[10[6],i,j;
char barCodePattern[2][2];

srand(time(NULL)); /*seed the random number generator*/
generateZipcode();

/*read digitWeights.txt into the digitWeightTable array*/
if(!(fp=fopen("digitWeights.txt","r")))/*open file for reading*/
{/*if file could not be opened*/
printf("Unable to open file, digitWeights.txt for reading. ");
exit(1);
}
for(i=0;i<10;i++)
for(j=0;j<6;j++)
fscanf(fp,"%d",&digitWeightTable[i][j]);
fclose(fp);

/*read barCodefor0and1.txt into the digitWeightTable array*/
if(!(fp=fopen("barCodefor0and1.txt","r")))/*open file for reading*/
{/*if file could not be opened*/
printf("Unable to open file, barCodefor0and1.txt for reading. ");
exit(1);
}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
fscanf(fp,"%c",&barCodePattern[i][j]);
fclose(fp);


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote