Problem 1: Write a function coincount
that computes the dollar value of a number of quarters, dimes, and nickels. Use it to compute the dollar value of 18 quarters, 5 dimes, and 12 nickels.
Problem 2: Write a function hms2decimal
that converts a time in hours, minutes, and seconds and converts it to hours in decimal. Use it to calculate the decimal equivalent of 6 hours, 27 minutes, and 18 seconds.
Problem 3: Write a function decimal2hms
that converts a time in decimal hours to hours, minutes, and seconds. Use it to compute the hours, minute, and seconds equivalent of 18.782 hours.
Problem 4: Write a function polar2cartesian
that converts polar coordinates r, theta
to Cartesian coordinates x,y
. Use it to compute the Cartesian coordinates of r=2, theta=pi/6
.
Problem 5: Write a function cartesian2polar
that converts Cartesian coordinates x,y
to polar coordinates r, theta
. Use it to compute the polar coordinates of x=2, y=3
. Hint: use the arctangent function atan
to compute theta
from x
and y
.
Problem 6: Are there any values of x,y
for which your function from problem 4 fails? Try these values of (x,y)
: (1,0), (-1,0), (0,0)
. Revise cartesian2polar
function to fix these the problems these examples point out using if-else
statements, so that your function gives correct r, theta
values for all x,y
values.
Problem 7: Write a tempconvert
function that converts a temperature in any of C, F,or K units and converts it to any desired units. The function should take a single input argument t
. It should then prompt the user for the units of t
using an input
statement, prompt again for the desired units of the output, print a statement using fprintf
of the form 67 F is equivalent to 292.594 K
(where the numbers and units depend on the input values), and then return the numerical value of the temperature in the desired output units. If the input temperature is below absolute value, the program should print an error message and return absolute zero in the desired units.