CSCI 261 - Programming Concepts - Summer 2019

Lab 5B - Polar to Cartesian

This lab is due by Friday, May 31, 2019 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab.


Instructions


Create a new project and call it Lab5B. One of the limitations of functions is that they can only return a single value. A workaround to this limitation is to pass parameters by reference. When the function completes, the arguments corresponding to these parameters will contain the modified values. A generic function prototype would match the following template:

void functionName( const dataType inParam1, const dataType inParam2, // input to the function
                   dataType& outParam1, dataType& outParam2 );       // output from the function

We will create two functions called polarToCartesian and cartesian2Polar that match this format. Begin by reviewing the Polar to Cartesian Conversion equations.

Your program should first prompt the user which direction they wish to convert, either
(r, θ) -> (x, y)
or
(x, y) -> (r, θ)
Prompt the user to input the values on the left hand side and then call the corresponding function to compute the right hand side. Display these values to the user.

Your functions must match the following specifications:

    • Function Name: polarToCartesian
    • Input: Double passed by constant value corresponding to the radius, Double passed by constant value corresponding to the angle, Double passed by reference corresponding to the x-coord, Double passed by reference corresponding to the y-coord
    • Output: None
    • Description: Converts polar (r, θ) to cartesian (x, y).

    • Function Name: cartesianToPolar
    • Input: Double passed by constant value corresponding to the x-coord, Double passed by constant value corresponding to the y-coord, Double passed by reference corresponding to the radius, Double passed by reference corresponding to the angle
    • Output: None
    • Description: Converts cartesian (x, y) to polar (r, θ).


Lab Submission



You will submit your solution to this lab with the rest of Set5. Detailed instructions for doing this are posted in Assignment 5.


This lab is due by Friday, May 31, 2019 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab.