Advertisement
kutuzzzov

Untitled

May 19th, 2025
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <cctype>
  5.  
  6. bool isPalindrome(const std::string& str) {
  7.     std::string reversed = str;
  8.     std::reverse(reversed.begin(), reversed.end());
  9.     return str == reversed;
  10. }
  11.  
  12. int countCharacters(const std::string& str) {
  13.     return str.length();
  14. }
  15.  
  16. std::string toUpperCase(const std::string& str) {
  17.     std::string result = str;
  18.     for (char& ch : result) {
  19.         ch = std::toupper(ch);
  20.     }
  21.     return result;
  22. }
  23.  
  24. void printResults(bool isPal, int count, const std::string& upperStr) {
  25.     std::cout << "Is palindrome: " << (isPal ? "Yes" : "No") << "\n";
  26.     std::cout << "Character count: " << count << "\n";
  27.     std::cout << "Uppercase: " << upperStr << "\n";
  28. }
  29.  
  30. int main() {
  31.     std::string text = "level";
  32.  
  33.     bool isPal = isPalindrome(text);
  34.     int count = countCharacters(text);
  35.     std::string upperStr = toUpperCase(text);
  36.  
  37.     printResults(isPal, count, upperStr);
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement