Advertisement
monito2207

Untitled

Dec 2nd, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // Monika Dobrinova 8MI0600008
  2. #include <iostream>
  3. using namespace std;
  4. const int ARR_SIZE = 30;
  5. bool isLower(char c) {
  6. if (c >= 'a' && c <= 'z') {
  7. return true;
  8. }
  9. return false;
  10. }
  11. bool isUpper(char c) {
  12. if (c >= 'A' && c <= 'Z') {
  13. return true;
  14. }
  15. return false;
  16. }
  17. char ToUpper(char c) {
  18. if (isLower(c) == true) {
  19. return c - ('a' - 'A');
  20. }
  21. return c;
  22. }
  23. char ToLower(char c) {
  24. if (isUpper(c) == true)
  25. {
  26. return c + ('a' - 'A');
  27. }
  28. return c;
  29. }
  30. void my_strcpy(char* dest, const char* source)
  31. {
  32. unsigned iter = 0;
  33. while (source[iter] != '\0')
  34. {
  35. dest[iter] = source[iter];
  36. iter++;
  37. }
  38. dest[iter] = '\0';
  39. }
  40. unsigned my_strlen(const char* str)
  41. {
  42. unsigned length = 0;
  43. while (str[length] != '\0')
  44. length++;
  45. return length;
  46. }
  47. void Cipher(char str[]) {
  48. char res;
  49. int num = my_strlen(str);
  50. char buffer[ARR_SIZE];
  51. for (int i = 0; i < num; ++i)
  52. {
  53. if (isUpper(str[i]) == true)
  54. {
  55. res = ToLower(str[i]);
  56. }
  57. else if (isLower(str[i]) == true)
  58. {
  59. res = ToUpper(str[i]);
  60. }
  61.  
  62. if ((res >= 'A' && res <= 'M')|| (res >= 'a' && res <= 'm')) {
  63. res += 13;
  64. buffer[i] = res;
  65. }
  66. else if ((res >= 'N' && 'Z' <= res)|| (res >= 'n' && 'z' <= res))
  67. {
  68. res -= 13;
  69. buffer[i] = res;
  70. }
  71.  
  72. }
  73. my_strcpy(str, buffer);
  74. str[30] = '\0';
  75. }
  76.  
  77. int main()
  78. {
  79. char arr[ARR_SIZE];
  80. cin.getline(arr, ARR_SIZE-1);
  81. my_strlen(arr);
  82. Cipher(arr);
  83. for (size_t i = 0; i < 30; i++)
  84. {
  85. cout << arr[i];
  86. }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement