I am trying to convert 5 digits of zipcode into 27 digits of barcode(composed with 0 and 1) and vice versa. The first and last digits of the bar code are always 1. Removing these leave 25 digits. Split into 5 digits each, from left to right the digits encode the values 7, 4, 2, 1, 0. If multiplied by the corresponding value with the digit and compute the sum, we can get first number of zipcode. For example, 25 digits of barcodes are 10100 10100 01010 11000 01001, the zipcode would be 99504.
1 x 7 = 7
0 x 4 = 0
1 x 2 = 2
0 x 1 = 0
0 x 0 = 0
sum = 9
// main.cpp
#include <iostream>
#include <iomanip>
#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 << "Digits" << " " << "Bar Code" << endl;
cout << zip1.getZipCode() << setw(35) << zip1.getBarCode() << endl;
cout << zip2.getZipCode() << setw(35) << zip2.getBarCode() << endl;
cout << zip3.getZipCode() << setw(35) << zip3.getBarCode() << endl;
cout << endl;
cout << zip4.getZipCode() << setw(35) << zip4.getBarCode() << endl;
cout << zip5.getZipCode() << setw(35) << zip5.getBarCode() << endl;
cout << zip6.getZipCode() << setw(35) << zip6.getBarCode() << endl;
return 0;
}
Now here is my question: In getZipCode(int num){}
, how do I compare each integer value and evaluate as barcode? For example, in main()
, it says ZipCode zip1(99504);
. Since 99504 is an integer, how do I evaluate 9 to barcode and then evaluate next one and so on?