CST2602 Visual Basic II
Assignments


Turn your homework in on a CD-ROM.  You must label the CD-ROM with your name, assignment number, and course number.  Be sure to keep a backup for yourself.

Note:  Most of the programming examples in the textbook can be found on the CD-ROM included with the book.

 

Lab 1

Read (Bell&Parr) Chapters 11 & 24  - Inheritance and Polymorphism.
Read (Deitel) Chapters 9 & 10  - Inheritance & Polymorphism.

 

Exercises

Exercise RationalInheritance (20 points)

In this exercise your are going to build upon Exercise RationalCalculations that you completed in VB I week 7.


You had created a class named Rational for performing arithmetic with fractions. 

You provided public member functions (methods) that performed each of the following tasks:

  • Adding two Rational numbers.  The result should be stored in reduced form.
  • Subtracting two Rational numbers.  The result should be stored in reduced form.
  • Multiplying two Rational numbers.  The result should be stored in reduced form.
  • Dividing two Rational numbers.  The result should be stored in reduced form.
  • Returning a Rational number in floating-point (double) format.
  • Returning a string representing a Rational number in the form a/b, where a is the numerator and b is the denominator.

You had provided a private member function named Reduce.

You provided get accessors to be able to retrieve the numerator and denominator variables.

And you wrote a main Windows GUI program to test your class.


This week for exercise RationalInheritance you are to create a new class named ProperRational that inherits from your previously made class named Rational.  So in other words you are making a subclass named ProperRational from a base class named Rational.

This new class is to extend the functionality of Rational class by providing the ability to store all rationals properly by using whole numbers if necessary and where no numerator shall be larger than the denominator.  Also the negative sign needs to be applied to the whole number, if there is a non zero whole number.  If the whole number is zero, then the negative sign shall be applied to the numerator.

The only changes that you should need to make with your class Rational will be to make a couple of the class variables protected and the method Reduce protected.  The rest of the class should be untouched.

For your new class ProperRational, you need to provide public member functions (methods) that performed each of the following tasks:

  • Adding two ProperRational numbers.  The result should be stored in reduced form.  Use the add method from the Rational class as a helper method.
  • Subtracting two ProperRational numbers.  The result should be stored in reduced form.  Use the subtract method from the Rational class as a helper method.
  • Multiplying two ProperRational numbers.  The result should be stored in reduced form.  Use the multiply method from the Rational class as a helper method.
  • Dividing two ProperRational numbers.  The result should be stored in reduced form.  Use the divide method from the Rational class as a helper method.
  • Returning a ProperRational number in floating-point (double) format.
  • Returning a string representing a ProperRational number in the form w n/d, where w is the whole (if there is one) and n is the numerator and d is the denominator.

Provide a private member function named Reduce  to reduce ProperRationals.  Reuse the reduce function from the Rational class as a helper function.

In all of the above methods, call upon the base class methods to perform the bulk of the work.

Provide a get accessor to be able to retrieve the whole variable.

Write a main Windows GUI program (RationalInheritance) to test your class.

To get you started, I am providing much of the ProperRational class  for you in this file.  So pretty much all is left is for you to complete the member functions.  The add function has been done for you already.  Also notice I made some private helper functions to take care of the signs.  Here is most of my code for my main windows GUI to test the class.  For clarity I removed most of the "Windows Form Designer generated code" and the code for the switch button.

  Result (Save to your local machine and run)


Lab 2

Read (Deitel) Chapter 14 Multithreading.

 

Exercises

Exercise Multithreading (20 points)

In this exercise your are going to build upon Exercise 5.6 (Pythagorean Triples) that you completed in VB I

Basically you are to duplicate the Pythagorean Triples program logic 3 times (or more).  Run each duplication of the logic as a separate thread.  Review my example programs  to get a better understanding of the problem.

Write a main Windows GUI program (Multithreading) to test your multithreading.

Use the Windows Task Manager to see the effectiveness of your multithreading.  If your application is written correctly, your program should have a CPU usage of at least 80%, but probably not more than 95%.

  Result (Save to your local machine and run)  This is the program before it is multithreaded.  It uses the DoEvents method to help responsiveness.  However this solution is not as responsive as it should be.  Also the programmer has no control over the wait period.

  Result (Save to your local machine and run)  This is the program written using multithreading.  The programmer has the ability to control processor loading and overall responsiveness is increased.

Note:
At first it appeared that if I clicked start button many times in succession for a set of program logic, that the threads were interfering with each other.  You would see unusual results in the list box.  But on further examination, the threads are running independently just fine.  The list box is just being written to by multiple threads executing at the same time.
 


Lab 3

Read (Deitel) Chapter 22 Networking: Streams-Based Sockets and Datagrams.

Exercises

Exercise TicTacToe (20 points)

In Chapter 22 of Deitel there is an example program of Tic-Tac-Toe that is set up as a client/server and is to be played on two computers.  Use this program as your base program for this exercise.

Modify the program in some way with interesting graphics, sounds, score keeping, etc.

Package package and deploy the program with the Windows Installer (.msi) so that anyone with Windows 98 or better can run your program.

Give your instructor the packaged program on CD so that your instructor can install the program.  Demonstrate to the instructor that the program will work across the internet.  Your laptop will be one machine and the instructor's laptop will be the other.