{"id":35190,"date":"2016-04-06T22:24:15","date_gmt":"2016-04-07T03:24:15","guid":{"rendered":"http:\/\/diegodamy.wordpress.com\/?p=269"},"modified":"2016-04-06T22:44:12","modified_gmt":"2016-04-07T03:44:12","slug":"palindroming-all-day-long","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2016\/2016\/04\/palindroming-all-day-long\/","title":{"rendered":"Palindroming all day long"},"content":{"rendered":"<p>#TC1017 #QUIZ5<\/p>\n<p>So this was hard. This, I must say, is one of my least effective codes written so far, it\u00b4s too long, buuuuuuut it works, so I\u00b4ll take it. Basically the user inputs the word, letter by letter (ineffective!) and then my code displays it the normal way and then reversed, just so the user sees it. Then it compares index by index to check if its the same.<\/p>\n<p>The function .pushback was helpful for creating vectors of unknown size.<\/p>\n<p>The real hard part was making it case unsensitive, oh man that took a while. Ken helped me out with a magical function and everything ran just fine. Also, mek sure to #include all necessary modules.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-279\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/217707e4754fc74dd915f3cba39d87ea.jpg\" alt=\"QUIZ5.PNG\"   \/><\/p>\n<p>Source Code below:[GitHub Link: <a href=\"https:\/\/github.com\/diegodamy\/Quiz5%5D\" rel=\"nofollow\">https:\/\/github.com\/diegodamy\/Quiz5%5D<\/a><\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;ctype.h&gt;<br \/>\nusing namespace std;<\/p>\n<p>char DisplayWord (vector&lt;char&gt; word){ \/\/Outputs word in order<br \/>\nint size = word.size();<br \/>\nvector&lt;char&gt;word1;<\/p>\n<p>cout &lt;&lt; &#8220;Your word: &#8220;;<br \/>\nfor (int i = 0; i&lt;word.size(); i++){<br \/>\ncout &lt;&lt; word[i];<br \/>\n}<br \/>\n}<\/p>\n<p>vector&lt;char&gt; DisplayWordReversed (vector&lt;char&gt; word){ \/\/Outputs word in inverse order<br \/>\nint size = word.size();<br \/>\nvector&lt;char&gt;word2;<br \/>\ncout &lt;&lt; endl &lt;&lt; &#8220;Reversed: &#8220;;<\/p>\n<p>for (int i = word.size()-1; i &gt;=0; i&#8211;){<br \/>\ncout &lt;&lt; word[i];<br \/>\nword2.push_back(word[i]);<br \/>\n}<br \/>\nreturn word2; \/\/Returns value od reversed word (vector)<br \/>\n}<\/p>\n<p>char FindPalindrome (vector&lt;char&gt; word, vector&lt;char&gt; word2){ \/\/Compares indices of tow vectors: normal word and inversed word<br \/>\nint size = word.size();<br \/>\ncout &lt;&lt; endl;<br \/>\nfor (int i = 0; i&lt;word.size(); i++){<br \/>\nif (word[i] == word2[i]){<br \/>\nreturn 1; \/\/If elements of indices match, return true for palindrome<br \/>\n} else{<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>int ConvertLowerUpper (){<br \/>\nint i=0;<br \/>\nchar str[]=&#8221;Test String.n&#8221;;<br \/>\nchar c;<br \/>\nwhile (str[i])<br \/>\n{<br \/>\nc=str[i];<br \/>\nputchar (tolower(c));<br \/>\ni++;<br \/>\n}<br \/>\nreturn 0;<br \/>\n}<br \/>\nint main(){<br \/>\nchar letter;<\/p>\n<p>cout &lt;&lt; &#8220;Please enter letter by <\/p>\n<div class=\"post-limited-image\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/7daf1989a1083a429999f0deced67a0b.jpg\" \/><\/div>\n<div class=\"post-limited-image\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/9ef27a16aaf4c975d7dfd173853edfa4.jpg#038;blog=105336245&#038;%23038;post=269&#038;%23038;subd=diegodamy&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div>\n<p><!--more-->.&#8221;&lt;&lt; endl;<br \/>\ncout &lt;&lt; &#8220;To stop enter dot: .&#8221; &lt;&lt; endl;<br \/>\nvector&lt;char&gt; word;<br \/>\ncout &lt;&lt; endl &lt;&lt; &#8220;Please enter the letters:&#8221; &lt;&lt; endl;<\/p>\n<p>int i=0;<br \/>\nchar c;<\/p>\n<p>while (1){<br \/>\ncin &gt;&gt; letter;<\/p>\n<p>if(letter == &#8216;.&#8217;) {<br \/>\nbreak;<br \/>\n}<br \/>\nletter = tolower(letter);<br \/>\nword.push_back(letter);<\/p>\n<p>}<\/p>\n<p>DisplayWord(word);<\/p>\n<p>vector&lt;char&gt; v2 = DisplayWordReversed(word);<\/p>\n<p>if (FindPalindrome(word,v2) == 1){<br \/>\ncout &lt;&lt; &#8220;It is palindrome!&#8221; &lt;&lt; endl;<br \/>\n} else {<br \/>\ncout &lt;&lt; &#8220;It&#8217;s not a palindrome.&#8221; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>}<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<div class=\"html\">Photo Credit: &lt;a href=&#8221;<a href=\"https:\/\/www.flickr.com\/photos\/27067946@N00\/26150917136\/&#8221;&gt;jfhweb&lt;\/a&#038;%23038;gt\" rel=\"nofollow\">https:\/\/www.flickr.com\/photos\/27067946@N00\/26150917136\/&#8221;&gt;jfhweb&lt;\/a&#038;gt<\/a>; via &lt;a href=&#8221;<a href=\"http:\/\/compfight.com&#038;\/#8221;&gt;Compfight&lt;\/a&#038;%23038;gt\" rel=\"nofollow\">http:\/\/compfight.com&#8221;&gt;Compfight&lt;\/a&#038;gt<\/a>; &lt;a href=&#8221;<a href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/&#8221;&gt;cc&lt;\/a&#038;%23038;gt\" rel=\"nofollow\">https:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/&#8221;&gt;cc&lt;\/a&#038;gt<\/a>;<\/div>\n<p>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/diegodamy.wordpress.com\/269\/\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/7daf1989a1083a429999f0deced67a0b.jpg\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/9ef27a16aaf4c975d7dfd173853edfa4.jpg#038;blog=105336245&#038;%23038;post=269&#038;%23038;subd=diegodamy&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#TC1017 #QUIZ5 So this was hard. This, I must say, is one of my least effective codes written so far, it\u00b4s too long, buuuuuuut it works, so I\u00b4ll take it. Basically the user inputs the word, letter by letter (ineffective!) and then my code displays it the normal way and then reversed, just so the &hellip; <a href=\"https:\/\/kenscourses.com\/tc101winter2016\/2016\/04\/palindroming-all-day-long\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Palindroming all day long<\/span><\/a><\/p>\n","protected":false},"author":20,"featured_media":35204,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[209,32],"class_list":["post-35190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-quiz5","tag-tc1017"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/35190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/comments?post=35190"}],"version-history":[{"count":2,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/35190\/revisions"}],"predecessor-version":[{"id":35209,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/35190\/revisions\/35209"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media\/35204"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media?parent=35190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/categories?post=35190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/tags?post=35190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}