Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Monika Dobrinova 8MI0600008
- #include <iostream>
- using namespace std;
- const int ARR_SIZE = 30;
- bool isLower(char c) {
- if (c >= 'a' && c <= 'z') {
- return true;
- }
- return false;
- }
- bool isUpper(char c) {
- if (c >= 'A' && c <= 'Z') {
- return true;
- }
- return false;
- }
- char ToUpper(char c) {
- if (isLower(c) == true) {
- return c - ('a' - 'A');
- }
- return c;
- }
- char ToLower(char c) {
- if (isUpper(c) == true)
- {
- return c + ('a' - 'A');
- }
- return c;
- }
- void my_strcpy(char* dest, const char* source)
- {
- unsigned iter = 0;
- while (source[iter] != '\0')
- {
- dest[iter] = source[iter];
- iter++;
- }
- dest[iter] = '\0';
- }
- unsigned my_strlen(const char* str)
- {
- unsigned length = 0;
- while (str[length] != '\0')
- length++;
- return length;
- }
- void Cipher(char str[]) {
- char res;
- int num = my_strlen(str);
- char buffer[ARR_SIZE];
- for (int i = 0; i < num; ++i)
- {
- if (isUpper(str[i]) == true)
- {
- res = ToLower(str[i]);
- }
- else if (isLower(str[i]) == true)
- {
- res = ToUpper(str[i]);
- }
- if ((res >= 'A' && res <= 'M')|| (res >= 'a' && res <= 'm')) {
- res += 13;
- buffer[i] = res;
- }
- else if ((res >= 'N' && 'Z' <= res)|| (res >= 'n' && 'z' <= res))
- {
- res -= 13;
- buffer[i] = res;
- }
- }
- my_strcpy(str, buffer);
- str[30] = '\0';
- }
- int main()
- {
- char arr[ARR_SIZE];
- cin.getline(arr, ARR_SIZE-1);
- my_strlen(arr);
- Cipher(arr);
- for (size_t i = 0; i < 30; i++)
- {
- cout << arr[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement