CST1620 C# / C++ Programming
Lab Week 11


Notes

Regular expressions can simplify extracting data from a string if used properly.

Regular Expression Library.

Regular Expression online tester.

 

Exercises

Exercise 16.10  Phone Parse (10 points)

Write a program that accepts a 10 digit phone number.  3 digits for the area code, 3 digits for the exchange, and 4 digits for the local.

Parse the phone number in such a way that the user has flexibility for entering the number in many of the common forms in use today.

Examples:
(320) 555-1212
320-555-1212
320 555 1212
320.555.1212

Hint:
Read the input as a string from a textbox.  Convert the string to a character array.  Parse the character array.
Solve this problem using regular expressions.

Write a main Windows GUI program (Ex16_10) to test your parsing.

  Result (Save to your local machine and run) 
 

Exercise 16.6  Number String (10 points)

Write a  program which allows input of the form:

12 + 345 - 44 - 23 - 57 + 2345

can be handled.  Assume that the user will make no error in entering the string of numbers and operators.  The operators are limited to be only addition and subtraction.

Hint: The patter of such input is an initial number, followed by any number of operator/number pairs.  Your program should handle the initial number, then loop to handle the following pairs of operators and numbers.

Write a main Windows GUI program (Ex16_6) to produce the result.

  Result (Save to your local machine and run) 
 

Exercise 15.3  Poker Hand EC (Extra Credit 20 points)

Modify the program in Figure 15.18 of the C# How to Program textbook (Deitel ) so that the card dealing method deals a five card poker hand.  Then write the following additional methods:

  • Determine if the hand contains a pair.
  • Determine if the hand contains two pars.
  • Determine if the hand contains three of a kind (e.g. three jacks).
  • Determine if the hand contains four of a kind (e.g. four aces).
  • Determine if the hand contains a flush (i.e. all five cards of the same suit).
  • Determine if the hand contains a straight (i.e. five cards of consecutive face values).
  • Determine if the hand contains a full house (i.e. two cards of one face value and three cards of another face value).

Write a main Windows GUI program (Ex15_3) to test your hands.