Wrap-Up

Answers to Self Review Exercises

16.1

a) True. b) False. strings are immutable; they cannot be modified after they are created. StringBuilder objects can be modified after they are created. c) False. EnsureCapacity sets the instance's capacity to either double the current capacity or the value of its argument, whichever is larger. d) True. e) True. f) True. g) False. StringBuilder should be used if the string is to be modified. h) False. string method ToUpper creates a new string with all of its letters capitalized. i) False. The expression d in a regular expression denotes all digits.

16.2

a) +, Append, Concat. b) lexicographical. c) System.Text.RegularExpressions. d) AppendFormat e) ArgumentOutOfRangeException. f) Replace. g) currency. h) *. i) ^.

Exercises

16.3

Modify the program in Fig. 16.17 so that the card-dealing method deals a five-card poker hand. Then write the following additional methods:

  1. Determine if the hand contains a pair.
  2. Determine if the hand contains two pairs.
  3. Determine if the hand contains three of a kind (e.g., three jacks).
  4. Determine if the hand contains four of a kind (e.g., four aces).
  5. Determine if the hand contains a flush (i.e., all five cards of the same suit).
  6. Determine if the hand contains a straight (i.e., five cards of consecutive face values).
  7. Determine if the hand contains a full house (i.e., two cards of one face value and three cards of another face value).
16.4

Write an application that uses string method CompareTo to compare two strings input by the user. Output whether the first string is less than, equal to or greater than the second.

16.5

Write an application that uses random-number generation to create sentences. Use four arrays of strings, called article, noun, verb and preposition. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, noun. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the sentence is output, it should start with a capital letter and end with a period. The program should generate 10 sentences and output them to a text area.

The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the past-tense verbs "drove", "jumped", "ran", "walked" and "skipped"; and the preposition array should contain the prepositions "to", "from", "over", "under" and "on".

After the preceding program is written, modify the program to produce a short story consisting of several of these sentences. (How about the possibility of a random term-paper writer!)

16.6

(Pig Latin) Write an application that encodes English language phrases into pig Latin. Pig Latin is a form of coded language often used for amusement. Many variations exist in the methods used to form pig Latin phrases. For simplicity, use the following algorithm:

To translate each English word into a pig Latin word, place the first letter of the English word at the end of the word and add the letters "ay." Thus, the word "jump" becomes "umpjay," the word "the" becomes "hetay" and the word "computer" becomes "omputercay." Blanks between words remain blanks. Assume the following: The English phrase consists of words separated by blanks, there are no punctuation marks and all words have two or more letters. Enable the user to input a sentence. Use techniques discussed in this chapter to divide the sentence into separate words. Method GetPigLatin should translate a single word into pig Latin. Keep a running display of all the converted sentences in a text area.

16.7

Write a program that reads a five-letter word from the user and produces all possible three-letter words that can be derived from the letters of the five-letter word. For example, the three-letter words produced from the word "bathe" include the commonly used words "ate," "bat," "bet," "tab," "hat," "the" and "tea."

Graphics and Multimedia

Preface

Index

    Introduction to Computers, the Internet and Visual C#

    Introduction to the Visual C# 2005 Express Edition IDE

    Introduction to C# Applications

    Introduction to Classes and Objects

    Control Statements: Part 1

    Control Statements: Part 2

    Methods: A Deeper Look

    Arrays

    Classes and Objects: A Deeper Look

    Object-Oriented Programming: Inheritance

    Polymorphism, Interfaces & Operator Overloading

    Exception Handling

    Graphical User Interface Concepts: Part 1

    Graphical User Interface Concepts: Part 2

    Multithreading

    Strings, Characters and Regular Expressions

    Graphics and Multimedia

    Files and Streams

    Extensible Markup Language (XML)

    Database, SQL and ADO.NET

    ASP.NET 2.0, Web Forms and Web Controls

    Web Services

    Networking: Streams-Based Sockets and Datagrams

    Searching and Sorting

    Data Structures

    Generics

    Collections

    Appendix A. Operator Precedence Chart

    Appendix B. Number Systems

    Appendix C. Using the Visual Studio 2005 Debugger

    Appendix D. ASCII Character Set

    Appendix E. Unicode®

    Appendix F. Introduction to XHTML: Part 1

    Appendix G. Introduction to XHTML: Part 2

    Appendix H. HTML/XHTML Special Characters

    Appendix I. HTML/XHTML Colors

    Appendix J. ATM Case Study Code

    Appendix K. UML 2: Additional Diagram Types

    Appendix L. Simple Types

    Index



    Visual C# How to Program
    Visual C# 2005 How to Program (2nd Edition)
    ISBN: 0131525239
    EAN: 2147483647
    Year: 2004
    Pages: 600

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