{"id":36730,"date":"2016-04-30T21:44:37","date_gmt":"2016-05-01T02:44:37","guid":{"rendered":"http:\/\/everolivares.wordpress.com\/?p=262"},"modified":"2016-04-30T22:47:56","modified_gmt":"2016-05-01T03:47:56","slug":"wsq13-partial-exam-2","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2016\/2016\/04\/wsq13-partial-exam-2\/","title":{"rendered":"#WSQ13-Partial exam 2"},"content":{"rendered":"<p>Here is the partial exam answered of course jajajaja so the exam just had four questions and I will list them in order.<\/p>\n<p>QUESTION 1:<\/p>\n<div class=\"page\" title=\"Page 1\">\n<div class=\"layoutArea\">\n<div class=\"column\">\n<p>Write a function called triangles which receives a single parameter (int) which represents the size of a triangle as explained below. The function should print a triangle using loops (for or while). The only characters printed here are &#8216;T&#8217; and the new-line character. The first line is length one, the middle line is length size and the last line is length one. The example below is for size 6.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"page\" title=\"Page 1\">\n<div class=\"layoutArea\">\n<div class=\"column\">\n<pre>      T\n      TT\n      TTT\n      TTTT\n      TTTTT\n      TTTTTT\n      TTTTTT\n      TTTTT\n      TTTT\n      TTT\n      TT\n      T\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\/\/CODE<\/p>\n<p>\/\/ Ever Olivares<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\nusing namespace std;<\/p>\n<p>int triangle (int x)<br \/>\n{<br \/>\nfor (int i=1; i&lt;=x ;i++)<br \/>\n{<br \/>\nfor (int j=1; j&lt;i+1; j++)<br \/>\ncout &lt;&lt;&#8220;T&#8221;; cout &lt;&lt;endl;<br \/>\n}<br \/>\nfor (int i=x-1; i&gt;=1; i&#8211;)<br \/>\n{<br \/>\nfor (int j=1; j&lt;i+1; j++)<br \/>\ncout &lt;&lt;&#8220;T&#8221;; cout &lt;&lt;endl;<br \/>\n}<br \/>\nreturn 0;<br \/>\n}<br \/>\nint main ()<br \/>\n{<br \/>\nint y;<br \/>\nstd::cout&lt;&lt;&#8220;type the numbers of T you want&#8221; &lt;&lt;std::endl;<br \/>\nstd::cin &gt;&gt; y;<br \/>\ntriangle (y);<br \/>\n}<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-274\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/085e3c25eff52ee2ce2794932a766493.jpg\" alt=\"Captura de pantalla 2016-04-30 a las 21.38.49.png\"   \/><\/p>\n<p>QUESTION 2:<\/p>\n<p>Write a function called superpower that has two parameters of type long and returns a long which\u00a0is first parameter raised to the power of the second, which is to say it returns ab So, superpower(3,4) would return 81.<\/p>\n<p>\/\/CODE:<\/p>\n<p>\/\/ Ever Oliavres<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;cmath&gt;<\/p>\n<p>void superpower(int num1, int num2){<br \/>\nint R;<br \/>\nR= pow(3,4);<br \/>\nstd::cout &lt;&lt; &#8220;The result is&#8230; &#8220;&lt;&lt;R &lt;&lt; std::endl;<br \/>\n}<\/p>\n<p>int main(int argc, char const *argv[]) {<br \/>\nint R;<br \/>\nsuperpower(3,4);<\/p>\n<p>return 0;<br \/>\n}<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-279\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/9bbdff1e1ec4b2c5e5b5cff8401660c4.jpg\" alt=\"Captura de pantalla 2016-04-30 a las 21.40.17.png\"   \/><\/p>\n<p>QUESTION 3:<\/p>\n<p>Write a function called fibonacci which receives a long \u201cn\u201d and returns a long which is the value of the nth number in the fibonacci series which is: 0,1,1,2,3,5,8,13,21,34,55,89&#8230;&#8230;&#8230;&#8230;<span style=\"line-height:1.7;\">So, fibonacci(0) would return 0. fibonacci(5) would return 5, fibonacci(8) would return <\/p>\n<div class=\"post-limited-image\"><img decoding=\"async\" class=\"alignnone size-full wp-image-285\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/5e3958c04939820149a4e27dfe0cdd02.jpg\" alt=\"Captura de pantalla 2016-04-30 a las 21.42.16.png\"   \/><\/div>\n<div class=\"post-limited-image\"><img decoding=\"async\" class=\"alignnone size-full wp-image-290\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/d77bcdf6a271b87037d383181264d785.jpg\" alt=\"Captura de pantalla 2016-04-30 a las 21.43.21.png\"   \/><\/div>\n<div class=\"post-limited-image\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/4d1caab1af628cdf6707d4e0bed114e9.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\/595877c3f86e4c0d7e21d890037433b7.jpg#038;blog=105236756&#038;%23038;post=262&#038;%23038;subd=everolivares&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div>\n<p><!--more-->.<\/span><span style=\"line-height:1.7;\">Note that the first two fibonacci numbers are 0 and\u00a0<\/span><span style=\"line-height:1.7;\">All others are the sum of the previous two fibonacci numbers.<\/span><\/p>\n<p>\/\/CODE:<\/p>\n<p>\/\/ Ever Olivares<br \/>\n#include &lt;iostream&gt;<br \/>\nusing namespace std;<\/p>\n<p>long fibonacci(long n){<br \/>\nlong i=0,a=1,b=1,c=0;<br \/>\nif (n&lt;2){<br \/>\nreturn n;<br \/>\n}<br \/>\nif (n==2){<br \/>\nreturn 1;<br \/>\n}<br \/>\nwhile(i&lt;n-2)<br \/>\n{<br \/>\nc=a+b;<br \/>\na=b; b=c;<br \/>\ni++;}<br \/>\nreturn c;<br \/>\n}<br \/>\nint main(){<br \/>\nlong n;<br \/>\ncout&lt;&lt; &#8220;Type the number &#8221; &lt;&lt; endl;<br \/>\ncin &gt;&gt; n;<br \/>\ncout &lt;&lt; &#8220;The Fibonacci &#8221; &lt;&lt; n &lt;&lt; &#8221; position of the serie is: &#8221; &lt;&lt; endl;<br \/>\ncout&lt;&lt;fibonacci(n)&lt;&lt;endl;<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-285\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/5e3958c04939820149a4e27dfe0cdd02.jpg\" alt=\"Captura de pantalla 2016-04-30 a las 21.42.16.png\"   \/><\/p>\n<p>QUESTION 4:<\/p>\n<p>Write a function called isPalindrome which receives a string \u201cx\u201d and returns true if the string x is a palindrome, otherwise false.<\/p>\n<p>\/\/CODE:<\/p>\n<p>\/\/ Ever Oliavres<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;iomanip&gt;<br \/>\n#include &lt;string&gt;<\/p>\n<p>using namespace std;<\/p>\n<p>string word, fin;<\/p>\n<p>string is_palindrome(string word)<\/p>\n<p>{<br \/>\nstring backwards;<br \/>\ncout &lt;&lt; &#8220;Type a word: n&#8221;;<br \/>\ncin &gt;&gt; word;<\/p>\n<p>int large = word.length();<br \/>\nfor (int x = large &#8211; 1; x &gt;= 0; x&#8211;)<\/p>\n<p>{<br \/>\nbackwards += word[x];<br \/>\n}<\/p>\n<p>if (backwards == word)<br \/>\n{<br \/>\nfin = &#8220;Your word is a palindrome&#8221;;<br \/>\n}<\/p>\n<p>else<br \/>\nfin = &#8220;Your word is not a palindrome&#8221;;<br \/>\nreturn fin;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\ncout &lt;&lt; is_palindrome(fin);<br \/>\n}<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-290\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/d77bcdf6a271b87037d383181264d785.jpg\" alt=\"Captura de pantalla 2016-04-30 a las 21.43.21.png\"   \/><\/p>\n<p>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/everolivares.wordpress.com\/262\/\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/4d1caab1af628cdf6707d4e0bed114e9.jpg\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/595877c3f86e4c0d7e21d890037433b7.jpg#038;blog=105236756&#038;%23038;post=262&#038;%23038;subd=everolivares&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is the partial exam answered of course jajajaja so the exam just had four questions and I will list them in order. QUESTION 1: Write a function called triangles which receives a single parameter (int) which represents the size of a triangle as explained below. The function should print a triangle using loops (for &hellip; <a href=\"https:\/\/kenscourses.com\/tc101winter2016\/2016\/04\/wsq13-partial-exam-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">#WSQ13-Partial exam 2<\/span><\/a><\/p>\n","protected":false},"author":58,"featured_media":36754,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[25,41],"class_list":["post-36730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-uncategorized","tag-wsqs"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/36730","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\/58"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/comments?post=36730"}],"version-history":[{"count":2,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/36730\/revisions"}],"predecessor-version":[{"id":36764,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/36730\/revisions\/36764"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media\/36754"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media?parent=36730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/categories?post=36730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/tags?post=36730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}