// The isalpha and isupper functions are standard library functions. Their brief functions are as follows:
Int islower (int c)
{
Return 'A' <= C & C <= 'Z ';
}
Int isupper (int c)
{
Return 'A' <= C & C <= 'Z ';
}
Int isalpha (int c)
{
Return islower (c) | isupper (C );
}
// The testxxxx function is a test case.
//////////////////////////////////////// ////////////////////////
# Include <assert. h>
# Include <ctype. h>
# Include <stdio. h>
Char postpone (char orig, int distance)
{
// Do not process non-letters
If (isalpha (orig) = 0)
{
Return orig;
}
Int d = distance % 26;
Char Top = (isupper (orig )? 'Z': 'Z')-D;
// Imply orig <base + 4 because isalpha (orig)
If (orig> top)
{
D-= 26;
}
# Ifndef ndebug
Printf ("If '% C' [% 3d]>' % C' [% 3d] Then put off % 3d get % C [% 3d] n", orig, orig, top, top, D, orig + D, orig + D );
# Endif
Return orig + D;
}
Void testpostponenonealpha ()
{
Assert (postpone ('', 4) = '');
Assert (postpone ('_', 4) = '_');
Assert (postpone ('~ ', 4) = '~ ');
}
Void testpostpone4letter ()
{
Assert (postpone ('A', 4) = 'E ');
Assert (postpone ('A', 4) = 'E ');
Assert (postpone ('V', 4) = 'Z ');
Assert (postpone ('V', 4) = 'Z ');
Assert (postpone ('w', 4) = 'A ');
Assert (postpone ('w', 4) = 'A ');
Assert (postpone ('Z', 4) = 'D ');
Assert (postpone ('Z', 4) = 'D ');
}
Void testpostpone0letter ()
{
Assert (postpone ('V', 0) = 'V ');
Assert (postpone ('V', 0) = 'V ');
Assert (postpone ('w', 0) = 'W ');
Assert (postpone ('w', 0) = 'W ');
Assert (postpone ('Z', 0) = 'Z ');
Assert (postpone ('Z', 0) = 'Z ');
}
Int main ()
{
Testpostponenonealpha ()
Testpostpone4letter ();
Testpostpone0letter ();
Return 0;
}