Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void convertAllCharacter(char str[])
- {
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] >= 'A' && str[i] <= 'Z')
- {
- str[i] += 32;
- }
- else if (str[i] >= 'a' || str[i] <= 'z')
- {
- str[i] -= 32;
- }
- }
- cout << str << endl;
- }
- void convertAllToUpperOrLower(char str[])
- {
- unsigned short choose = 0;
- do
- {
- cout << "1 -[lower to upper]\n2 - [upper to lower]\n";
- cin >> choose;
- } while (choose < 1 || choose >> 2);
- switch (choose)
- {
- case 1:
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] >= 'a' && str[i] <= 'z')
- {
- str[i] -= 32;
- }
- }
- break;
- case 2:
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] >= 'A' && str[i] <= 'Z')
- {
- str[i] += 32;
- }
- }
- default:
- break;
- }
- cout << str << endl;
- }
- bool isPalindrom(char str[])
- {
- for (int i = strlen(str) - 1; i >= 0; i--) {
- if (str[i] != str[(strlen(str) - 1) - i]) {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- char str[20];
- unsigned int choose;
- cout << "Enter value of char string: ";
- cin >> str;
- do
- {
- cout << "Enter value of function:\n[1] lower to upper and upper to lower:\n[2] lower to upper or upper to lower:\n[3] is Palindrom ?\n";
- cin >> choose;
- switch (choose)
- {
- case 1:
- convertAllCharacter(str);
- choose = -1;
- break;
- case 2:
- convertAllToUpperOrLower(str);
- choose = -1;
- break;
- case 3:
- if (isPalindrom(str)) {
- cout << "This char string is palindrom" << endl;
- }
- else {
- cout << "This char string is not palindrom" << endl;
- }
- choose = -1;
- break;
- default:
- break;
- }
- } while (choose < 0 || choose > 6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement