Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. /**
  2.  *  @author Mghazzawi
  3.  *  @date 2/13/2020
  4.  *  @file h07.cpp
  5.  */
  6. #include <string>
  7. using namespace std;
  8.  
  9. string STUDENT = "mghazzawi"; // Add your Canvas/occ-email ID
  10.  
  11. #include "h08.h"
  12.  
  13. // Put your function implementation (definitions) in this file
  14. string barCode(int zip)
  15. {
  16.     string result;
  17.     int base = zip;
  18.     int check = checkDigit(base);
  19.     int digit;
  20.     for( int i = 0; i < 5; i++)
  21.     {
  22.         digit = base % 10;
  23.         base = base/10;
  24.         result = codeForDigit(digit) + result;
  25.     }
  26.     result = "|" + result + codeForDigit(check) + "|";
  27.     return result;
  28. }
  29. string codeForDigit(int digit)
  30. {
  31.     string result;
  32.     switch(digit)
  33.     {
  34.         case 1:
  35.             result = ":::||";
  36.             break;
  37.         case 2:
  38.             result = "::|:|";
  39.             break;
  40.         case 3:
  41.             result = "::||:";
  42.             break;
  43.         case 4:
  44.             result = ":|::|";
  45.             break;
  46.         case 5:
  47.             result = ":|:|:";
  48.             break;
  49.         case 6:
  50.             result = ":||::";
  51.             break;
  52.         case 7:
  53.             result = "|:::|";
  54.             break;
  55.         case 8:
  56.             result = "|::|:";
  57.             break;
  58.         case 9:
  59.             result = "|:|::";
  60.             break;
  61.         case 10:
  62.             result = "|:|:::;
  63.            break;
  64.        case 0:
  65.            result = "||:::";
  66.            break;
  67.    }
  68.  
  69.    return result;
  70. }
  71. int checkDigit(int zip)
  72. {
  73.    int sumOfDigit = 0;
  74.    while(zip)
  75.    {
  76.        sumOfDigit += (zip % 10);
  77.        zip /= 10;
  78.    }
  79.    zip = 10 - (sumOfDigit % 10);
  80.    return zip;
  81. }
  82.  
  83.  
  84.  
  85. /////////// Student Testing ///////////////////////
  86. #include <iostream>
  87. int run()
  88. {
  89.    // You can add code that "runs" here
  90.    return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement