Starting from:
$35

$29

PS3 Solution

Q1

A point in the plane requires two coordinates. We could choose from many coordinate systems. The two that are most familiar are rectangular and polar. We choose rectangular coordinates (two double values representing distances from the point in question to perpendicular coordinates). Conversion the internal representation of this class from rectangular to polar coordinates should be an excellent problem for students who are reasonably prepared. These members should be implemented:

    • a member function, set, to set the private data after creation

    • a member function to move the point a vertical distance and a horizontal distance specified by the first and second arguments.
    • a member function that rotates the point 90 degrees clockwise about the origin.

    • two const inspector functions to retrieve the current coordinates of the point.

Document the member functions.

Test with several points exercise member functions.




Q2

Define a class for a type called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of numerator / denominator as a double. Include an additional member function that outputs the value of the fraction reduced to lowest terms, e.g. instead of outputting 20/60 the method should output 1/3. This will require finding the greatest common divisor for the numerator and denominator, and then dividing both by that number. Embed your class in a test program.



Turn In

    • Make and submit a zip file(<your_full_name>_PS3.zip) which includes the following:

– Source code of Q1: q1.cpp

– Source code of Q2: q2.cpp

– Run Q1 and Q2 and attach screenshots(in jpg format, not exceeding 300kb each) which show that your programs are running.
– At least 1 screenshot for each question.





















1

More products