The encoding scheme for a five-digit zip code is shown in Figure 1. There are fu
ID: 3658817 • Letter: T
Question
The encoding scheme for a five-digit zip code is shown in Figure 1. There are full- height frame bars on each side. The five encoded digits are followed by a check digit, which is computed as follows: Add up all digits, and choose the check digit to make the sum a multiple of 10. For example, the zip code 95014 has a sum of 19 (9 + 5 + 0 + 1 + 4), so the check digit is 1 to make the sum equal to 20 (i.e., a multiple of 10). Each digit of the zip code, and the check digit, is encoded according to the following table, where | denotes a full bar and : a half bar. 1 :::|| 2 ::|:| 3 ::||: 4 :|::| 5 :|:|: 6 ?:||:: 7 ?|:::| 8 ?|::|: 9 ?|:|:: 0 ?||::: Write a program (Using C++) that asks the user for a five-digit zip code and prints the bar code. For example ( Please enter a five-digit zip code: 95014 ||:|:::|:|:||::::::||:|::|:::|||Explanation / Answer
import java.util.Scanner;
class BarCode
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.print("Enter the 5 digit number: ");
String b=s.nextLine();
String ar[]={"||::: ",":::||","::|:|","::||:",":|::|",":|:|:","::||::","||:::|",
"||::|:","||:|::"};
int i,sum=0;
System.out.print("Barcode is: ");
for(i=0;i<b.length();i++)
{
int t=Integer.parseInt(b.charAt(i)+"");
System.out.print(ar[t]);
sum=sum+t;
}
int sumb=sum;
while(true)
{
if(sum%10==0)break;
sum++;
}
System.out.print(ar[sum-sumb]);
System.out.println(" Number is: "+b+(sum-sumb));
}
}
======================================================
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.