CST1620 C# / C++ Programming
Lab Week 9


Exercises

Exercise 11.1  Rational Exceptions (10 points)

In this exercise your are going to build upon Exercise 10/11.1 that you completed last week.

So far you have created a subclass (child class) named ProperRational that inherits from a base (super or parent) class named Rational.  You have a main Windows GUI program that tests your classes.

By nature of the working with rationals, there definitely is the possibility of a divide by zero error and also errors from parsing non numeric input from the input text boxes.

Modify your program using try - catch - finally exception handling to handle all possible errors.  Make your program bulletproof so that it can handle all input possibilities.

General programming philosophies are that methods in classes are not to have any direct interaction with the user GUI.  In other words, there should be no error pop up message boxes generated within the classes that you wrote.  However the error handling can be preprocessed in the class methods, and then throw a new Exception with a custom error message.  Write a catch block in the main Windows GUI program to actually catch the custom exceptions and display of the custom error messages and then take corrective action.

Write a main Windows GUI program (Ex11_1) to test your classes and error handling.

  Result (Save to your local machine and run)

Note:
Extra credit if you set the tab order of your input text boxes and calculate button to follow a logical order. (2 points).
 

Exercise 17.3  Triangle Area (10 points)

If you know the length of the three sides of a triangle, the area can be calculated by:

area = Math.Sqrt(s * (s - a) * (s - b) * (s - c))

where

s = (a + b + c) / 2

Write method for calculating and returning the area.  Make it throw a suitable exception (with a message) when the three lengths cannot form a triangle.

Catch input formatting errors in the main program.

Write a main Windows GUI program (Ex17_3) that catches the exceptions and takes appropriate action.

  Result (Save to your local machine and run)
 

Exercise 11.2  GUI 1 (10 points)

Write a Windows GUI program that contains these items:

  • A group of related radio buttons.
  • Another group of related radio buttons.
  • Some check boxes.
  • At least two buttons.
  • Two text boxes that display the current coordinates of your mouse when the mouse pointer is over your form.
  • Two text boxes that take a snapshot the coordinates of your mouse when you use the left click of the mouse.

Have your main program read the state of the various controls and display those states in some manner.  I would suggest just sending the states of the controls to a listBox or something similar.

  Result (Save to your local machine and run)