Original code (noticed by others ):
# Include <iostream>
Using namespace STD;
// Transfer the ID card's 15-digit to 18-digit
Void per15to18 (char peridsrc [])
{
Int Is = 0;
// Weighting factor constant
Int const IW [] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
// Verification Code constant
Char const lastcode [] = "10x98765432 ";
// New ID card number
Char peridnew [19];
For (INT I = 0; I <6; I ++)
{
Peridnew [I] = peridsrc [I];
}
// Fill in the numbers '1' and '9' in the 6th and 7th digits.
Peridnew [6] = '1 ';
Peridnew [7] = '9 ';
For (INT I = 8; I <17; I ++)
{
Peridnew [I] = peridsrc [I-2];
}
// Perform weighted summation
For (INT I = 0; I <17; I ++)
{
Is + = (peridnew [I]-'0') * IW [I];
/**//*
Peridnew [I]-'0:
Peridnew [I]-> ASCII code. The obtained value is actually a decimal number;
'0'-> ASCII code, same as above;
Peridnew [I]-'0'-> to obtain the specific decimal value;
For the reason why the conversion is made, see C ++ primer.
*/
}
// Modulo operation to obtain the modulo Value
Int Iy = is % 11;
// Obtain the model-based index number from lastcode and add it to the last digit of the ID card, that is, the new ID card number.
Peridnew [17] = lastcode [Iy];
// Add the Terminator
Peridnew [18] = '\ 0 ';
Cout <"this old perid is:" <peridsrc <Endl;
Cout <"this new perid is:" <peridnew <Endl;
}
// Verify the last verification code of the ID card (this is not explained)
Void per18 (char peridsrc [])
{
Int Is = 0;
Int const IW [] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
Char const lastcode [] = "10x98765432 ";
For (INT I = 0; I <17; I ++)
{
Is + = (INT) (peridsrc [I]-'0') * IW [I];
}
Int Iy = is % 11;
Cout <"The perid is:" <peridsrc <Endl;
Cout <"the last number is:" <lastcode [Iy] <Endl;
}
Void main ()
{
Per15 to18 ("320482810923461 ");
Per18 ("410928198509022324 ");
System ("pause ");
}