{"id":14615,"date":"2024-04-27T21:00:08","date_gmt":"2024-04-27T18:00:08","guid":{"rendered":"https:\/\/elzero.org\/?p=14615"},"modified":"2024-04-16T09:31:24","modified_gmt":"2024-04-16T06:31:24","slug":"implement-functions-with-cpp-uppercase-lowercase-swapcase","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/implement-functions-with-cpp-uppercase-lowercase-swapcase\/","title":{"rendered":"UpperCase, LowerCase, SwapCase"},"content":{"rendered":"<h3>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-c\">\r\n#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\n\/\/ String To Upper Case and Lower Case and Swap Case\r\n\/\/ elzero\r\n\r\nstring to_uppercase(string st)\r\n{\r\n  string result;\r\n  for (char c : st)\r\n  {\r\n    if (c >= 'a' && c <= 'z') \/\/ This Character In Range a -> z\r\n    {\r\n      \/\/ c -= 32;\r\n      c -= ('a' - 'A');\r\n    }\r\n    result += c;\r\n  }\r\n  return result;\r\n}\r\n\r\nstring to_lowercase(string st)\r\n{\r\n  string result;\r\n  for (char c : st)\r\n  {\r\n    if (c >= 'A' && c <= 'Z') \/\/ This Character In Range A -> Z\r\n    {\r\n      \/\/ c += 32;\r\n      c += ('a' - 'A');\r\n    }\r\n    result += c;\r\n  }\r\n  return result;\r\n}\r\n\r\nstring swap_case(string st)\r\n{\r\n  string result;\r\n  for (char c : st)\r\n  {\r\n    if (c >= 'a' && c <= 'z') \/\/ This Character In Range a -> z\r\n    {\r\n      \/\/ c -= 32;\r\n      c -= ('a' - 'A');\r\n    }\r\n    else if (c >= 'A' && c <= 'Z') \/\/ This Character In Range A -> Z\r\n    {\r\n      \/\/ c += 32;\r\n      c += ('a' - 'A');\r\n    }\r\n    result += c;\r\n  }\r\n  return result;\r\n}\r\n\r\nint main()\r\n{\r\n  \/\/ cout << int('a') << endl;            \/\/ 97\r\n  \/\/ cout << int('A') << endl;            \/\/ 65\r\n  \/\/ cout << int('a') - int('A') << endl; \/\/ 97 - 65 = 32\r\n  cout << to_uppercase(\"elzero\") << endl;\r\n  cout << to_lowercase(\"ELZERO\") << endl;\r\n  cout << swap_case(\"eLZerO\") << endl;\r\n  return 0;\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1454],"tags":[],"class_list":["post-14615","post","type-post","status-publish","format-standard","hentry","category-implement-functions-with-cpp"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14615"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14615\/revisions"}],"predecessor-version":[{"id":14616,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14615\/revisions\/14616"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}