Question

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 00101 01100 11000 Now, we look at each group of 5. There will always be two 1s. Depending on its location within the group, each 1 represents a number. When the numbers that the 1s represent are added together, you get that digit of the zip code. The table below translates the underlined group, which represents the number 6. POSTNET Digits 0 11 00 Value We see that the 1s correspond to the values of 4 and 2, respectively. Adding them up gives us 6, which is the first digit of the zip code (and also the fourth since the same group appears again, due to the zip code having two 6s) n order to represent the number 0, the 1s will add up to a value of 11. This is done because of the requirement that every group of five always has two 1s in it
Requirements NOTE: Typically, Ihave tried to make the extra credit something that can be tacked on to the regular assignment. This is not the case here. The extra credit option will still use much of the same logic, but it requires that the homework be designed in a fundamentally different manner Name your source file program10.cpp These are the first-50 lines of code (Dont forget the required comment block!) #include <iostream> #include #include <fstream> <string> z s using namespace std struct Zipcode int romanZipcode; string postnetCode; // Does not store the leading and trailing 1 / Accepts both roman and barcode formats fills both struct members Zipcode fillzipcode(const string zip): 1/ Conversion of roman zip code to bar code string romanToPOSTNET (const int r); 8 11 Conversion of bar code to roman zip code int postnetToRoman (const string p); a void printRomanZip(const Zipcode zip) n void printPOSTNET (const Zipcode zip); as Filename will be the roman zip, as // contents are graphical bar code n void writeToFile(const Zipcode zip); 0 Argument is used to display appropriate prompt to user s2 Creates and assigns to a Zipcode struct 4 Creates a file whose name is in the format ROMAN,txt where Gets zip code from user Prints roman and graphical bar code to screen 35 ROMAN is the roman zip code, and the contents are the
graphical representation of the bar code R/ void processZip(int prompt); o int main() int mainMenu cout < This program is able to convert zip codes to a POSTNET format and vice versaln << \tl. Convert zip code to POSTNETVn <く Vt2. Convert POSTNET to zip coden do ( cout << Please make your selection: cin > mainMenu; switch(mainMenu) case 1 case 2 processZip (mainMenu); break if (mainMenu3) else default cout << Invalid choice...In cout << n while (mainMenu!3) return 0 Implement and use all functions as given The main() function will not be altered You may declare and use additional functions if needed You may as sume that a valid zip code is entered, in either format -You may also assume that no zip code will be provided that begins with a 0, even though they are legal A sample run with zip code input will look something like this (NOTES:Some of the output is displayed on multiple lines simply to fit on the page, &the $represents the terminal prompt
you should NOT print it in your code): ./prog10 This program is able to convert zip codes to a POSTNET format and vice versa 1. Convert zip code to POSTNET 2. Convert POSTNET to zip code 3. Quit Please make your selection Enter a zip code in roman format (#####): 67260 Your zip code is 67260, and the bar code looks like this Your zip code was saved in the file 67260.txt A sample run with bar code input will look something like this /prog10 This program is able to convert zip codes to a POSTNET format and vice versa 1. Convert zip code to POSTNET 2. Convert POSTNET to zip code 3. Quit Please make your selection: 2 Enter a zip code in bar code format (1s and 0s) 1011001000100101011001 10001 Your zip code is 67260, and the bar code looks 1ike this: Your zip code was saved in the file 67260.txt Yes, choices 1 and 2 provide the exact same output - The only difference is the prompt that the user sees, and what the user enters
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear student ,
Please comment for any doubts or modifications...
Please upvote if the answer is helpful .....thanks...





Program screenshot:

Header files #include #include #include <iostream> <f3tre am> <string> #include #include #include #include #include <cmath> <

return pos tnet: // The following function is used to convert // the bar code to roman zip code. int postnetloRoman (const 3t

indext+ for index < (2 len) + 1; index++) cout << I cout << endl; // The following function accepts the zipcode and / this f

// The following method is used to convert the /I zip to postnet and display it on the screen // and writes it to the file wi

output <n for (; ǐ < (2 * len) + 2; i++) output <<I output << endl; output.close O cout << InYour zip code was saved in

Sample output screenshot:

D:AlexLee VBicppTest DebugicppTest.exe This program is able to convert zip codes to a POSTNET format and vice versa 1. Conver

Sample output file screenshot:

67260 - Notepad File Edit Format View Help Your Zip code is 67260, and the bar code looks like this:

Code to copy:

// Header files

#include <iostream>

#include <fstream>

#include <string>

#include <cmath>

#include <cstdio>

#include <vector>

#include <sstream>

#include <algorithm>

using namespace std;

struct ZipCode {

     int romanZipCode;

     string postnetCode;

};

// Function declarations

ZipCode fillZipCode(const string zip);

string romanToPOSTNET(const int r);

int postnetToRoman(const string p);

void printRomanZip(const ZipCode zip);

void printPOSTNET(const ZipCode zip);

void writeToFile(const ZipCode zip);

void processZip(int prompt);

int getInt(string str);

void printGraphicalPOSTNET(string postnet);

string get5BitBinary(int x);

// The following function is used to accepts both roman

// and barcode formats, fills both struct members.

ZipCode fillZipCode(ZipCode zip)

{

     if (zip.postnetCode == "")

     {

          zip.postnetCode = romanToPOSTNET(zip.romanZipCode);

     }

     else

     {

          zip.romanZipCode = postnetToRoman(zip.postnetCode);

     }

     return zip;

}

// The following function is used to convert

// the roman zip code to bar code.

string romanToPOSTNET(const int r)

{

     string postnet;

     postnet = postnet + get5BitBinary(r);

     return postnet;

}

// The following function is used to convert

// the bar code to roman zip code.

int postnetToRoman(const string p)

{

     int i = 1;

     int r = 0;

     while (p.length() - i >= 5)

     {

          r = r * 10 + getInt(p.substr(i, 5));

          i += 5;

     }

     return r;

}

// The following function is used to display

// the roman zip

void printRomanZip(const ZipCode zip)

{

     cout << "\nYour Zip code is " << zip.romanZipCode;

}

// The following function is used to display

// the graphical representation.

void printPOSTNET(const ZipCode zip)

{

     cout << ", and the bar code looks like this:\n" << endl;;

     printGraphicalPOSTNET(zip.postnetCode);

}

// The following function is used to display

// the graphical post net representation.

void printGraphicalPOSTNET(string postnet)

{

     int len = postnet.length();

     int index = 0;

     for (index = 0; index < len; index++)

     {

          if (postnet[index] == '1')

          {

               cout << "|";

          }

          else {

              cout << " ";

          }

     }

     cout << "\n";

     index++;

     for (; index < (2 * len) + 1; index++)

     {

          cout << "|";

     }

     cout << endl;

}

// The following function accepts the zipcode and

// this function returns its POSTNET code

string get5BitBinary(int x)

{

     string binary[] = { "11000","00011","00101", "00110",

          "01001","01010","01100", "10001",

          "10010","10100" };

     string str = "1";

     while (x > 0)

     {

          int bit = x % 10;

          str = binary[bit] + str;

          x /= 10;

     }

     // when the zipcode has trailing 0's

     // Ex : 02363

     if (str.length() < 25)

     {

          str = binary[0] + str;

     }

     str = "1" + str;

     return str;

}

// The following function accepts the string datatype input

// which contains 5 bits.

// This function returns its integer value

int getInt(string str)

{

     string binary[] = { "11000","00011","00101", "00110",

          "01001","01010","01100", "10001",

          "10010","10100" };

     for (int index = 0; index < 10; index++)

     {

          if (str.compare(binary[index]) == 0)

          {

              return index;

          }

     }

}

// The following method is used to convert the

// zip to postnet and display it on the screen

// and writes it to the file with zip as its name

// if the user selects option 1 and this function

// is used to convert the postnet to zip and then

// displays it on the screen and writes it to the

// file, if the user selectds option 2.

void processZip(int prompt)

{

     struct ZipCode code;

     if (prompt == 1)

     {

          cout << "\nEnter a zip code in roman format (#####): ";

          cin >> code.romanZipCode;

          code = fillZipCode(code);

          printRomanZip(code);

          printPOSTNET(code);

     }

     else

     {

          cout << "\nEnter a zip code in bar code format (1's and 0's): ";

          cin >> code.postnetCode;

          code = fillZipCode(code);

          printRomanZip(code);

     }

     writeToFile(code);

}

// The following function is used to write the zip code in

// the file.

void writeToFile(const ZipCode zip)

{

     string filename = "";// to_string(zip.romanZipCode)+".txt";

     std::stringstream ss;

     ss << zip.romanZipCode;

     filename.append(ss.str());

     filename += ".txt";

     ofstream output(filename.c_str(), ios::out);

     output << "Your Zip code is " << zip.romanZipCode;

     output << ", and the bar code looks like this:\n";

     int len = zip.postnetCode.length();

     int i = 0;

     for (i = 0; i < len; i++)

     {

          if (zip.postnetCode[i] == '1')

          {

              output << "|";

          }

          else

          {

              output << " ";

          }

     }

     output << "\n";

     i++;

     for (; i < (2 * len) + 2; i++)

     {

          output << "|";

     }

     output << endl;

     output.close();

     cout << "\nYour zip code was saved in the file "<< filename

          <<endl;

}

// Create a main method to execute the program.

int main()

{

     int mainMenu;

     cout << " This program is able to convert zip codes to a POSTNET format "

          << "and vice versa\n"

          << "\t 1. Convert zip code to POSTNET\n"

          << "\t 2. Convert POSTNET to zip code\n"

          << "\t 3. Quit\n";

     do

     {

          cout << "Please make your selection: ";

          cin >> mainMenu;

          switch (mainMenu)

          {

          case 1:

          case 2:

              processZip(mainMenu);

              break;

          default:

              if (mainMenu != 3)

                   cout << "Invalid choice...\n";

              else

                   cout << "\n";

          }

     } while (mainMenu != 3);

     return 0;

}

Add a comment
Know the answer?
Add Answer to:
In the program, the zipcode will be represented by an integer and the corresponding barcode will...
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...

  • Please help me figure out why my code is not working properly.I had thought my logic...

    Please help me figure out why my code is not working properly.I had thought my logic was sound but later found it will run one time through fine however if the user opts to enter another value it will always be returned as an error. #include <iomanip> #include <iostream> #include <cstdlib> using namespace std; int const TRUE = 1; int const FALSE = 0; // declares functions void GetZipcode(); void RunAgain(); int GetSum(char d1, char d2, char d3, char d4,...

  • Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package...

    Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package delivery service to check delivery areas. 1 using static System.Console; 2 class CheckZips 3 { 4 static void Main() 5 { 6 string[] zips = {"12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210"}; CheckZips.cs(10,8): error CS002 9: Cannot implicitly convert ty pe 'string' to 'string[]' CheckZips.cs(18,5): error CS001 9: Operator '==' cannot be appl ied to operands of type 'string []' and...

  • Hey I really need some help asap!!!! I have to take the node class that is...

    Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input...

  • (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....

    (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits I 1 V 5 X 10 L 50 C 100 D 500 M 1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately....

  • Write C++ program T 1030 UUIII DUCOUL The bar code on an envelope used by the...

    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 using a format called POSTNET (this format is being deprecated in favor of a new system, OneCode, in 2009). The bar code consists of long and short bars as shown below: Illlllllllll For this program we will represent the bar code as a string of digits. The digit 1 represents a long bar...

  • Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the...

    Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the prototype added to the .h file......and the implementation in the .cpp file....thanks! edited: I just need the above and then I was told to use the methods in the main program; for the vehicle. Any 3 attributes and any three methofds. source.cpp file // Header Comment #include #include #include #include "Automobile.h" using namespace std; struct Address{ string street; string city; string state; string zip;...

  • In c programming . Part A: Writing into a Sequential File Write a C program called...

    In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...

  • Write the functions needed to complete the following program as described in the comments. Use the...

    Write the functions needed to complete the following program as described in the comments. Use the input file course.txt and change the mark of student number 54812 to 80. /* File: course.cpp A student's mark in a certain course is stored as a structure (struct student as defined below) consisting of first and last name, student id and mark in the course.  The functions read() and write() are defined for the structure student.   Information about a course is stored as a...

  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

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