{"id":531,"date":"2017-06-21T09:04:56","date_gmt":"2017-06-21T09:04:56","guid":{"rendered":"https:\/\/typedessays.com\/cartesian-datavector-homework\/"},"modified":"2017-06-21T09:04:56","modified_gmt":"2017-06-21T09:04:56","slug":"cartesian-datavector-homework","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/cartesian-datavector-homework\/","title":{"rendered":"Cartesian Data\/Vector homework"},"content":{"rendered":"<p>Cartesian Data\/Vector homework<br \/>\nSetup<br \/>\nYou will need the class files:<br \/>\n~\/cs162\/baseCode\/classes\/incl\/complex0.h<br \/>\n~\/cs162\/baseCode\/classes\/src\/complex0.cpp<br \/>\nand the Homework Exercise files:<br \/>\n~\/cs162\/lu07\/7_assign_code\/hw02\/incl\/fns02.h<br \/>\n~\/cs162\/lu07\/7_assign_code\/hw02\/src\/fns02.cpp<br \/>\n~\/cs162\/lu07\/7_assign_code\/hw02\/src\/drvr02.cpp<br \/>\nProblem Statement<br \/>\nDefine a complex class so that the following function can use it with correct results:<br \/>\n#include &lt;iostream&gt;<br \/>\nusing namespace std;<br \/>\n#include &#8220;..\/incl\/complex0.h&#8221; \/\/to avoid confusion with complex.h<\/p>\n<p>void demoComplex()<br \/>\n{<br \/>\ncomplex a( 3.0, 4.0 ); \/\/ initialize to (3, 4i)<br \/>\ncomplex c;<br \/>\ncout &lt;&lt; &#8220;Enter a complex number (q to quit):n&#8221; ;<br \/>\nwhile( cin &gt;&gt; c )<br \/>\n{<br \/>\ncout &lt;&lt; &#8220;c is &#8221; &lt;&lt; c &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;complex conjugate is &#8221; &lt;&lt; ~c &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;a is &#8221; &lt;&lt; a &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;a + c is &#8221; &lt;&lt; a + c &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;a &#8211; c is &#8221; &lt;&lt; a &#8211; c &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;a * c is &#8221; &lt;&lt; a * c &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;2 * c is &#8221; &lt;&lt; 2 * c &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;c * 2 is &#8221; &lt;&lt; c * 2 &lt;&lt; &#8216;n&#8217; ;<br \/>\ncout &lt;&lt; &#8220;Enter a complex number (q to quit):n&#8221; ;<br \/>\n}<br \/>\ncout &lt;&lt; &#8220;Done!n&#8221; ;<br \/>\n}<br \/>\nSolving the Problem<br \/>\nGeneral Approach<br \/>\nDeclare the class in the class header file. Specify the data members needed, the constructors, inspectors, mutators, and facilitators indicated by the problem statement and the requirements of the demonstration function. Declare operator overloads as needed to satisfy the needs of the demonstration function. Overloads should be non-member auxiliary functions, not member or friend functions. Declare public member functions needed by the overload functions.<br \/>\nDefine the member functions, testing each as you define it. Use the ~\/cs162\/lu07\/7_assign_code\/hw02\/src\/drvr02.cpp file for this, as well as executing the demonstration function.)<br \/>\nDeclare and define the demonstration function as specified in the Problem Statement.<br \/>\nSpecific Approach<br \/>\nNote that you have to overload the &lt;&lt; and &gt;&gt; operators for this class. Use const wherever warranted &#8211; specifically with inspector functions, and Complex objects passed as reference parameters.<br \/>\nProvide overloads for both n * c and c * n<br \/>\nA sample run of the demonstration function might produce this output:<br \/>\nEnter a complex number (q to quit):<br \/>\nreal: 10<br \/>\nimaginary: 12<br \/>\nc is (12, 12i)<br \/>\ncomplex conjugate is (10, -12i)<br \/>\na is (3, 4i)<br \/>\na + c is (13, 16i)<br \/>\na &#8211; c is (-7, -8i)<br \/>\na * c is (-18, 76i)<br \/>\n2 * c is (20, 24i)<br \/>\nc * 2 is (20, 24i)<br \/>\nEnter a complex number (q to quit):<br \/>\nreal: q<br \/>\nDone!<\/p>\n<p>Setup<br \/>\nYou will need the class files:<br \/>\n~\/cs162\/baseCode\/classes\/incl\/myvector.h<br \/>\n~\/cs162\/baseCode\/classes\/src\/myvector.cpp<br \/>\nand the Homework files<br \/>\n~\/cs162\/lu07\/7_assign_code\/hw01\/incl\/fns01.h<br \/>\n~\/cs162\/lu07\/7_assign_code\/hw01\/src\/fns01.cpp<br \/>\n~\/cs162\/lu07\/7_assign_code\/hw01\/src\/drvr01.cpp<br \/>\nProblem Statement<br \/>\nModify the Vector class header and implementation files so that the magnitude and angle are no longer stored as data components. Instead, they should be calculated on demand when the magval() and angval() methods are called.<br \/>\nSolving the Problem<br \/>\nGeneral approach:<br \/>\nLeave the public interface unchanged (the same public methods with the same arguments) but alter the private section, including the private methods and their method implementations. Test the modified version with a third version of the randwalk() function, which should be left unchanged other than using the new version of the Vector class, because the public interface of the Vector class is unchanged.<br \/>\nSpecific approach:<br \/>\nYou will find class definitions here that you built in the Topic A Exploration Exercises.<\/p>\n<p>Create a third version of the Vector class, Vector3.<\/p>\n<p>Create a new version of the randwalk() function, randwalk3(), copying the function definition you find in the Topic A Exploration Three Exercise 1 file.<br \/>\nModify the declaration for Vector3 to remove the polar coordinate data members, modify the prototypes of the private methods, and change the inline definitions of the inspectors for the now-deleted polar coordinate values.<br \/>\nThe public inspectors for polar coordinate values must now invoke the revised facilitators to get the values they compute from x-y coordinate values. These were coded as inline definitions, and can stay that way &#8211; they will still have just one statement each.<br \/>\nModify the definitions for Vector3 to update the private methods.<br \/>\nThe private methods that were originally mutators for the polar coordinate data members will need to become facilitators that compute the polar coordinate equivalents of the x-y coordinates that are stored in the class. They should be constant functions that do not modify data member values, and return double values. The existing method definitions do the correct computations, but will need to return their results rather than setting the now-deleted polar coordinate data members.<br \/>\nThe private methods that are mutators for the x-y coordinate data members can no longer read from the polar coordinate data members, but must receive polar coordinate values as method parameters. The mutator definitions do the correct computations, and will just need to be modified to work with their new input parameters.<br \/>\nWhile no public interface changes should be made, three of the public methods will need definition changes: the two constructors and the reset() method.<br \/>\nThere are no more polar coordinate data members to set in any of the three.<br \/>\nIf the input parameters are provided in polar coordinate form, they still need to be converted to x-y coordinate equivalent values before being stored in the data members. All the necessary pieces are there in the existing code, needing just slight modifications to create local variables and to pass those to the mutator functions.<br \/>\nModify the randwalk3() function to declare variables of the Vector3 class. This is the only modification needed.<br \/>\nAdd a call to randwalk3() to the Homework Exercise code file. The first two versions can still be tested through the Topic A project.<br \/>\nboth are considered 1 assaignment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cartesian Data\/Vector homework Setup You will need the class files: ~\/cs162\/baseCode\/classes\/incl\/complex0.h ~\/cs162\/baseCode\/classes\/src\/complex0.cpp and the Homework Exercise files: ~\/cs162\/lu07\/7_assign_code\/hw02\/incl\/fns02.h ~\/cs162\/lu07\/7_assign_code\/hw02\/src\/fns02.cpp ~\/cs162\/lu07\/7_assign_code\/hw02\/src\/drvr02.cpp Problem Statement Define a complex class so that the following function can use it with correct results: #include &lt;iostream&gt; using <a href=\"https:\/\/www.benedictsol.com\/blogs\/cartesian-datavector-homework\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}