STARTING OUT WITH Visual C# - Pearson

Transcription

STARTING OUT WITHVisual C# Fifth EditionTony GaddisHaywood Community CollegeA01 GADD3519 05 SE FM.indd 104/01/19 5:40 PM

Senior Vice President Courseware PortfolioManagement: Marcia J. HortonDirector, Portfolio Management: Engineering,Computer Science & Global Editions: JulianPartridgePortfolio Manager: Matt GoldsteinPortfolio Management Assistant: Meghan JacobyManaging Content Producer: Scott DisannoContent Producer: Carole SnyderRights and Permissions Manager: Ben FerriniManufacturing Buyer, Higher Ed, Lake SideCommunications, Inc. (LSC): Maura Zaldivar-GarciaInventory Manager: Bruce BoundyProduct Marketing Manager: Yvonne VannattaField Marketing Manager: Demetrius HallMarketing Assistant: Jon BryantCover Designer: IntegraCover Photo: Akepong Srichaichana/ShutterstockPrinter/Binder: LSC Communications, Inc.Full-Service Project Management: Abhishan Sharma, IntegraCopyright 2020 by Pearson Education, Inc. or its affiliates. All Rights Reserved. Printed in the United States of America. Thispublication is protected by copyright, and permission should be obtained from the publisher prior to any prohibitedreproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,recording, or otherwise. For information regarding permissions, request forms and the appropriate contacts within the PearsonEducation Global Rights & Permissions department, please visit www.pearsoned.com/permissions.Acknowledgements of third party content appear the same page as the content, which constitutes an extension of this copyrightpage. Unless otherwise indicated herein, any third-party trademarks that may appear in this work are the property of theirrespective owners and any references to third-party trademarks, logos or other trade dress are for demonstrative or descriptivepurposes only. Such references are not intended to imply any sponsorship, endorsement, authorization, or promotion ofPearson’s products by the owners of such marks, or any relationship between the owner and Pearson Education, Inc. or itsaffiliates, authors, licensees or distributors.The programs and applications presented in this book have been included for their instructional value. They have been testedwith care, but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations,nor does it accept any liabilities with respect to the programs or applications.Library of Congress Cataloging-in-Publication DataNames: Gaddis, Tony, author.Title: Starting out with visual C# / Tony Gaddis, Haywood Community College.Description: Fifth edition. Hoboken, NJ : Pearson, [2020] Includes index.Identifiers: LCCN 2018048218 ISBN 9780135183519 ISBN 0135183510Subjects: LCSH: C# (Computer program language) Visual programming languages(Computer science)Classification: LCC QA76.73.C154 G33 2019 DDC 005.1/18--dc23 LC record available athttps://lccn.loc.gov/201804821810 9 8 7 6 5 4 3 2 1ISBN 10:0-13-518351-0ISBN 13: 978-0-13-518351-9A01 GADD3519 05 SE FM.indd 204/01/19 5:40 PM

Locations of pter 1 Tutorial 1-1: Starting Visual Studio and SettingUp the Environment 28Tutorial 1-2: Starting a New Visual C# Project 30Tutorial 1-3: Saving and Closing a Project 32Tutorial 1-4: Opening an Existing Project 40Tutorial 1-5: Getting Familiar with the VisualStudio Environment 41Chapter 2Tutorial 2-1: Creating the GUI for the Hello World Application 61Tutorial 2-2: Writing Code for the Hello World Application 75Tutorial 2-3: Creating the Language Translator Application 86Tutorial 2-4: Creating the Flags Application 94Tutorial 2-5: Creating the Card Flip Application 98Solving the Clickable Number Images Problem 113Chapter 3Tutorial 3-1: The Birth Date String Application 126Tutorial 3-2: Calculating Fuel Economy 147Tutorial 3-3: Creating the Sale Price Calculator Applicationwith Currency Formatting 153Tutorial 3-4: Creating the Test Average Applicationwith Exception Handling 161Tutorial 3-5: Creating the Change Counter Application 170Tutorial 3-6: Single-stepping through an Application’sCode at Runtime 186Solving the Tip, Tax, and Total Problem 196Chapter 4Tutorial 4-1: Completing the Test Score Average Application 206Tutorial 4-2: Completing the Payroll with Overtime Application 212Tutorial 4-3: Completing the Loan Qualifier Application 218Tutorial 4-4: Calculating Fuel Economy 241Tutorial 4-5: Creating the Color Theme Application 250Tutorial 4-6: Creating the Time Zone Application 257Solving the Mass and Weight Problem 266Chapter 5Tutorial 5-1: Using a Loop to Calculate an Account Balance 277Tutorial 5-2: Enhancing the Ending Balance Application 280Tutorial 5-3: Using the for Loop 290Tutorial 5-4: Writing Data to a Text File 301Tutorial 5-5: Appending Data to the Friend.txt File 306Tutorial 5-6: Using a Loop to Read to the End of a File 314Tutorial 5-7: Calculating a Running Total 318Tutorial 5-8: Simulating Coin Tosses 328Tutorial 5-9: Creating a Load Event Handler 333Solving the Celsius to Fahrenheit Table Problem 340iiiA01 GADD3519 05 SE FM.indd 304/01/19 5:40 PM

ivLocations of VideoNotesChapter 6Tutorial 6-1: Creating and Calling Methods 349Tutorial 6-2: Passing an Argument to a Method 356Tutorial 6-3: Using an Output Parameter 367Tutorial 6-4: Writing a Value-Returning Method 376Tutorial 6-5: Modularizing Input Validation with a BooleanMethod 379Tutorial 6-6: Practicing the Step Into Command 385Tutorial 6-7: Practicing the Step Over Command 386Tutorial 6-8: Practicing the Step Out Command 387Solving the Kinetic Energy Problem 392Chapter 7 Tutorial 7-1: Using an Array to Hold a List of RandomLottery Numbers 407Tutorial 7-2: Processing an Array 432Tutorial 7-3: Completing the Seating Chart Application 447Tutorial 7-4: Completing the Test Score List Application 460Tutorial 7-5: Completing the Random Card Application 467Solving the Total Sales Problem 474Chapter 8 Tutorial 8-1: Completing the Password ValidationApplication 485Tutorial 8-2: Completing the Telephone Format Application 498Tutorial 8-3: Completing the Telephone Unformat Application 502Tutorial 8-4: Completing the CSV Reader Application 509Solving the Sum of Numbers in a String Problem 522Chapter 9Tutorial 9-1: Completing the Phonebook Application 535Tutorial 9-2: Completing the Color Spectrum Application 552Tutorial 9-3: Storing Names and Birthdays in a Dictionary: 564Tutorial 9-4: Using a Dictionary to Simulate a Deck of Cards 566Solving the Course Information Problem 578Chapter 10Tutorial 10-1: Creating and Using the Coin Class 588Tutorial 10-2: Creating and Using the CellPhone Class 598Tutorial 10-3: Creating and Using the BankAccount Class 603Tutorial 10-4: Completing the Cell Phone InventoryApplication 612Tutorial 10-5: Creating an Application with Two Forms 630Tutorial 10-6: Accessing a Control on a Different Form 635Tutorial 10-7: Creating a Simple Logging Utility with a StaticClass: 643Solving the Pet Class Problem 652Chapter 11 Tutorial 11-1: Creating and Testing the SavingsAccount andCDAccount Classes 664Tutorial 11-2: Completing the Polymorphism Application 677Tutorial 11-3: Completing the Computer Science StudentApplication 684Solving the Employee and Production–Worker ClassesProblem 712Chapter 12 Tutorial 12-1: Starting the Phone Book Application and Creatingthe Phonelist.mdf Database 721Tutorial 12-2: Completing the Phone Book Application 729A01 GADD3519 05 SE FM.indd 404/01/19 5:40 PM

Locations of VideoNotesvTutorial 12-3: Creating the Products Application and Using aDetails View 738Tutorial 12-4: Creating the Product Lookup Application 749Tutorial 12-5: Creating the Multiform Products Application 752Tutorial 12-6: Creating the Product Queries Application 764Tutorial 12-7: Creating the Product Queries Application 773Tutorial 12-8: Creating the Product Search Application 777Solving the Personnel Database Problem 787A01 GADD3519 05 SE FM.indd 5Chapter 13Tutorial 13-1: Working with List Methods and Lambdas 811Solving the List Manipulator Problem 818Chapter 14Tutorial 14-1: Completing the Student Roster Application 827Tutorial 14-2: Modifying the Student Roster Application 835Tutorial 14-3: Completing the Team Player Application 849Tutorial 14-4: Completing the Phonelist Names Application 859Tutorial 14-5: Completing the Product Reports Application 864Tutorial 14-6: Completing the Query Data SourceApplication 871Solving the Unique Words Problem 88104/01/19 5:40 PM

Brief ContentsChapter 1Introduction to Computers and Programming Chapter 2Introduction to Visual C# Chapter 3Processing Data 117Chapter 4Making Decisions 201Chapter 5Loops, Files, and Random Numbers 271Chapter 6Modularizing Your Code with Methods 343Chapter 7Arrays and Lists 397Chapter 8Text Processing 479Chapter 9Structures, Enumerated Types, and Dictionaries 525Chapter 10Introduction to Classes 581Chapter 11Inheritance, Polymorphism, and Interfaces 655Chapter 12Databases 715Chapter 13Delegates, Anonymous Methods, andLambda Expressions 789Chapter 14Language-Integrated Query (LINQ) 821Appendix AC# Primitive Data Types 883Appendix BAdditional User Interface Controls 885Appendix CASCII/Unicode Characters 905Appendix D Answers to Checkpoint Questions Appendix EIndex Installing LINQ to SQL Classes in Visual Studio 151907929931viA01 GADD3519 05 SE FM.indd 604/01/19 5:40 PM

ContentsPrefacexiiiAttention Students xxChapter 1Introduction to Computers and Programming1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Hardware and Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2How Computers Store Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7How a Program Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Graphical User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21The Program Development Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Getting Started with the Visual Studio Environment . . . . . . . . . . . . . . . . . . . 27TUTORIAL 1-1: Starting Visual Studio and Setting Up the Environment 28TUTORIAL 1-2: Starting a New Visual C# Project 30TUTORIAL 1-3: Saving and Closing a Project 32TUTORIAL 1-4: Opening an Existing Project 40TUTORIAL 1-5: Getting Familiar with the Visual Studio Environment 41Key Terms 43 Review Questions 44 Programming Problems 491.11.21.31.41.51.61.71.8Chapter 2Introduction to Visual C#   512.1 Getting Started with Forms and Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 512.2 Creating the GUI for Your First Visual C# Application:The Hello World Application 60TUTORIAL 2-1: Creating the GUI for the Hello World Application 612.3 Introduction to C# Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652.4 Writing Code for the Hello World Application . . . . . . . . . . . . . . . . . . . . . . . . 75TUTORIAL 2-2: Writing Code for the Hello World Application 752.5 Label Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78TUTORIAL 2-3: Creating the Language Translator Application 862.6 Making Sense of IntelliSense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892.7 PictureBox Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90TUTORIAL 2-4: Creating the Flags Application 94TUTORIAL 2-5: Creating the Card Flip Application 982.8 Comments, Blank Lines, and Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . 1022.9 Writing the Code to Close an Application’s Form . . . . . . . . . . . . . . . . . . . . 1042.10 Dealing with Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105Key Terms 107 Review Questions 107 Programming Problems 112viiA01 GADD3519 05 SE FM.indd 704/01/19 5:40 PM

viiiContentsChapter 3Processing Data  1173.1 Reading Input with TextBox Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1173.2 A First Look at Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120TUTORIAL 3-1: The Birth Date String Application 1263.3 Numeric Data Types and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1313.4 Performing Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1373.5 Inputting and Outputting Numeric Values . . . . . . . . . . . . . . . . . . . . . . . . . 142TUTORIAL 3-2: Calculating Fuel Economy 1473.6 Formatting Numbers with the ToString Method . . . . . . . . . . . . . . . . . . . . 150TUTORIAL 3-3: Creating the Sale Price Calculator Application withCurrency Formatting 1533.7 Simple Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157TUTORIAL 3-4: Creating the Test Average Application withException Handling 1613.8 Using Named Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1653.9 Declaring Variables as Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166TUTORIAL 3-5: Creating the Change Counter Application 1703.10 Using the Math Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1743.11 More GUI Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1763.12 Using the Debugger to Locate Logic Errors . . . . . . . . . . . . . . . . . . . . . . . . . 185TUTORIAL 3-6: Single-stepping through an Application’s Code at Runtime 185Key Terms 191 Review Questions 191 Programming Problems 196Chapter 4Making Decisions  2014.1 Decision Structures and the if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 201TUTORIAL 4-1: Completing the Test Score Average Application 2064.2 The if-else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210TUTORIAL 4-2: Completing the Payroll with Overtime Application 2114.3 Nested Decision Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216TUTORIAL 4-3: Completing the Loan Qualifier Application 2184.4 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2274.5 bool Variables and Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2324.6 Comparing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2324.7 Preventing Data Conversion Exceptions with the TryParse Methods . . . . 236TUTORIAL 4-4: Calculating Fuel Economy 2414.8 Input Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2444.9 Radio Buttons and Check Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245TUTORIAL 4-5: Creating the Color Theme Application 2494.10 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2524.11 Introduction to List Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255TUTORIAL 4-6: Creating the Time Zone Application 257Key Terms 261 Review Questions 261 Programming Problems 265Chapter 5Loops, Files, and Random Numbers   2715.1 More about ListBoxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2715.2 The while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273TUTORIAL 5-1: Using a Loop to Calculate an Account Balance 277A01 GADD3519 05 SE FM.indd 804/01/19 5:40 PM

ContentsixEnhancing the Ending Balance Application 2805.3 The and operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2845.4 The for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285TUTORIAL 5-3: Using the for Loop 2905.5 The do-while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2935.6 Using Files for Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295TUTORIAL 5-4: Writing Data to a Text File 301TUTORIAL 5-5: Appending Data to the Friend.txt File 306TUTORIAL 5-6: Using a Loop to Read to the End of a File 314TUTORIAL 5-7: Calculating a Running Total 3185.7 The OpenFileDialog and SaveFileDialog Controls . . . . . . . . . . . . . . . . . . . . 3215.8 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326TUTORIAL 5-8: Simulating Coin Tosses 3285.9 The Load Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332TUTORIAL 5-9: Creating a Load Event Handler 333Key Terms 336 Review Questions 336 Programming Problems 339TUTORIAL 5-2:Chapter 6Modularizing Your Code with Methods   3436.1 Introduction to Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3436.2 void Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345TUTORIAL 6-1: Creating and Calling Methods 3496.3 Passing Arguments to Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353TUTORIAL 6-2: Passing an Argument to a Method 3566.4 Passing Arguments by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364TUTORIAL 6-3: Using an Output Parameter 3676.5 Value-Returning Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371TUTORIAL 6-4: Writing a Value-Returning Method 376TUTORIAL 6-5: Modularizing Input Validation with a Boolean Method 3796.6 Debugging Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384TUTORIAL 6-6: Practicing the Step Into Command 385TUTORIAL 6-7: Practicing the Step Over Command 386TUTORIAL 6-8: Practicing the Step Out Command 387Key Terms 389 Review Questions 389 Programming Problems 385Chapter 7Arrays and Lists   3977.1 Value Types and Reference Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3977.2 Array Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400TUTORIAL 7-1: Using an Array to Hold a List of RandomLottery Numbers 4077.3 Working with Files and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4127.4 Passing Arrays as Arguments to Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 4157.5 Some Useful Array Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422TUTORIAL 7-2: Processing an Array 4327.6 Advanced Algorithms for Sorting and Searching Arrays . . . . . . . . . . . . . . . 4377.7 Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444TUTORIAL 7-3: Completing the Seating Chart Application . . . . . . . . . . . . . . 4477.8 Jagged Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453A01 GADD3519 05 SE FM.indd 904/01/19 5:40 PM

xContents7.9 The List Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454TUTORIAL 7-4: Completing the Test Score List Application . . . . . . . . . . . . . . 4607.10 The ImageList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465TUTORIAL 7-5: Completing the Random Card Application . . . . . . . . . . . . . . 467Key Terms 470 Review Questions 470 Programming Problems 474Chapter 8Text Processing  4798.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4798.2 Working with Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479TUTORIAL 8-1: Completing the Password Validation Application . . . . . . . . . 4858.3 Working with Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489TUTORIAL 8-2: Completing the Telephone Format Application . . . . . . . . . . . 498TUTORIAL 8-3: Completing the Telephone Unformat Application . . . . . . . . . 5028.4 Tokenizing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506TUTORIAL 8-4: Completing the CSV Reader Application . . . . . . . . . . . . . . . . 5098.5 The String.Format Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514Key Terms 519 Review Questions 519 Programming Problems 521Chapter 9Structures, Enumerated Types, and Dictionaries   5259.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5259.2 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525TUTORIAL 9-1: Completing the Phonebook Application . . . . . . . . . . . . . . . . 5359.3 The DateTime and TimeSpan Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . 5419.4 Enumerated Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549TUTORIAL 9-2: Completing the Color Spectrum Application 5529.5 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556TUTORIAL 9-3 Storing Names and Birthdays in a Dictionary: . . . . . . . . . . . . 564TUTORIAL 9-4 Using a Dictionary to Simulate a Deck of Cards 566Key Terms 572 Review Questions 572 Programming Problems 575Chapter 10 Introduction to Classes   58110.1 Introduction to Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581TUTORIAL 10-1: Creating and Using the Coin Class . . . . . . . . . . . . . . . . . . . 58810.2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593TUTORIAL 10-2: Creating and Using the CellPhone Class 59810.3 Parameterized Constructors and Overloading . . . . . . . . . . . . . . . . . . . . . . . 602TUTORIAL 10-3: Creating and Using the BankAccount Class . . . . . . . . . . . . 60310.4 Storing Class Type Objects in Arrays and Lists . . . . . . . . . . . . . . . . . . . . . . 611TUTORIAL 10-4: Completing the Cell Phone Inventory Application . . . . . . . 61210.5 Finding the Classes and Their Responsibilities in a Problem . . . . . . . . . . . . 61610.6 Application of Classes: Creating Multiple Forms in a Project . . . . . . . . . . . . 625TUTORIAL 10-5: Creating an Application with Two Forms . . . . . . . . . . . . . . 630TUTORIAL 10-6: Accessing a Control on a Different Form . . . . . . . . . . . . . . . 63510.7 Static Class Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639TUTORIAL 10-7: Creating a Simple Logging Utility with a Static Class: 643Key Terms 648 Review Questions 648 Programming Problems 652A01 GADD3519 05 SE FM.indd 1004/01/19 5:40 PM

ContentsxiChapter 11 Inheritance, Polymorphism, and Interfaces   65511.1 Inheritance 655TUTORIAL 11-1: Creating and Testing the SavingsAccountand CDAccount Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66411.2 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672TUTORIAL 11-2: Completing the Polymorphism Application 67711.3 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682TUTORIAL 11-3: Completing the Computer Science Student Application 68411.4 Extension Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688TUTORIAL 11-4: Creating Extension Methods 69311.5 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696TUTORIAL 11-5: Writing and Implementing an Interface 699Key Terms 708 Review Questions 708 Programming Problems 712Chapter 12 Databases  71512.1 Introduction to Database Management Systems . . . . . . . . . . . . . . . . . . . . . 71512.2 Tables, Rows, and Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71712.3 Creating a Database in Visu

vi Brief Contents Chapter 1 Introduction to Computers and Programming 1 Chapter 2 Introduction to Visual C# 51 Chapter 3 Processing Data 117 Chapter 4 Making Decisions 201 Chapter 5 Loops, Files, and Random Numbers 271 Chapter 6 Modularizing Your Code with Methods 343 Chapter 7 Arrays and Lists 397 Chapter 8 Text Processing 479 Chapter 9 Structures, Enumerated Types, and Dictionaries 525