1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: void encodeChar(int i, std::string& str)
5: {
6: int base = static_cast<int>('a');
7: if (isupper(str[i]))
8: base = int('A');
9: char newChar = (static_cast<int>(str[i]) − base + 3) % 26 + base;
10: try
11: {
12: str.replace(i, 1, 1, newChar);
13: }
14: catch (std::out_of_range e)
15: {
16: std::cout << "No character at position " << i << std::endl;
17: } // end try-catch
18: } // end encodeChar