Only Required Section of the Case Study Software... Optional Software Engineering Case Study: Examining the Section 4.4.. Optional Software Engineering Case Study: Identifying the... Op
Trang 1P J Deitel - Deitel & Associates, Inc
Publisher : Prentice Hall Pub Date : December 15, 2005 Print ISBN-10 : 0-13-152523-9
Print ISBN-13 : 978-0-13-152523-8 eText ISBN-10 : 0-13-133214-7 eText ISBN-13 : 978-0-13-133214-0
Pages : 1648
Learn how to build winning C# applications, start to finish, using the Deitels' proven methodology and signature Live-Code(tm) Approach! This new edition includes extensive use of Visual Studio 2005's new visual programming tools that tremendously reduce the amount of code programmers need to write in ADO.NET and ASP.NET applications With these new tools, programmers can develop powerful ADO.NET and ASP.NET applications quickly and easily
Trang 2P J Deitel - Deitel & Associates, Inc
Publisher : Prentice Hall Pub Date : December 15, 2005 Print ISBN-10 : 0-13-152523-9
Print ISBN-13 : 978-0-13-152523-8 eText ISBN-10 : 0-13-133214-7 eText ISBN-13 : 978-0-13-133214-0
About Deitel & Associates, Inc xxxvii Chapter 1 Introduction to Computers, the Internet and Visual C# 1
Section 1.2 What Is a Computer? 3 Section 1.3 Computer Organization 3 Section 1.4 Early Operating Systems 4 Section 1.5 Personal Computing, Distributed Computing and Client/Server
Trang 3Section 1.7 Microsoft's Windows® Operating System 6 Section 1.8 Machine Languages, Assembly Languages and High-Level
Section 1.10 C, C++, Java and Visual Basic 10 Section 1.11 Other High-Level Languages 11 Section 1.12 The Internet and the World Wide Web 12 Section 1.13 Extensible Markup Language (XML) 13 Section 1.14 Microsoft's NET 13 Section 1.15 The NET Framework and the Common Language Runtime 14 Section 1.16 Test-Driving a C# Application 15 Section 1.17 (Only Required Section of the Case Study) Software
Trang 4Section 3.4 Modifying Your Simple C# Application 90 Section 3.5 Formatting Text with Console.Write and Console.WriteLine 93 Section 3.6 Another C# Application: Adding Integers 94
Section 3.9 Decision Making: Equality and Relational Operators 102 Section 3.10 (Optional) Software Engineering Case Study: Examining the
Section 4.4 Declaring a Method with a Parameter 135 Section 4.5 Instance Variables and Properties 138 Section 4.6 UML Class Diagram with a Property 143 Section 4.7 Software Engineering with Properties and set and get
Section 4.8 Value Types vs Reference Types 145 Section 4.9 Initializing Objects with Constructors 146 Section 4.10 Floating-Point Numbers and Type decimal 149 Section 4.11 (Optional) Software Engineering Case Study: Identifying the
Trang 5Section 5.4 Control Structures 173 Section 5.5 if Single-Selection Statement 176 Section 5.6 if else Double-Selection Statement 177 Section 5.7 while Repetition Statement 182 Section 5.8 Formulating Algorithms: Counter-Controlled Repetition 183 Section 5.9 Formulating Algorithms: Sentinel-Controlled Repetition 188 Section 5.10 Formulating Algorithms: Nested Control Statements 196 Section 5.11 Compound Assignment Operators 200 Section 5.12 Increment and Decrement Operators 202
Trang 6Section 7.3 static Methods, static Variables and Class Math 275 Section 7.4 Declaring Methods with Multiple Parameters 278 Section 7.5 Notes on Declaring and Using Methods 282 Section 7.6 Method Call Stack and Activation Records 283 Section 7.7 Argument Promotion and Casting 284 Section 7.8 The Framework Class Library 286 Section 7.9 Case Study: Random-Number Generation 287 Section 7.10 Case Study: A Game of Chance (Introducing Enumerations) 293 Section 7.11 Scope of Declarations 298 Section 7.12 Method Overloading 301
Section 7.14 Passing Arguments: Pass-by-Value vs Pass-by-Reference 307 Section 7.15 (Optional) Software Engineering Case Study: Identifying
Trang 7Self-Review Exercises 390 Answers to Self-Review Exercises 391
Special Section: Building Your Own Computer 401 Chapter 9 Classes and Objects: A Deeper Look 408
Section 9.2 Time Class Case Study 410 Section 9.3 Controlling Access to Members 413 Section 9.4 Referring to the Current Object's Members with the this
Section 9.6 Time Class Case Study: Overloaded Constructors 420 Section 9.7 Default and Parameterless Constructors 425
Section 9.9 Garbage Collection and Destructors 430 Section 9.10 static Class Members 431 Section 9.11 readonly Instance Variables 436 Section 9.12 Software Reusability 438 Section 9.13 Data Abstraction and Encapsulation 439 Section 9.14 Time Class Case Study: Creating Class Libraries 441
Section 9.16 Class View and Object Browser 447 Section 9.17 (Optional) Software Engineering Case Study: Starting to
Trang 8Section 12.5 .NET Exception Hierarchy 573
Section 12.7 Exception Properties 582 Section 12.8 User-Defined Exception Classes 587
Trang 9Section 13.1 Introduction 597
Section 13.4 Control Properties and Layout 608 Section 13.5 Labels, TextBoxes and Buttons 612 Section 13.6 GroupBoxes and Panels 615 Section 13.7 CheckBoxes and RadioButtons 618
Section 13.10 NumericUpDown Control 631 Section 13.11 Mouse-Event Handling 633 Section 13.12 Keyboard-Event Handling 636
Section 14.7 CheckedListBox Control 671 Section 14.8 ComboBox Control 674 Section 14.9 TreeView Control 678 Section 14.10 ListView Control 684 Section 14.11 TabControl Control 690 Section 14.12 Multiple Document Interface (MDI) Windows 695 Section 14.13 Visual Inheritance 703 Section 14.14 User-Defined Controls 706
Trang 10Chapter 15 Multithreading 719
Section 15.2 Thread States: Life Cycle of a Thread 721 Section 15.3 Thread Priorities and Thread Scheduling 723 Section 15.4 Creating and Executing Threads 725 Section 15.5 Thread Synchronization and Class Monitor 728 Section 15.6 Producer/Consumer Relationship without Thread
Section 15.7 Producer/Consumer Relationship with Thread
Section 15.8 Producer/Consumer Relationship: Circular Buffer 745 Section 15.9 Multithreading with GUIs 753
and Indexer of Class StringBuilder 781
Section 16.12 Append and AppendFormat Methods of Class StringBuilder 783 Section 16.13 Insert, Remove and Replace Methods of Class StringBuilder 785
Section 16.15 Card Shuffling and Dealing Simulation 790 Section 16.16 Regular Expressions and Class Regex 794
Trang 11Self-Review Exercises 808 Answers to Self-Review Exercises 808
Chapter 17 Graphics and Multimedia 810
Section 17.2 Drawing Classes and the Coordinate System 811 Section 17.3 Graphics Contexts and Graphics Objects 813
Section 18.8 Creating a Sequential-Access File Using Object Serialization 913 Section 18.9 Reading and Deserializing Data from a Sequential-Access
Trang 12Section 19.8 (Optional) Document Object Model (DOM) 963 Section 19.9 (Optional) Schema Validation with Class XmlReader 977 Section 19.10 (Optional) XSLT with Class XslCompiledTransform 980
Section 20.5 ADO.NET Object Model 1009 Section 20.6 Programming with ADO.NET: Extracting Information from a
Section 20.7 Querying the Books Database 1022 Section 20.8 Programming with ADO.NET: Address Book Case Study 1031 Section 20.9 Using a DataSet to Read and Write XML 1039
Trang 13Chapter 21 ASP.NET 2.0, Web Forms and Web Controls 1050
Section 21.2 Simple HTTP Transactions 1052 Section 21.3 Multitier Application Architecture 1054 Section 21.4 Creating and Running a Simple Web-Form Example 1055
Section 21.6 Session Tracking 1092 Section 21.7 Case Study: Connecting to a Database in ASP.NET 1110 Section 21.8 Case Study: Secure Books Database Application 1122
Trang 14Section 23.7 Connectionless Client/Server Interaction with Datagrams 1247 Section 23.8 Client/Server Tic-Tac-Toe Using a Multithreaded Server 1252 Section 23.9 WebBrowser Control 1267
Trang 15Section 26.4 Type Constraints 1373 Section 26.5 Overloading Generic Methods 1376 Section 26.6 Generic Classes 1377 Section 26.7 Notes on Generics and Inheritance 1386
Trang 16Section C.1 Introduction 1441 Section C.2 Breakpoints and the Continue Command 1441 Section C.3 The Locals and Watch Windows 1446
Section E.2 Unicode Transformation Formats 1462 Section E.3 Characters and Glyphs 1463 Section E.4 Advantages/Disadvantages of Unicode 1463
Trang 17Section G.2 Basic XHTML Tables 1493 Section G.3 Intermediate XHTML Tables and Formatting 1496 Section G.4 Basic XHTML Forms 1498 Section G.5 More Complex XHTML Forms 1501 Section G.6 Internal Linking 1508 Section G.7 Creating and Using Image Maps 1511
Section G.9 frameset Element 1516 Section G.10 Nested framesets 1520
Appendix H HTML/XHTML Special Characters 1523
Appendix J ATM Case Study Code 1527 Section J.1 ATM Case Study Implementation 1527
Section J.5 Class CashDispenser 1535 Section J.6 Class DepositSlot 1537
Section J.8 Class BankDatabase 1540 Section J.9 Class Transaction 1542 Section J.10 Class BalanceInquiry 1544 Section J.11 Class Withdrawal 1545
Trang 19or use of these programs
Many of the designations used by manufacturers and sellers todistinguish their products are claimed as trademarks and
registered trademarks Where those designations appear in thisbook, and Prentice Hall and the authors were aware of a
trademark claim, the designations have been printed in initialcaps or all caps All product names mentioned remain
trademarks or registered trademarks of their respective owners
All rights reserved No part of this book may be reproduced, inany form or by any means, without permission in writing fromthe publisher
Trang 20Languag™e and UML™ are trademarks of Object ManagementGroup, Inc
Trang 21Harvey M Deitel and Paul J Deitel
Trang 22[Page ii]
Trang 24Simply C++: An Application-Driven Tutorial Approach
Simply C#: An Application-Driven Tutorial Approach
Simply Java™ Programming: An Application-Driven TutorialApproach
Simply Visual Basic® NET: An Application-Driven Tutorial
Approach (Visual Studio NET 2002 Edition)
Simply Visual Basic® NET 2003: An Application-Driven TutorialApproach
Trang 26[Page xxiii]
Trang 27"Live in fragments no longer, only connect."
Edgar Morgan Foster
Welcome to C# and the world of Windows, Internet and Webprogramming with Visual Studio 2005 and the NET 2.0
platform! This book presents leading-edge computing
technologies for computer science students, software
developers and IT professionals
At Deitel & Associates, we write computer science textbooks forcollege students and professional books for software
developers We also teach this material in industry seminars atorganizations worldwide
This book was a joy to create To start, we put the previousedition under the microscope:
We audited our C# presentation against the most recentEcma and Microsoft C# Language Specifications, which can
be found at
www.ecma-international.org/publications/standards/Ecma-334.html
and msdn.microsoft.com/vcsharp/programming/language/,respectively
All of the chapters have been significantly updated and
upgraded
We changed to an early classes and objects pedagogy Nowreaders build reusable classes starting in Chapter 4
We updated our object-oriented presentation to use the
Trang 28latest version of the UML (Unified Modeling Language)UML™ 2.0the industry-standard graphical language for modeling
object-oriented systems
We added an optional OOD/UML automated teller machine(ATM) case study in Chapters 1, 39 and 11 The case studyincludes a complete C# code implementation of the ATM in
All of this has been carefully scrutinized by a substantial team
of academics, NET industry developers and members of theMicrosoft C# development team
We believe that this book and its support materials have
everything instructors and students need for an informative,interesting, challenging and entertaining C# educational
experience In this Preface, we overview various conventionsused in the book, such as syntax shading the code examplesand code highlighting We also discuss the book's
comprehensive suite of ancillary materials that help instructorsmaximize their students' learning experience, including the
Prentice Hall Instructor's Resource Center, PowerPoint® Slide
lecture notes, companion Web site, SafariX (Pearson
Education's WebBook publications) and more
Trang 29Visual C# 2005 How to Program, 2/e presents 230 complete,
working C# programs and depicts their inputs and outputs inactual screen shots of running programs This is our signature
"live-code" approachwe present concepts in the context of
complete working programs
As you read this book, if you have questions, send an e-mail to
deitel@deitel.com; we will respond promptly For updates onthis book and the status of C# software, and for the latest news
Trang 30Before You Begin
Downloading Microsoft Visual C# 2005 Express Edition Software
On November 7, 2005 Microsoft released its Visual Studio 2005development tools, including the Visual C# 2005 Express
Edition Per Microsoft's Web site, Microsoft Express Editions are
"lightweight, easy-to-use and easy-to-learn tools for the
hobbyist, novice and student developer." This product is
available free for download through November 6, 2006 Afterthis date, if you have already downloaded the software, it willstill work However, if you need to download the software afterthis one-year period, Microsoft may charge a fee for the
download
You may use this software to compile and execute the exampleprograms in the book You can download Visual C# 2005
Express Edition at:
msdn.microsoft.com/vstudio/express/
Microsoft provides a dedicated forum for help using the ExpressEdition:
forums.microsoft.com/msdn/ShowForum.aspx?ForumID=24
Visual C# 2005 How to Program, 2/e Code
Examples
The book's source code is available free for download at
Trang 31example files to your computer, please see your instructor
Once you download the complete examples.zip file, extract thefiles to the C:\ folder on your computer This will create an
examples folder that contains subfolders for each chapter (e.g., ch01, ch02, etc.)
Additional Software Downloads
For the examples in Chapter 17, Graphics and Multimedia, weuse Microsoft Agent If students use the examples in a lab
environment, more than likely this software will have to beinstalled as part of the lab setup
www.microsoft.com/msagent/downloads/default.asp
For Chapter 20, you will need SQL Server 2005 Express Edition(also available as part of the Visual C# 2005 Express Editiondownload)
Trang 32Features in Visual C# 2005 How to Program, 2/e
This new edition contains many new and enhanced features
Updated for Visual Studio 2005, C# 2.0 and NET 2.0
We updated the entire text to reflect Microsoft's latest release ofVisual C# 2005 New items include:
Screenshots updated to the Visual Studio 2005 IDE
Property accessors with different access modifiers
Viewing exception data with the Exception Assistant (a newfeature of the Visual Studio 2005 Debugger)
Trang 33feel for ASP.NET Web pages
Using Visual Studio 2005 smart tag menus to perform many
of the most common programming tasks when new controlsare dragged onto a Windows Form or ASP.NET Web page
Using Visual Web Developer's built-in Web server to testASP.NET 2.0 applications and Web services
Using an XmlDataSource to bind XML data sources to a control
Using a SqlDataSource to bind a SQL Server database to a
control or set of controls
Using an ObjectDataSource to bind a control to an object thatserves as a data source
Using generic collections from the Systems.Collections.Genericnamespace
New Interior Design
Working with the creative services team at Prentice Hall, we
Trang 35terminology in Chapter 1 In the previous edition, we developedcustom classes in Chapter 9, but in this edition, we start doingthat in the completely new Chapter 4 Chapters 58 have beencarefully rewritten with an "early classes and objects approach."
Carefully Tuned Treatment of Object-Oriented Programming in Chapters 911
We performed a high-precision upgrade of Visual C# 2005 How
to Program, 2/e This edition is clearer and more
accessibleespecially if you are new to object-oriented
programming (OOP) We completely rewrote the OOP chapters,integrating an employee payroll class hierarchy case study andmotivating interfaces with an accounts payable hierarchy
Case Studies
We include many case studies, some spanning multiple sectionsand chapters:
The GradeBook class in Chapters 4, 5, 6 and 8
Trang 36The Unified Modeling Language (UML)Using the UML 2.0 to Develop an Object-Oriented Design
of an ATM
The Unified Modeling Language™ (UML™) has become the
oriented systems All the UML diagrams in the book comply withthe UML 2.0 specification We use UML class diagrams to
preferred graphical modeling language for designing object-visually represent classes and their inheritance relationships,and we use UML activity diagrams to demonstrate the flow ofcontrol in each of C#'s control statements
Trang 37recommended) case study on object-oriented design using theUML The case study was reviewed by a distinguished team ofOOD/UML academic and industry professionals, including
leaders in the field from Rational (the creators of the UML andnow a division of IBM) and the Object Management Group
(responsible for maintaining and evolving the UML) In the casestudy, we design and fully implement the software for a simpleautomated teller machine (ATM) The Software Engineering
Case Study sections at the ends of Chapters 1, 39 and 11
present a carefully paced introduction to object-oriented designusing the UML We introduce a concise, simplified subset of theUML 2.0, then guide the reader through a first design
experience intended for the novice object-oriented
designer/programmer The case study is not an exercise; rather,
it is an end-to-end learning experience that concludes with adetailed walkthrough of the complete C# code The SoftwareEngineering Case Study sections help readers develop an
object-oriented design to complement the object-oriented
programming concepts they begin learning in Chapter 1 andimplementing in Chapter 4 In the first of these sections at theend of Chapter 1, we introduce basic OOD concepts and
terminology In the optional Software Engineering Case Studysections at the ends of Chapters 36, we consider more
substantial issues, as we undertake a challenging problem withthe techniques of OOD We analyze a typical requirements
document that specifies the system to be built, determine theclasses needed to implement that system, determine the
attributes the classes need to have, determine the behaviorsthe classes need to exhibit and specify how the classes mustinteract with one another to meet the system requirements In
Appendix J, we include a complete C# implementation of theobject-oriented system that we design in the earlier chapters
We employ a carefully developed, incremental object-orienteddesign process to produce a UML model for our ATM system.From this design, we produce a substantial working C#
implementation using key programming notions, including
Trang 38programmers to build Web documents that respond to clientrequests To enable interactive Web pages, server-side
programs process information users input into HTML forms ASP.NET provides enhanced visual programming capabilities, similar
to those used in building Windows forms for desktop programs.Programmers can create Web pages visually, by dragging anddropping Web controls onto Web forms Chapter 21, ASP.NET,Web Forms and Web Controls, introduces these powerful
technologies
Web Services and ASP.NET 2.0
Microsoft's NET strategy embraces the Internet and Web asintegral to software development and deployment Web servicestechnology enables information sharing, e-commerce and otherinteractions using standard Internet protocols and technologies,such as Hypertext Transfer Protocol (HTTP), Extensible MarkupLanguage (XML) and Simple Object Access Protocol (SOAP).Web services enable programmers to package application
functionality in a manner that turns the Web into a library ofreusable software components In Chapter 22, we present aWeb service that allows users to manipulate huge
integersintegers too large to be represented with C#'s built-in
Trang 39Object-Oriented Programming
Object-oriented programming is the most widely employed
technique for developing robust, reusable software This textoffers a rich treatment of C#'s object-oriented programmingfeatures Chapter 4 introduces how to create classes and
objects These concepts are extended in Chapter 9 Chapter 10
discusses how to create powerful new classes quickly by usinginheritance to "absorb" the capabilities of existing classes
Chapter 11 familiarizes the reader with the crucial concepts ofpolymorphism, abstract classes, concrete classes and
interfaces, which facilitate powerful manipulations among
objects belonging to an inheritance hierarchy
XML
Use of the Extensible Markup Language (XML) is exploding inthe software-development industry and in the e-business
community, and is pervasive throughout the NET platform
Because XML is a platform-independent technology for
describing data and for creating markup languages, XML's dataportability integrates well with C#-based portable applicationsand services Chapter 19 introduces XML, XML markup and thetechnologies, such as DTDs and Schema, which are used to
validate XML documents' contents We also explain how to
manipulate XML documents programmatically using the
Document Object Model (DOM™) and how to transform XMLdocuments into other types of documents via Extensible
Stylesheet Language Transformation (XSLT) technology
Trang 40ADO.NET 2.0
Databases store vast amounts of information that individualsand organizations must access to conduct business As an
evolution of Microsoft's ActiveX Data Objects (ADO) technology,ADO.NET represents a new approach for building applicationsthat interact with databases ADO.NET uses XML and an
enhanced object model to provide developers with the toolsthey need to access and manipulate databases for large-scale,extensible, mission-critical multi-tier applications Chapter 20