Question

Write C++ program

T 1030 UUIII DUCOUL The bar code on an envelope used by the US Postal Service represents a five (or more) digit zip code usinRepeat this for each group of five digits and concatenate to get the complete zip code. There is one special value. If the su

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<string.h>

using namespace std;

class zipcode{

int code;

//calculate the number wise encoded number

int get_num(string p)

{

int arr[]={7,4,2,1,0};

int val = 0;

//-48 because ascii of "0" is 48

for(int i=0;i<5;i++)

{

val+=arr[i]*((int)p[i]-48);

}

return val%11;

}

//calculate the numberwise string representation

string get_string(int n)

{

int copy =n;

int arr[5]={7,4,2,1,0};

string p = "";

for(int i=0;i<5;i++)

{ string zero="0";

string one = "1";

if(copy-arr[i]>=0)

{

copy=copy-arr[i];

p = p+one;

}

else{

p = p+zero;

}

}

return p;

}

//decode the string code to integer

int decode(string n)

{

int k = n.length();

//cout<<"hello"<<k<<n.substr();

int inte = 0;

int mult = 10000;

for(int i=0;i<5;i++)

{

string s1 = n.substr((i)*5+1,5);

int val = get_num(s1);

inte+=mult*val;

mult= mult/10;

}

return inte;

}

//encode the integer to string

string encode(int n)

{ int copy =n;

string one = "1";

string en = "1";

for(int i=0;i<5;i++)

{

int x = copy%10;

en = get_string(x) + en;

copy = copy/10;

}

return one+en;

}

public:

//constructor with integer input

zipcode(int n)

{

code = n;

}

//constructor with string input

zipcode(string s)

{

code = decode(s);

}

string get_string()

{

return encode(code);

}

int get_numeric()

{

return code;

}

};

int main()

{

string k = "110100101000101011000010011";

zipcode z(k);

cout<<z.get_numeric();

}

test case-

"110100101000101011000010011"

sumit@linux:-/Desktop$ ./a.out 99504sumit@linux:-/Desktop |

Add a comment
Know the answer?
Add Answer to:
Write C++ program T 1030 UUIII DUCOUL The bar code on an envelope used by the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1 Until 2009, the US Postal Service printed a bar code on every envelope that represented...

    1 Until 2009, the US Postal Service printed a bar code on every envelope that represented the zip code using a format called POSTNET. We will be doing the same with only 5-digit zip codes. POSTNET consists of long and short lines, as seen below: The POSTNET representation of 67260, WSU's zip code In the program, the zipcode will be represented by an integer and the corresponding barcode will be represented by strings of digits. The digit 1 will represent...

  • Python Write a program that asks the user for a zip code and converts it to...

    Python Write a program that asks the user for a zip code and converts it to a postal bar code. A postal bar code uses two types of lines long and short. Since we can't print "long line” we will use: 0 - short line 1 - long line. The digits are represented by bars as explained in the below chart Value Encoding 1 00011 2 00101 00110 01001 01010 01100 10001 8 10010 9 10100 0 11000 The bar...

  • In the program, the zipcode will be represented by an integer and the corresponding barcode will...

    In the program, the zipcode will be represented by an integer and the corresponding barcode will be represented by a string of digits. The digit 1 will represent the long bar, and the digit 0 will represent the short bar, The first and last digits of a POSTNET code are always 1. Stripping these leaves 25 digits, which can be split into groups of 5. The above example translates into the following string and groups of five: 101100100010010101100110001 01100 10001...

  • Have you ever noticed the bar code printed on envelopes? That code helps the USPS process...

    Have you ever noticed the bar code printed on envelopes? That code helps the USPS process the mail. The barcode is generated as specified below. In this assignment you are to write a JAVA program that will accept a 5 digit number from the user and then prints the appropriate symbols to the screen. Name your file ZipCode_yourInitials.java. The specifications for the code are PostalCodeAsignment.pdf. Using a do while loop allow the user to continue entering numbers as long as...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • Write a java project that reads a sequence of up to 25 pairs of names and...

    Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes, street address, city, state, and 10-digit phone number for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer), street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' . Assume each...

  • Please I need help with this c++ code. please show all steps , write comments and...

    Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • (C++)This is the problem that I'm supposed to write a program for: This is the layout...

    (C++)This is the problem that I'm supposed to write a program for: This is the layout that we are supposed to fill out for the project: If anything is unclear, comment and I'll try to clarify. Thank you! Objective Reading Dala Files Project This is a variation of ng challenge 133 de Write a class named Car that has the following pelvate member variables. model Year An ie car's uodd year. make A string that bolds the make of the...

  • Using C++ Design a class called Numbers that can be used to translate integers in the range 0 to ...

    Using C++ Design a class called Numbers that can be used to translate integers in the range 0 to 9999 into an English description of the number. The class should have a single integer member variable: int number; and a static array of string objects that specify how to translate the number into the desired format. For example, you might use static string arrays such as: string lessThan20[20] = {"zero", "one", ..., "eighteen", "nineteen"}; string hundred = "hundred"; string thousand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT