Verhoeff algorithm: Difference between revisions
→{{header|C++}}
Line 235:
#include <iostream>
#include <string>
#include <array>
typedef std::pair<std::string, bool> data;
const std::array<const std::array<int32_t, 10>, 10> multiplication_table = { {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
{ 1, 2, 3, 4, 0, 6, 7, 8, 9, 5 },
Line 249 ⟶ 250:
{ 8, 7, 6, 5, 9, 3, 2, 1, 0, 4 },
{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }
} };
const std::array<const std::array<int32_t, 10>, 8> permutation_table = { {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
{ 1, 5, 7, 6, 2, 8, 3, 0, 9, 4 },
Line 262 ⟶ 263:
{ 2, 7, 9, 3, 8, 0, 6, 4, 1, 5 },
{ 7, 0, 4, 6, 9, 1, 3, 2, 5, 8 }
} };
if ( doDisplay ) {
std::string calculationType = doValidation ? "Validation" : "Check digit";
Line 276 ⟶ 277:
}
const
for (
const
const
c = multiplication_table[c][pi];
Line 296 ⟶ 297:
int main( ) {
const std::array<data,
std::make_pair("123", true), std::make_pair("12345", true), std::make_pair("123456789012", false) };
for ( data test : tests ) {
std::cout << "The check digit for " << test.first << " is " << digit << "\n" << std::endl;
|