CST1620 C# / C++ Programming
Lab Week 5


Exercises

Exercise 6.1 Temperature Conversions (10 points)

Implement the following integer methods:

  1. Method Celsius returns the Celsius equivalent of a Fahrenheit temperature.
  2. Method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature.
  3. Use these methods to write a program that prints charts showing the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees.  Print the outputs in a neat tabular format the minimizes the number of lines of output while remaining readable.

You may make either a console or a Windows GUI application.

Hint:  Celsius = 5/9 * (Fahrenheit - 32)  and Fahrenheit = (9/5 * Celsius) + 32
You will need to use casting in the equation to produce correct results.

  Result (Save to your local machine and run)
Console variation

  Result (Save to your local machine and run)
Windows GUI variation

Note: Extra credit if you make both variations. (4 points).

Exercise 6.2  Rational Reduction (10 points)

Many fractions (rationals) can be reduced.  As an example, a rational with a numerator of 12 and a denominator of 16  reduces to 3/4.  Write a method named Reduce in which  you pass two parameters by reference, a numerator and a denominator.  The reduced numerator and denominator is to be returned back in the parameters that were passed by reference.  If the original rational cannot be reduced, just return the original numerator and denominator.  Incorporate your method Reduce into a Windows program.

  Result (Save to your local machine and run)

Exercise 6.10  Hypotenuse EC (Extra credit 10 points)

Define a method Hypotenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given.  The method should take two arguments of type double and return the hypotenuse as a double.  Incorporate the method into a Windows applications that reads integer values for side1 and side2 from TextBoxes and performs the calculation with the Hypotenuse method.

Test data:
Triangle  Side1  Side2
    1       3.0    4.0
    2       5.0   12.0
    3       8.0   15.0

Hint:  In a right triangle a2 + b2 = c2   where a and b are the short sides and c is the hypotenuse.