CST1801 Visual Basic I
Lab Week 5


Exercises

Exercise RationalReduction (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 (subroutine) 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.  Remember to accept negatives for numerators and denominators.  Reduce the signs as well.  A resulting negative sign, if there is one, should be attached to the numerator.  Incorporate your method (subroutine) Reduce into a Windows program.

  Result (Save to your local machine and run)

Exercise TemperatureConversions EC Extra credit (10 points)

Implement the following integer functions:

  1. Function Celsius returns the Celsius equivalent of a Fahrenheit temperature.
  2. Function Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature.
  3. Use these functions 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 extra credit if you make both variations. (4 points).

Exercise  TrafficLight (10 points)

8 seconds 2 seconds 0.5 seconds 8 seconds 2 seconds 0.5 seconds

Above are the 6 states of a set of typical traffic lights.  Write a program to simulate a set of traffic lights.  Use timers to do this.

  Result (Save to your local machine and run)