Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. /**
  2. * @author Put your name here
  3. * @date Put the date here
  4. * @file h09.cpp
  5. */
  6. #include <string>
  7. using namespace std;
  8.  
  9. string convertDigit(int zip);
  10.  
  11.  
  12. string STUDENT = "vdinh29"; // Add your Canvas/occ-email ID
  13.  
  14. #include "h08.h"
  15.  
  16. // Put your function implementation (definitions) in this file
  17. string codeForDigit(int digit)
  18. {
  19. string result;
  20. if (digit == 0)
  21. {
  22. return "||:::";
  23. }
  24. else if (digit == 1)
  25. {
  26. return ":::||";
  27. }
  28. else if (digit == 2)
  29. {
  30. return "::|:|";
  31. }
  32. else if (digit == 3)
  33. {
  34. return "::||:";
  35. }
  36. else if (digit == 4)
  37. {
  38. return ":|::|";
  39. }
  40. else if (digit == 5)
  41. {
  42. return ":|:|:";
  43. }
  44. else if (digit == 6)
  45. {
  46. return ":||::";
  47. }
  48. else if (digit == 7)
  49. {
  50. return "|:::|";
  51. }
  52. else if (digit == 8)
  53. {
  54. return "|::|:";
  55. }
  56. else if (digit == 9)
  57. {
  58. return "|:|::";
  59. }
  60. else
  61. {
  62. return "Invalid";
  63. }
  64.  
  65. return result;
  66. }
  67. int checkDigit(int zip)
  68. {
  69. int result = 0;
  70. while (zip)
  71. {
  72. result += zip % 10;
  73. zip /= 10;
  74. }
  75. result = 10 - (result % 10);
  76. return result;
  77. }
  78. string barCode(int zip) // Defining the barcode function, which will convert the whole zipcode into complete barcode.
  79. {
  80.  
  81. string result;
  82. string barCode;
  83. int finalBarint = checkDigit(zip);
  84. while (zip)
  85. {
  86. int testDigit = zip % 10;
  87. barCode = codeForDigit(testDigit) + barCode;
  88. zip /= 10;
  89. }
  90. string finalBarCode = codeForDigit(finalBarint);
  91. result = "|" + barCode + finalBarCode + "|";
  92. return result;
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /////////// Student Testing ///////////////////////
  100. #include <iostream>
  101. int run()
  102. {
  103. // You can add code that "runs" here
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement