Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Put your name here
- * @date Put the date here
- * @file h09.cpp
- */
- #include <string>
- using namespace std;
- string convertDigit(int zip);
- string STUDENT = "vdinh29"; // Add your Canvas/occ-email ID
- #include "h08.h"
- // Put your function implementation (definitions) in this file
- string codeForDigit(int digit)
- {
- string result;
- if (digit == 0)
- {
- return "||:::";
- }
- else if (digit == 1)
- {
- return ":::||";
- }
- else if (digit == 2)
- {
- return "::|:|";
- }
- else if (digit == 3)
- {
- return "::||:";
- }
- else if (digit == 4)
- {
- return ":|::|";
- }
- else if (digit == 5)
- {
- return ":|:|:";
- }
- else if (digit == 6)
- {
- return ":||::";
- }
- else if (digit == 7)
- {
- return "|:::|";
- }
- else if (digit == 8)
- {
- return "|::|:";
- }
- else if (digit == 9)
- {
- return "|:|::";
- }
- else
- {
- return "Invalid";
- }
- return result;
- }
- int checkDigit(int zip)
- {
- int result = 0;
- while (zip)
- {
- result += zip % 10;
- zip /= 10;
- }
- result = 10 - (result % 10);
- return result;
- }
- string barCode(int zip) // Defining the barcode function, which will convert the whole zipcode into complete barcode.
- {
- string result;
- string barCode;
- int finalBarint = checkDigit(zip);
- while (zip)
- {
- int testDigit = zip % 10;
- barCode = codeForDigit(testDigit) + barCode;
- zip /= 10;
- }
- string finalBarCode = codeForDigit(finalBarint);
- result = "|" + barCode + finalBarCode + "|";
- return result;
- }
- /////////// Student Testing ///////////////////////
- #include <iostream>
- int run()
- {
- // You can add code that "runs" here
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement