#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.

}