Question: Hi i need help with my C++ barcode lab. Below are the instructions for the lab and my code: My code: // main.cpp #include #include

Hi i need help with my C++ barcode lab. Below are the instructions for the lab and my code:

Hi i need help with my C++ barcode lab. Below are the

instructions for the lab and my code: My code: // main.cpp #include

My code:

// main.cpp

#include

#include

#include "Zipcode.h"

using namespace std;

int main()

{

ZipCode zip1(99504);

ZipCode zip2(12345);

ZipCode zip3(67890);

ZipCode zip4("100101010011100001100110001");

ZipCode zip5("110100001011100001100010011");

ZipCode zip6("100011000110101000011100101");

cout

cout

cout

cout

cout

cout

cout

cout

return 0;

}

//ZipCode.h

#ifndef _ZIPCODE_

#define _ZIPCODE_

#include

using namespace std;

class ZipCode

{

private:

string barcode;

//string zipcode;

string calcZip();

void calcBar(int zipcode);

public:

int getZipCode();

string getBarCode();

ZipCode(int zipcode);

ZipCode(string barcode);

};

#endif // !_ZIPCODE_

//ZipCode.cpp

#include

#include

#include "Zipcode.h"

using namespace std;

ZipCode::ZipCode(int zipcode)

{

calcBar(zipcode);

}

ZipCode::ZipCode(string barcode)

{

*this = barcode;

}

string ZipCode::calcZip()

{

string zipcode;

char *first = new char;

first = &barcode.at(0);

barcode.pop_back();

barcode.erase(*first);

delete first;

first = NULL;

for (int i = 0; i

{

string temp;

int count = 0;

int sum = 0;

temp = barcode.substr(i, 5);

if (count == 2)

{

if (sum == 11)

sum = 0;

zipcode += sum;

}

else

{

for (int index = 0; index

{

int subBar;

subBar = (int)temp.at(i);

if (subBar == 1)

{

if (i == 0)

sum += (subBar * 7);

else if (i == 1)

sum += (subBar * 4);

else if (i == 2)

sum += (subBar * 2);

else if (i == 3)

sum += (subBar * 1);

else if (i == 4)

sum += (subBar * 0);

}

}

}

}

return zipcode;

}

void ZipCode::calcBar(int zipcode)

{

std::string temp = std::to_string(zipcode);

for (int i = 0; i

{

if (temp.at(i) == 9)

barcode.append("10100");

else if (temp.at(i) == 8)

barcode.append("10010");

else if (temp.at(i) == 7)

barcode.append("10000");

else if (temp.at(i) == 6)

barcode.append("01100");

else if (temp.at(i) == 5)

barcode.append("01010");

else if (temp.at(i) == 4)

barcode.append("01000");

else if (temp.at(i) == 3)

barcode.append("00110");

else if (temp.at(i) == 2)

barcode.append("00100");

else if (temp.at(i) == 1)

barcode.append("00010");

else if (temp.at(i) == 0)

barcode.append("00000");

}

}

int ZipCode::getZipCode()

{

int zipcode = 0;

string zip;

zip = calcZip();

zipcode = stoi(zip);

return zipcode;

}

string ZipCode::getBarCode()

{

return barcode;

}

For this program we will represent the bar code as a string of digits. The digit 1 represents a long bar, and the digit 0 represents a short bar. Therefore, the bar code shown above would be represented in our program as: 110100101000101011000010011 The first and last digits of the bar code are always 1. Removing these leave 25 digits. If these 25 digits are split into groups of five digits each then we have: 10100 10100 01010 11000 01001 Next, consider each group of five digits. There will always be exactly two 1's in each group of digits. Each digit stands for a number. From left to right the digits encode the values 7, 4, 2, 1, and 0. Multiply the corresponding value with the digit and compute the sum to get the final encoded digit for the zip code. The table below shows the encoding for 10100. Bar Code Digits Value 1 0 1 0 0 t x Value7 02 0 0 Zip Code Digit = 7 + 0 + 2 +0+0-9 Repeat this for each group of five digits and concatenate to get the complete zip ote that there is one special value. If the sum of a group of five digits is n this represents the digit 0 (this is necessary because with two 1's per t is not possible to represent zero). The zip code for the sample bar code on Object-Oriented Programming with C++ Page 137

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!