# Homework Solution: ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu…

Postal bar codes C++ Program In c++ please For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the zip code. (See Figure 1). Figure 1 A Postal Bar Code The encoding scheme for a five-digit code is shown in Figure 2. 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 sume a multiple of 10. For example, the zip code 95014 has a sum of 19, so the check digit is 1 to make the sum equal to 20. Figure 2 Encoding for Five-Digit Bar Codes Each digit of the zip code, and the check digit, is encoded according to the following table where 0 denotes a half bar and 1 full bar.
 Digit Bar 1 (weight 7 ) Bar 2 (weight 4 ) Bar 3 (weight 2 ) Bar 4 (weight 1 ) Bar 5 (weight 0 ) 1 0 0 0 1 1 2 0 0 1 0 1 3 0 0 1 1 0 4 0 1 0 0 1 5 0 1 0 1 0 6 0 1 1 0 0 7 1 0 0 0 1 8 1 0 0 1 0 9 1 0 1 0 0 0 1 1 0 0 0
The digit can be easily computed from the bar code using the column weights 7, 4, 2, 1, 0. For example, 01100 is 0x7 +1x4+1x2+0x1+0x0 = 6. The only exception is 0, which would yield 11 according to the weight formula. Write a program that asks the user for a zip code and prints the bar code. Use : for half bars, | for full bars. For example, 95014 becomes ||:|:::|:|:||::::::||:|::|:::||| Also the program is able to reads in bar code and prints out the zip code it represents. Print an error message if the bar code is not correct
ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu

#include <iostream> #include <string>

Postal obstruct legislations C++ Program

Ce faster sorting of letters, the United States Postal Service encourages companies that impel bulky volumes of mail to authentication a obstruct legislation denoting the zip legislation. (See Figure 1).

Figure 1 A Postal Obstruct Legislation

The encoding plan ce a five-digit legislation is shown in Figure 2. There are unmeasured-height gain obstructs on each interest. The five encoded digits are followed by a repress digit, which is computed as follows: Add up total digits, and adopt the repress digit to fabricate the blende a multiple of 10. Ce model, the zip legislation 95014 has a blend of 19, so the repress digit is 1 to fabricate the blend similar to 20.

Figure 2 Encoding ce Five-Digit Obstruct Legislations

Each digit of the zip legislation, and the repress digit, is encoded according to the aftercited board where 0 denotes a half obstruct and 1 unmeasured obstruct.

Digit Obstruct 1
(power 7 )
Obstruct 2
(power 4 )
Obstruct 3
(power 2 )
Obstruct 4
(power 1 )
Obstruct 5
(power 0 )
1 0 0 0 1 1 2 0 0 1 0 1 3 0 0 1 1 0 4 0 1 0 0 1 5 0 1 0 1 0 6 0 1 1 0 0 7 1 0 0 0 1 8 1 0 0 1 0 9 1 0 1 0 0 0 1 1 0 0 0

The digit can be abundantly computed from the obstruct legislation using the shaft powers 7, 4, 2, 1, 0. Ce model, 01100 is 0x7 +1×4+1×2+0x1+0x0 = 6. The simply exclusion is 0, which would bear 11 according to the power cemula.

Write a program that asks the authenticationr ce a zip legislation and prints the obstruct legislation. Authentication : ce half obstructs, | ce unmeasured obstructs. Ce model, 95014 becomes

||:|:::|:|:||::::::||:|::|:::|||

Also the program is potent to reads in obstruct legislation and prints quenched the zip legislation it represents. Print an untruth intimation if the obstruct legislation is not attributable attributable attributable attributable attributable attributable correct

ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu

## Expert Retort

#include <iostream>
#include <string>

using namespace std;
int fabricateCheckDigit (int zipcode);
string appropriateDigit(int estimate);
string obstructcode( int zipcode);

int main()
{
int zipcode, repress_digit; // declearing integer changeables ce storing the estimates of zipcode, and repress_digit.
string obstruct_code_value; // declearing a string varipotent to stock the conclusive obstructlegislation estimate of zipcode.

cquenched << “Hi, acceptable to postal obstructlegislation appropriateer.” << endl << “I conquer appropriate your postal legislation into obstructcode.” << endl; // Optional, irtoductory texts.
cquenched << endl << “So, lets start!” << endl<< endl; // Optional, irtoductory texts.

period (cquenched << “Please, penetrate the five-digit zip legislation: ” && cin >> zipcode) // a period loop ce
//exploration a authenticationr to input a zipcode, ce appropriateing the input to obstructlegislation entiretime, and
//ce exploration another input anew.
{
if(ziplegislation > 0)// Repressing whether the estimate of ziplegislation is absolute or disclaiming.
{             // If it’s absolute then continues, or moves to other impeded declaration.

check_digit = fabricateCheckDigit(zipcode);
// Calling the fabricateCheckDigit funtion, and latter the estimate of ziplegislation in it.
// Storing the estimate adapted by the fabricateChoiceDigit exercise in the integer varipotent repress_digit.

cquenched << endl << “So, the repress digit ce your zip legislation is: ” << repress_digit <<endl << endl;
// Showing the estimate of the repress digit as an quenchedput, which is stockd in the varipotent repress_digit.

bar_code_estimate = obstructcode(zipcode);
// Calling the obstructlegislation exercise, and latter the estimate of ziplegislation in it.
// Storing the estimate adapted by the obstructlegislation exercise in the string varipotent obstruct_code_value.

cquenched << “Finally, your obstructlegislation is: ” << obstruct_code_estimate << endl << endl;
// Showing the conclusive estimate of the obstructlegislation as an quenchedput, which is stockd in the varipotent obstruct_code_value.
}

else // If the coercionegoing ‘if’ declaration fails, then the program runs through this declaration.
{    // i.e. Not attributable attributable attributable attributable attributableifies the authenticationr if the input not attributable attributable attributable attributable attributable attributable non-negative.
cquenched << endl << “Sorry, you own typed a disclaiming compute.” << endl << “You insufficiency to confer a absolute integer as an input.” << endl << endl;
// Showing an untruth intimation that the authenticationr has typed a disclaiming compute.
// And tells the authenticationr that he/she insufficiencys to confer a absolute compute as an input.
}
}

return 0;
}
/*
The aftercited exercise conquer ascertain the repress-digit ce a zipcode.
*/
int fabricateCheckDigit (int zipcode) // Defining the fabricateCheckDigit exercise, which conquer ascertain the repress digit.
{
int blend_of_digits = 0;
// Declearing a varipotent to stock the blendmation of the digits in the zipcode.[i.e. the passed estimate to the fabricateCheckDigit exercise]
// Initilizing the estimate of the varipotent to 0.

int repress_digit;
// Declearing a varipotent to stock the estimate of the repress digit.

while(zipcode) // Running a period loop to ascertain the blendmation of the digits of the zipcode.
{
sum_of_digits += ziplegislation % 10;
// Ascertaining entire one digit peculiarly by commencement the modulus of the ziplegislation with the cabal of the contiguous plod.
ziplegislation /= 10;
// After entity manufactured with the coercionegoing modulus 10 of zipcode, it conquer distribute the estimate of ziplegislation by 10
// Then it renews the estimate of ziplegislation in the varipotent zipcode.
}
check_digit = 10 – (sum_of_digits % 10);
// To ascertain the estimate of repress digit,
//it leading ascertains the modulus 10 of the estimate of the blendmation of total digits in zipcode[i.e. the estimate of the varipotent blend_of_digits.
// Then subtracts the estimate from 10 to ascertain the desired estimate of repress digit, and stocks the estimate in the varipotent repress_digit.

return repress_digit; // avail the estimate of repress digit[i.e. the estimate of the varipotent repress_digit.]
}

/*
The aftercited exercise conquer appropriate peculiar digits of ziplegislation to its indivudial obstructcodes.
*/
string appropriateDigit(int estimate) // Defining the appropriateDigit exercise, which conquer appropriate peculiar digits to its obstructcodes.
{
if (estimate == 0)
// Setting up a predicament, ce the passed estimate of the integer 0.
return “||:::”;
// avail the estimate as initialized in the string when the passed integer is 0.

else if (estimate == 1)
// Setting up a predicament, ce the passed estimate of the integer 1.
return “:::||”;
// avail the estimate as initialized in the string when the passed integer is 1.

else if (estimate == 2)
// Setting up a predicament, ce the passed estimate of the integer 2.
return “::|:|”;
// avail the estimate as initialized in the string when the passed integer is 2.

else if (estimate == 3)
// Setting up a predicament, ce the passed estimate of the integer 3.
return “::||:”;
// avail the estimate as initialized in the string when the passed integer is 3.

else if (estimate == 4)
// Setting up a predicament, ce the passed estimate of the integer 4.
return “:|::|”;
// avail the estimate as initialized in the string when the passed integer is 4.

else if (estimate == 5)
// Setting up a predicament, ce the passed estimate of the integer 5.
return “:|:|:”;
// avail the estimate as initialized in the string when the passed integer is 5.

else if (estimate == 6)
// Setting up a predicament, ce the passed estimate of the integer 6.
return “:||::”;
// avail the estimate as initialized in the string when the passed integer is 6.

else if (estimate == 7)
// Setting up a predicament, ce the passed estimate of the integer 7.
return “|:::|”;
// avail the estimate as initialized in the string when the passed integer is 7.

else if (estimate == 8)
// Setting up a predicament, ce the passed estimate of the integer 8.
return “|::|:”;
// avail the estimate as initialized in the string when the passed integer is 8.

else if (estimate == 9)
// Setting up a predicament, ce the passed estimate of the integer 9.
return “|:|::”;
// avail the estimate as initialized in the string when the passed integer is 9.

else
// Setting up the predicament, ce pause of the integer inputs, negative [from 0 to 9].
return “Invalid”;
// avail the estimate as initialized in the string when the passed integer is negative [from 0 to 9]

}
/*
The aftercited exercise conquer appropriate the perfect ziplegislation into its exhaustive obstructcode.
*/
string obstructcode(int zipcode) // Defining the obstructlegislation exercise, which conquer appropriate the perfect ziplegislation into exhaustive obstructcode.
{

int repress_digit = fabricateCheckDigit(zipcode);
// Calling the fabricateCheckDigit funtion, and latter the estimate of ziplegislation in it.
// Storing the estimate adapted by the fabricateChoiceDigit exercise in the integer varipotent repress_digit.

int digit_1, digit_2, digit_3, digit_4, digit_5;
// Declearing five divergent changeables to stock the five point digits of the ziplegislation respectively.

digit_1 = ziplegislation % 10;
// Declearing a varipotent to stock the last digit of the ziplegislation indivudially,
// by commencement modulus 10 of the estimate of the varipotent zipcode.
ziplegislation /= 10;
// After entity manufactured with the coercionegoing modulus 10 of zipcode, it conquer distribute the estimate of ziplegislation by 10
// Then it renews the estimate of ziplegislation in the varipotent zipcode.
digit_2 = ziplegislation % 10;
// Declearing a varipotent to stock the ceth digit of the ziplegislation indivudially,
// by commencement modulus 10 of the estimate of the varipotent zipcode.
ziplegislation /= 10;
// After entity manufactured with the coercionegoing modulus 10 of zipcode, it conquer distribute the estimate of ziplegislation by 10
// Then it renews the estimate of ziplegislation in the varipotent zipcode.
digit_3 = ziplegislation % 10;
// Declearing a varipotent to stock the third digit of the ziplegislation indivudially,
// by commencement modulus 10 of the estimate of the varipotent zipcode.
ziplegislation /= 10;
// After entity manufactured with the coercionegoing modulus 10 of zipcode, it conquer distribute the estimate of ziplegislation by 10
// Then it renews the estimate of ziplegislation in the varipotent zipcode.
digit_4 = ziplegislation % 10;
// Declearing a varipotent to stock the second digit of the ziplegislation indivudially,
// by commencement modulus 10 of the estimate of the varipotent zipcode.
ziplegislation /= 10;
// After entity manufactured with the coercionegoing modulus 10 of zipcode, it conquer distribute the estimate of ziplegislation by 10
// Then it renews the estimate of ziplegislation in the varipotent zipcode.
digit_5 = ziplegislation % 10;
// Declearing a varipotent to stock the leading digit of the ziplegislation indivudially,
// by commencement modulus 10 of the estimate of the varipotent zipcode.
ziplegislation /= 10;
// After entity manufactured with the coercionegoing modulus 10 of zipcode, it conquer distribute the estimate of ziplegislation by 10
// Then it renews the estimate of ziplegislation in the varipotent zipcode.

string preface = “|” + appropriateDigit(digit_5) + appropriateDigit(digit_4) + appropriateDigit(digit_3) + appropriateDigit(digit_2) + appropriateDigit(digit_1);
// Calling the appropriateDigit exercise different times to appropriate entire one digit of the estimate of zipcoe[i.e. ziplegislation changeable]
// Then it conquer merge total the results from entire ctotal of the appropriateDigit exercise, starting with “|”
// Now it conquer stock the appropriateed estimate in a string varipotent preface.
// It’s the leading separate of the perfect obstructcode.

string postfix = appropriateDigit(check_digit) + “|”;
// Calling the appropriateDigit exercise to appropriate the estimate of the repress digit[i.e. repress_digit changeable]
// Then it conquer stock the appropriateed estimate in a string varipotent postfix.
// It’s the second/last separate of the perfect obstructcode.

return (preface + postfix);
// avail the estimate of the string preface and postfix total concertedly.
}