1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
int createZipcode();
int extract(int zip, int location);
int correction(int zipcode);
void displaycode(int digit);
void displaybarcode(int digit, int location);
void displaybarcode(int zipcode, int location)
{
printf(" |");
for (location = 1; location <= 5; location++)
{
displaycode(extract(zipcode, location));
}
printf("|\n");
}
void displaycode(int zipcode)
{
switch (zipcode)
{
case 0:
printf("||:::");
break;
case 1:
printf(":::||");
break;
case 2:
printf("::|:|");
break;
case 3:
printf("::||:");
break;
case 4:
printf(":|::|");
break;
case 5:
printf(":|:|:");
break;
case 6:
printf(":||::");
break;
case 7:
printf("|:::|");
break;
case 8:
printf("|::|:");
break;
case 9:
printf("|:|::");
break;
}
}
int createZipcode()
{
return 10000 + rand() % 99999;
}
int extract(int zip, int location)
{
while (location <= 4)
{
location++;
zip /= 10;
}
return zip % 10;
}
int correction(int zipcode)
{
int sum = 0;
sum = extract(zipcode, 1) + extract(zipcode, 2) + extract(zipcode, 3) + extract(zipcode, 4) + extract(zipcode, 5);
return sum;
}
int main()
{
printf("zip code digit barcode\n");
{
int zipcode;
int digit;
for (int k = 0; k <= 9; k++)
{
zipcode = createZipcode();
digit = (10 - (correction(zipcode)) % 10)%10;
printf("%d ", zipcode);
printf(" %d", digit);
displaybarcode(zipcode, 1);
}
}
return 0;
}
|