Programming Exercises

   


1:

Add a static method called Product to the Math class in Listing 20.1. This method must calculate the product of two parameters and be encapsulated by instances of the Calculation delegate. Write the code for testing this method with the delegate.

2:

Write a program similar to Listing 20.2. This time, instead of letting a number be manipulated by three different math operations, let the program allow an initial single letter to be manipulated by the three following string operations: "Add an 'A' to the string", "Add a B to the string", and "Add a C to the string". Allow the user to put together any sequence of string operations with a maximum of twenty operations.

3:

Expand Listing 20.4 with another subscriber class called Motorbike. Allow Motorbike objects to subscribe to the events fired by the GameController object by equipping it with a suitable event handler and so forth, similar to the Car class. Program the event handler so that when one of the signals MoveRequestType.FastForward or MoveRequestType.SlowForward are received, the Motorbike object moves forward by 30. If the MoveRequestType.Reverse is received, reverse the Motorbike object by 3 kilometers. Allow the user to add and remove Motorbike objects similar to that of the Car objects.


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net