{"id":38365,"date":"2016-05-12T00:43:44","date_gmt":"2016-05-12T05:43:44","guid":{"rendered":"http:\/\/diegodamy.wordpress.com\/?p=340"},"modified":"2016-05-12T02:12:00","modified_gmt":"2016-05-12T07:12:00","slug":"quiz-7-dot-product","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2016\/2016\/05\/quiz-7-dot-product\/","title":{"rendered":"QUIZ 7: Dot product"},"content":{"rendered":"<p>#TC1017 #QUIZ 7<\/p>\n<p>The last of the quizzes. I wanted to import the lists from text files just to practice doing that, but I had a problem with the unknown sizes of the lists, turns out I only managed to get it working properly if I specify before hand how big each list is. Other wise it was a simple quiz for me since I was also working on my sudoku.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-344\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/c29f7621d510ae546979de3ee328aff6.jpg\" alt=\"Captura.PNG\"   \/><\/p>\n<p>Source Code:<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;fstream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;string&gt;<\/p>\n<p>using namespace std;<\/p>\n<p>int CheckIfFirstOpen(string list1){<br \/>\nifstream ListOne;<br \/>\nListOne.open(list1.c_str());<\/p>\n<p>if (ListOne.is_open()){<br \/>\nreturn 1;<br \/>\n} else {<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<\/p>\n<p>int CheckIfSecondOpen(string list2){<br \/>\nifstream ListTwo;<br \/>\nListTwo.open(list2.c_str());<\/p>\n<p>if (ListTwo.is_open()){<br \/>\nreturn 1;<br \/>\n} else {<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<\/p>\n<p>vector&lt;int&gt;ReadList1(string list1){<br \/>\nvector&lt;int&gt;List1(4);<br \/>\nifstream ListOne;<br \/>\nListOne.open(list1.c_str());<\/p>\n<p>for (int i = 0; i &lt; List1.size(); i++) {<br \/>\nListOne &gt;&gt; List1[i];<br \/>\n}<br \/>\nreturn List1;<br \/>\nListOne.close();<br \/>\n}<br \/>\nvector&lt;int&gt;ReadList2(string list2){<br \/>\nvector&lt;int&gt;List2(4);<br \/>\nifstream ListTwo;<br \/>\nListTwo.open(list2.c_str());<\/p>\n<p>for (int i = 0; i &lt; List2.size(); i++){<br \/>\nListTwo &gt;&gt; List2[i];<br \/>\n}<br \/>\nreturn List2;<br \/>\nListTwo.close();<br \/>\n}<\/p>\n<p>int DotProduct (vector&lt;int&gt;List1, vector&lt;int&gt;List2){<br \/>\nint size = 4;<br \/>\nint sum;<\/p>\n<p>for (int i = 0; i &lt; size; i++){<br \/>\nsum += List1[i] * List2[i];<br \/>\n}<br \/>\ncout &lt;&lt; &#8220;Dot product is &#8221; &lt;&lt; sum;<br \/>\n}<\/p>\n<p>int main(){<br \/>\nstring list1;<br \/>\nstring list2;<\/p>\n<p>cout &lt;&lt; &#8220;Please enter the name of the first list:&#8221; &lt;&lt; endl;<br \/>\ncin &gt;&gt; list1;<br \/>\ncout &lt;&lt; &#8220;Please enter the name of the second list:&#8221; &lt;&lt; endl;<br \/>\ncin &gt;&gt; list2;<\/p>\n<p>while (CheckIfFirstOpen(list1) == 0) {<br \/>\ncout &lt;&lt; &#8220;Unable to open first file.&#8221; &lt;&lt; endl;<br \/>\ncout &lt;&lt;&#8220;Please enter the name of the first text:&#8221; &lt;&lt; endl;<br \/>\ncin &gt;&gt; list1;<br \/>\n}<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>while (CheckIfSecondOpen(list2) == 0) {<br \/>\ncout &lt;&lt; &#8220;Unable to open second file.&#8221; &lt;&lt; endl;<br \/>\ncout &lt;&lt;&#8220;Please enter <\/p>\n<div class=\"post-limited-image\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/3baedcb3bcb319983fcb7a9a64191b0b.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\/05\/1feefe683850919f9efbe5c0c8bcb179.jpg#038;blog=105336245&#038;%23038;post=340&#038;%23038;subd=diegodamy&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div>\n<p><!--more--> name of the second text:&#8221; &lt;&lt; endl;<br \/>\ncin &gt;&gt; list2;<br \/>\n}<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>vector&lt;int&gt;List1 = ReadList1(list1);<br \/>\nvector&lt;int&gt;List2 = ReadList2(list2);<br \/>\nDotProduct(List1,List2);<\/p>\n<p>}<\/p>\n<p>GitHub link:\u00a0https:\/\/github.com\/diegodamy\/Quiz7<\/p>\n<p>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/diegodamy.wordpress.com\/340\/\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/3baedcb3bcb319983fcb7a9a64191b0b.jpg\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/1feefe683850919f9efbe5c0c8bcb179.jpg#038;blog=105336245&#038;%23038;post=340&#038;%23038;subd=diegodamy&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#TC1017 #QUIZ 7 The last of the quizzes. I wanted to import the lists from text files just to practice doing that, but I had a problem with the unknown sizes of the lists, turns out I only managed to get it working properly if I specify before hand how big each list is. Other &hellip; <a href=\"https:\/\/kenscourses.com\/tc101winter2016\/2016\/05\/quiz-7-dot-product\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">QUIZ 7: Dot product<\/span><\/a><\/p>\n","protected":false},"author":20,"featured_media":38376,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[32,249],"class_list":["post-38365","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-tc1017","tag-quiz7"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/38365","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=38365"}],"version-history":[{"count":2,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/38365\/revisions"}],"predecessor-version":[{"id":38380,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/38365\/revisions\/38380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media\/38376"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media?parent=38365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/categories?post=38365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/tags?post=38365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}