LAB EXERCISE

 

FUN

 

 

Assignment:

 

 

 

1.   The two temperature scales used in the United States are Celsius and Fahrenheit.  The mathematical relationship between the two scales is:

 

            C = (F - 32)

 

      Write two functions, fToC and cToF, which convert temperatures from one scale to another.  For example, a call of fToC will return the equivalent Celsius temperature for a given Fahrenheit temperature.

 

            Celsius = fToC (100); // Celsius now stores 37.8

 

2.   Write a function which takes in the radius of a sphere and returns its volume.  The formula is:

 

            V = _ r3

 

      You are encouraged to use a constant for the value of _.

 

3.   Write a function which returns the hypotenuse of a right triangle given the input of the two smaller sides.  Use the Pythagorean theorem:

 

            a2 + b2 = c2

 

      Use the sqrt function to calculate the square root of a number

 

 

Instructions:

 

1. You will need to include the following header files:

 

#include <iostream.h>

#include <math.h>

#include <iomanip.h>

     

2. Round off all floating point values to two decimal places (0.01).

 

2.   Remember to write function prototypes for all four of your functions.

 

3.   You can use the following format of a cout statement to test your program:

 

      cout << "212 degrees F ---> " << fToC (212) << " degrees C" << endl;

 

      function main could be written using only 11 function calls.

 

4.   Use the following values to test your functions:

 

      Fahrenheit to Celsius:   212oF, 98.6oF, 10oF

      Celsius to Fahrenheit:   -15oC, 0oC, 70oC

      Volume of a sphere, radius of:  1.0, 2.25, 7.50

      Hypotenuse calculations:  sides of 3.0 and 4.0,  sides of 6.75 and 12.31