Download full C Programming From Problem Analysis to Program Design 4th Edition Barbara Doyle ebook all chapters
Download full C Programming From Problem Analysis to Program Design 4th Edition Barbara Doyle ebook all chapters
https://ebookgate.com/product/java-programming-from-problem-analysis-
to-program-design-4th-edition-d-s-malik/
ebookgate.com
https://ebookgate.com/product/c-programming-from-problem-analysis-to-
program-design-5th-5th-edition-d-s-malik/
ebookgate.com
https://ebookgate.com/product/c-programming-program-design-including-
data-structures-5ed-edition-malik-d-s/
ebookgate.com
https://ebookgate.com/product/c-programming-program-design-including-
data-structures-7th-edition-d-s-malik/
ebookgate.com
C Programming Program Design Including Data Structures 6th
Edition D. S. Malik
https://ebookgate.com/product/c-programming-program-design-including-
data-structures-6th-edition-d-s-malik/
ebookgate.com
https://ebookgate.com/product/fixed-income-analysis-4th-edition-
edition-barbara-s-petitt/
ebookgate.com
https://ebookgate.com/product/programming-in-objective-c-4th-edition-
stephen-kochan/
ebookgate.com
https://ebookgate.com/product/c-programming-data-structures-4th-
edition-e-balagurusamy/
ebookgate.com
https://ebookgate.com/product/reading-the-middle-ages-
from-c-900-to-c-1500-3-ed-edition-barbara-h-rosenwein/
ebookgate.com
C# PROGRAMMING:
FROM PROBLEM ANALYSIS TO PROGRAM DESIGN
FOURTH EDITION
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C# PROGRAMMING:
FROM PROBLEM ANALYSIS TO PROGRAM DESIGN
FOURTH EDITION
BARBARA DOYLE
Australia l Brazil l Japan l Korea l Mexico l Singapore l Spain l United Kingdom l United States
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C# Programming: From Problem Analysis © 2014 Cengage Learning
to Program Design, Fourth Edition
ALL RIGHTS RESERVED. No part of this work covered by the copyright
Barbara Doyle herein may be reproduced, transmitted, stored or used in any form or
by any means graphic, electronic, or mechanical, including but not
Executive Editor: Kathleen McMahon
limited to photocopying, recording, scanning, digitizing, taping, Web
Senior Product Manager: Alyssa Pratt distribution, information networks, or information storage and
Editorial Assistant: Sarah Ryan retrieval systems, except as permitted under Section 107 or 108 of the
1976 United States Copyright Act, without the prior written permission
Content Project Manager: Jennifer Feltri-George
of the publisher.
Art Director: Cheryl Pearl, GEX
Manufacturing Planner: Julio Esperas
Cover Designer: GEX Publishing Services For product information and technology assistance, contact us at
Cover Photo: ©iurii /Shutterstock Cengage Learning Customer & Sales Support,
www.cengage.com/support
Copyeditor: Andrea Schein
Indexer: Sharon Hilgenberg For permission to use material from this text or product,
submit all requests online at cengage.com/permissions
Compositor: Integra
Further permissions questions can be e-mailed to
[email protected]
Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or
registered trademarks of their respective manufacturers and sellers.
Any fictional data related to persons or companies or URLs used
throughout this book is intended for instructional purposes only. At the
time this book was printed, any such data was fictional and not
belonging to any real persons or companies.
Cengage Learning reserves the right to revise this publication and
make changes from time to time in its content without notice.
The programs in this book are for instructional purposes only. They
have been tested with care, but are not guaranteed for any
particular intent beyond educational purposes. The author and the
publisher do not offer any warranties or representations, nor do they
accept any liabilities with respect to the programs.
Cengage Learning is a leading provider of customized learning
solutions with office locations around the globe, including
Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan.
Locate your local office at: www.cengage.com/global
Cengage Learning products are represented in Canada by Nelson
Education, Ltd.
To learn more about Cengage Learning visit
www.cengage.com.
Purchase any of our products at your local college store or at our
preferred online store: www.cengagebrain.com
PREFACE xxi
7. Arrays 383
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
vi | C# Programming: From Problem Analysis to Program Design, Fourth Edition
GLOSSARY 1117
INDEX 1131
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
TABLE OF C ONTENTS
Preface xxi
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
viii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Main( ) Method 33
Method Body Statements 34
Compiling, Building, and Running an Application 38
Typing Your Program Statements 38
Compilation and Execution Process 39
Compiling the Source Code Using Visual Studio IDE 39
Debugging an Application 45
Syntax Errors 45
Run-time Errors 47
Creating an Application 47
Coding Standards 52
Pseudocode 52
Resources 53
Quick Review 53
Exercises 56
Programming Exercises 61
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | ix
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xi
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
ARRAYS 383
7 Array Basics 384
Array Declaration 385
Array Initializers 388
Array Access 390
Sentinel-Controlled Access 394
Using Foreach with Arrays 395
Array Class 396
Arrays as Method Parameters 401
Pass by Reference 401
Array Assignment 405
Params Parameters 406
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xiii
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xiv | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xvii
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xviii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xix
ASP.NET 986
Visual Studio for Web Development 986
ASP.NET Programming Models 987
Web Forms Page 988
Creating an ASP.NET Web Forms Site 988
Master Pages 993
Cascading Style Sheet (CSS) 997
ASP.NET Empty Web Site 1001
Controls 1004
HTML Controls 1004
HTML Server Controls 1008
Web Forms Standard Server Controls 1012
Available Web Forms Controls 1012
Web Forms Controls of the Common Form Type 1014
Adding Common Form-Type Controls 1018
Validation, Custom, and Composite Controls 1021
Validation Controls 1021
Calendar Control 1026
GridView Control 1033
AccessDataSource 1039
Using Visual Tools to Connect 1040
Setting the Visibility Property 1045
Other Controls 1047
Web Services 1050
Web Services Protocols 1050
Windows Communication Foundation (WCF) 1052
Smart Device Applications (Optional) 1052
Windows 7.x Phone 1053
Silverlight 1054
Creating a Smart Device Application for Windows 7.x Phones 1054
Windows 8 Phone Apps 1061
Creating a Windows 8 Phone App 1063
XML 1064
Code-Behind File 1065
XAML Code 1067
Running the App 1068
Deploying to an Emulator 1068
Deploying to a Device 1071
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xx | C# Programming: From Problem Analysis to Program Design, Fourth Edition
GLOSSARY 1117
INDEX 1131
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
P REFACE
Why C#?
C# has gained tremendous popularity in the industry. C# is a true object-oriented language
that includes a rich set of instruction statements. C# was the language used for development
of much of .NET, the Microsoft programming paradigm that includes a collection of
more than 2,000 predefined classes that make up the Framework Class Library (FCL).
Thus, C# has access to a large collection of predefined classes similar to those available to
Java. C# provides tools that make it easy to create graphical user interfaces—similar to the
tools Visual Basic programmers have employed for years. C# also provides the pure data
crunching horsepower to which C/C++ programmers have become accustomed. But
unlike other languages, C# was designed from scratch to accommodate Internet and
Windows applications. C# is an elegant and simple object-oriented language that allows
programmers to build a breadth of applications. For these reasons, C# was chosen as the
language for this book.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
traditionally found in most CS1 textbooks and, because of the inclusion of a number of
advanced applications, this textbook could also be used in an intermediate course for
students who have already been exposed to some programming concepts.
Advanced Topics
After building a solid programming foundation, this book presents rapid application
development techniques that can be used to build a number of advanced types of
applications including Windows, data-driven applications using a database, and Web and
mobile applications for smart devices. Generics, delegates, ArrayLists, dynamic data types,
abstract classes, interfaces, and many advanced object-oriented concepts are introduced.
Readers retrieve data from files and store data both to sequential and binary files. Solutions
involving multidimensional arrays and other advanced collection classes are demonstrated.
Illustrating the drag-and-drop construction approach used with Visual Studio, Windows and
Web applications are created. Readers are introduced to the event-driven programming
model, which is based on interactively capturing and responding to user input on Windows
and Web forms. Class libraries, Windows Forms applications, and Windows Presentation
Foundation client applications are created. Two full chapters are devoted to programming
based on events and then those topics are integrated throughout the remainder of the
book. Readers are introduced to ASP.NET for Web applications and ADO.NET for
working with databases.
For first-time programmers, this book is unusual in introducing applications that retrieve
and update data in databases such as those created using Microsoft Access. A number of
visual development tools are illustrated to connect to data sources. Other interesting
topics include retrieving data using Language-Integrated Query (LINQ), developing
stand-alone .dll components (class libraries), and programming applications for mobile
devices such as tablets and smart phones. All of these advanced features are discussed
after the reader has gained a thorough understanding of the basic components found in
programming languages.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxiii
Approach
A problem-solving methodology based on object-oriented software development is
introduced early and used throughout the book. Programming Examples are presented at
the end of each chapter, and each example follows a consistent approach: analyzing the
problem specifications, designing a solution, implementing the design, and verifying or
validating the solution structures.
The author believes that the best way to learn to program is to experience programming. This
assumption drives the material presented in this textbook. As new concepts are introduced,
they are described using figures and illustrations. Examples are shown and discussed as they
relate to the concept being presented. With a hands-on approach to learning, readers practice
and solidify the concepts presented by completing the end of the chapter exercises. Readers
are also encouraged throughout the book to explore and make use of the more than 2,000
classes that make up the Framework Class Library (FCL).
Every chapter begins with a list of objectives and a short overview of the previous
chapter. Text in each chapter is supplemented with figures and tables to help visual
learners grasp the concepts being presented. Each chapter is sprinkled with useful tips and
hints as NOTES on the concepts being presented. Code snippets and numbered examples
are embedded as new concepts are introduced in each chapter. In addition, each chapter
contains complete working programs illustrating an application using C#. Every chapter
ends with a Coding Standards section, which provides a summary of acceptable
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxiv | C# Programming: From Problem Analysis to Program Design, Fourth Edition
conventions or guidelines pertaining to the chapter’s topics that focus on style issues.
A list of Web sites for readers to explore is included in a special Resources section at
the end of each chapter. A summary of the major points covered in that chapter and
review exercises in both objective and subjective formats are included. Every chapter
contains 10 programming exercises that give readers an opportunity to experience
programming.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxv
Readers learn to create their own classes in Chapter 4. This chapter introduces the
components of a class including the data, property, and method members. Special methods,
including constructors, are written.
Chapters 5 and 6 introduce control structures that alter the sequential flow of execution.
Selection control constructs are introduced in Chapter 5. One-way, multiway, switch, and
ternary operators used to make decisions are illustrated. Looping is introduced in Chapter 6.
The rich set of iteration operators including while, for, do while, and foreach are
explored. Recursive solutions are also explored.
Chapter 7 discusses arrays. This chapter describes how to declare and perform compile-time
initialization of array elements. The Array class and its many members are introduced.
Methods of the string and ArrayList classes are included in Chapter 8. Multidimensional
arrays and other collection classes, including stacks, queues, and hash tables are also
introduced in Chapter 8.
Chapters 9 and 10 present a different way of programming, which is based on interactively
responding to events. A number of classes in the FCL that are used to create Windows
applications are introduced. Elements of good design are discussed in Chapter 9. Delegates
are also explored in Chapter 9. Visual Studio’s drag-and-drop approach to rapid application
development is introduced and used in these chapters. The Windows Presentation Foundation
(WPF) is also introduced in Chapter 10 as an alternative approach to Windows Forms for
creating Windows applications.
Advanced object-oriented programming features are the focus of Chapter 11. Readers are
introduced to component-based development and learn how to create their own class library
files. Inheritance, interfaces, abstract classes, sealed classes, generic types, partial classes, and
polymorphic programming are discussed in detail. Advanced features such as overriding,
overloading, and the use of virtual methods are also included in Chapter 11. Static versus
dynamic typing is also investigated in Chapter 11.
Chapter 12 discusses debugging and exception handling techniques. The chapter introduces
one of the tools available in Visual Studio, the Debugger, which can be used to observe the
run-time environment, take an up-close look at the code, and locate logic errors. The try. . .
catch. . .finally block is discussed for handling exceptions. In addition to discussing .NET
exception classes, custom exceptions are designed.
Chapter 13 presents the basics of creating, opening, closing, reading, and writing files. The
major classes used to work with file and directory systems are introduced. Chapter 14
introduces a number of new namespaces collectively called ADO.NET, which consists of a
managed set of library classes that enables interaction with databases. The chapter illustrates
how ADO.NET classes are used to retrieve and update data in databases. The visual
programming tools and wizards available with Visual Studio, which simplify accessing data,
are covered in this chapter. The Language-Integrated Query (LINQ) is also introduced in
Chapter 14.
The focus of Chapter 15 is on Web applications. Readers explore how the design of Web-
based applications differs from Windows applications. They discover the differences between
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxvi | C# Programming: From Problem Analysis to Program Design, Fourth Edition
static and dynamic Web pages and how HTML and Web server controls differ. Master pages
and Cascading Style Sheets are introduced. Also included in Chapter 15 is an introduction to
mobile applications that can be viewed with small smart devices such as the Windows Phone.
Chapter 15 illustrates how validation controls can be used to check users’ input values and
shows how the ADO.NET classes, introduced in Chapter 14, can also be used with Web
applications to access database records.
Appendix A presents suggestions for customizing the appearance and behavior of the
Integrated Development Environment (IDE). Appendix B discusses the Code Editor
features of Visual Studio. Code snippets and refactoring are described. These new features
improve programmer productivity by reducing the number of keystrokes required to enter
program statements. This appendix also illustrates developing applications visually using class
diagrams. Appendix C lists the Unicode and ASCII (American Standard Code for Information
Interchange) character sets. Appendix D shows the precedence of the C# operators and
Appendix E lists the C# keywords.
Features
Every chapter in this book includes the following features. These features are both conducive
to learning in the classroom and enable you to learn the material at your own pace.
l Multi-color interior design shows accurate C# code and related comments.
l Learning objectives offer an outline of the concepts discussed in detail in the chapter.
l Hundreds of visual diagrams throughout the text illustrate difficult concepts.
l Syntax boxes show the general form for different types of statements.
l Numbered examples illustrate the key concepts with their relevant code, and the code
is often followed by a sample run. An explanation follows that describes the functions
of the most difficult lines of code.
l Notes highlight important facts about the concepts introduced in the chapter.
l Numerous tables are included that describe and summarize information compactly for
easy viewing.
l A Coding Standards section provides a summary of acceptable conventions or guidelines
pertaining to the chapter’s topic. These coding/programming guidelines help ensure
consistency and reduce the number of bugs and errors entered into programming projects.
l Internet sites listed including tutorials that can be used to enhance concepts are
presented in the Resources section.
l Programming Examples are complete programs featured at the end of the chapter. The
examples contain the distinct stages of preparing a problem specification, analyzing the
problem, designing the solution, and coding the solution.
l Quick Reviews offer a summary of the concepts covered in the chapter.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxvii
l Exercises further reinforce learning and ensure that students have, in fact, absorbed the
material. Both objective and subjective types of questions are included at the end of
each chapter.
l Programming Exercises challenge students to write C# programs with a specified
outcome.
l The glossary at the end of the book lists nearly four-hundred key terms in alphabetical
order along with definitions for easy reference. Throughout this text the terms set in
bold indicate that they are defined in the glossary.
From beginning to end, the concepts are introduced at a pace that is conducive to learning.
The writing style of this book is simple and straightforward, and it parallels the teaching style of
a classroom. The concepts introduced are described using examples and small programs.
The chapters have two types of programs. The first type includes small programs that are part
of the numbered examples and are used to explain key concepts. This book also features
numerous case studies called Programming Examples. These Programming Examples are
placed at the end of the chapters to pull together many of the concepts presented
throughout the chapter. The programs are designed to be methodical and workable. Each
Programming Example starts with a Problem Analysis and is then followed by the Algorithm
Design. Every step of the algorithm is then coded in C#. In addition to teaching problem-
solving techniques, these detailed programs show the user how to implement concepts in an
actual C# program. Students are encouraged to study the Programming Examples very
carefully in order to learn C# effectively.
All source code and solutions have been written, compiled, and tested by quality assurance
with Visual Studio Professional 2012.
Microsoft Visual C# can be packaged with this text. Please contact your Course
Technology Sales Representative for more information.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
FEATURES OF THE BOOK
Numerous visual
diagrams
throughout the
text illustrate
difficult concepts.
Updated screen
shots of what
readers see in
Visual Studio are
also included
throughout the
book.
Multi-color
interior design
shows accurate
C# code and
related
comments.
Throughout the
book, keywords
are shown in blue
and comments
appear in green.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Syntax boxes
show the general
form for different
types of
statements.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Notes provide short quick
tips highlighting important
concepts and features that
might be overlooked.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Numbered
examples
illustrate the key
concepts with
their relevant
code, and the
code is often
followed by a
sample run. An
explanation
follows that
describes the
functions of the
most difficult
lines of code.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Programming
Examples are complete
programs featured at
the end of the chapter.
The examples contain
the distinct stages of
preparing a problem
specification,
analyzing the problem,
designing the solution,
and coding the
implementation.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Coding/programming
style guidelines and
suggestions are
featured at the end
of each chapter.
A special Resources
section at the end of
each chapter offers a
number of Web sites
for the reader to
explore.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Exercises further
reinforce learning
and ensure that
students have, in
fact, absorbed the
material. Both
objective and
subjective types of
activities are
included at the end
of each chapter.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Programming
Exercises challenge
students to write C#
programs with a
specified outcome.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxxvi | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Instructor Resources
The following teaching tools are available for download at our Instructor Companion Site.
Simply search for this text at login.cengage.com. An instructor login is required.
Electronic Instructor’s Manual. The Instructor’s Manual that accompanies this textbook
includes additional instructional material to assist in class preparation, including suggestions for
lecture topics.
ExamView. This textbook is accompanied by ExamView, a powerful testing software
package that allows instructors to create and administer printed, computer (LAN-based), and
Internet exams. ExamView includes hundreds of questions that correspond to the topics
covered in this text, enabling students to generate detailed study guides that include page
references for further review. These computer-based and Internet-testing components allow
students to take exams at their computers, and save the instructor time because each exam is
graded automatically.
PowerPoint Presentations. This book comes with Microsoft PowerPoint slides for each
chapter. These are included as a teaching aid for classroom presentations, either to make
available to students on the network for chapter review, or to be printed for classroom
distribution. Instructors can add their own slides for additional topics that they introduce to
the class.
Source Code for Examples. The complete Visual Studio project files for the examples
included within each chapter are available for instructors and are also posted for students on
www.cengagebrain.com. Individual source code files are stored with a .cs extension inside the
project subdirectory.
Programming Exercises Solution Files. The complete Visual Studio project files for the
solutions to all programming exercises included at the end of the chapters are provided. The
individual source code files are stored with a .cs extension inside the project subdirectory.
Acknowledgments
I would like to express my gratitude for the opportunity to complete the fourth edition of this
book. Like the other editions, it was a huge undertaking for me. Special thanks go out to
Alyssa Pratt, Senior Product Manager at Cengage Learning, for her positive comments,
guidance, and support. She was a pleasure to work with again on this new edition. I am
grateful to the Quality Assurance team members who verified that each of the examples and
exercise solutions worked properly. Also thanks to the Content Manager and Copy Editor,
Jennifer Feltri-George and Andrea Schein, who provided great suggestions as we progressed
with the project.
I am very grateful to the following reviewers for their uplifting comments and suggestions for
improvements:
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxxvii
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Neale Cousland / Shutterstock.com
CHAPTER
1
I NTRODUCTION TO
COMPUTING AND
P ROGRAMMING
I N T H I S C H A P T E R , YO U W I L L :
Computers have penetrated every aspect of our society and have greatly simplified many
tasks. Can you picture yourself typing a paper on an electric typewriter? Would you use an
eraser to make your corrections? Would you start from scratch to increase or decrease
your margins or line spacing? Can you imagine living in an age without electronic
messaging or e-mail capability? What would you do without an automatic teller machine
(ATM) in your neighborhood?
Computers have become such an integral part of our lives that many of their functions are
taken for granted. Yet, only a few years ago, mobile apps, text messaging and cloud
computing were unknown. Social media technologies like internet forums, weblogs,
wikis, podcasts and social networks like Facebook were unknown. In 2012 social media
became one of the most powerful sources for news updates through platforms like Twitter
and Facebook. Advances in computing are occurring every day, and the programs that are
loaded on your computer have become very complex. The technology of wireless
communication is advancing quickly. Expectations are that tablet sales will grow by 200
percent through 2016. Over 100 million units will be sold in 2012. For most consumers,
tablets are not replacements for their conventional computers, but are added devices
they’ll purchase. Mobile applications for smartphones, pocket and tablet PCs, and other
handheld wireless computers are increasingly in demand. To reach this level of
complexity, software development has gone through a number of eras, and today
technical advances accumulate faster and faster. What new types of computer services
and programs will be integral to our daily lives in the future? This book focuses on
creating software programs. Before beginning the journey into software development, a
historical perspective on computing is included to help you see the potential for
advancements that awaits you.
History of Computers
Computing dates back some 5000 years. Many consider the abacus to be the first computer.
Used by merchants of the past and present for trading transactions, the abacus is a calculating
device that uses a system of sliding beads on a rack for addition and subtraction.
In 1642, another calculating device, called the Pascaline, was created. The Pascaline had
eight movable dials on wheels that could calculate sums up to eight figures long. Both the
abacus and Pascaline could perform only addition and subtraction. It was not until the
1830s that the first general-purpose computer, the Analytical Engine, was available.
Charles Babbage and his assistant, Lady Augusta Ada Bryon, Countess of Lovelace,
designed the Analytical Engine. Although it was very primitive by today’s standards, it
was the prototype for what is known today as a general-purpose computer. The Analytical
Engine included input devices, memory storage, a control unit that allowed processing
instructions in any sequence, and output devices.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
History of Computers | 3
In the 1980s, the U.S. Defense Department named the Ada programming language in honor 1
of Lady Lovelace. She has been called the world’s first programmer. Controversy surrounds
her title. Lady Byron was probably the fourth or fifth person to write programs. She did
programming as a student of Charles Babbage and reworked some of his calculations.
Many computer historians believe the present day to be in the fifth generation of modern
computing. Each era is characterized by an important advancement. In the mid-1940s, the
Second World War, with its need for strategic types of calculations, spurred on the first
generation of general-purpose machines. These large, first-generation computers were
distinguished by the use of vacuum tubes. They were difficult to program and limited in
functionality. The operating instructions were made to order for each specific task.
The invention of the transistor in 1956 led to second-generation computers, which were
smaller, faster, more reliable, and more energy efficient than their predecessors. The
software industry was born during the second generation of computers with the
introduction of FORTRAN and COBOL.
The third generation, 1964–1971, saw computers become smaller, as transistors were
squeezed onto small silicon discs (single chips), which were called semiconductors.
Operating systems, as they are known today, which allowed machines to run many
different programs at once, were also first seen in third-generation systems.
As time passed, chips kept getting smaller and capable of storing more transistors, making
computers more powerful and less expensive. The Intel 4004 chip, developed in 1971,
placed the most important components of a computer (central processing unit, memory,
and input and output controls) on a minuscule chip about half the size of a dime. Many
household items such as microwave ovens, television sets, and automobiles benefited from
the fourth generation of computing.
During the fourth generation, computer manufacturers tried to bring computing to
general consumers. In 1981, IBM introduced its personal computer (PC). The 1980s
saw an expansion in computer use as clones of the IBM PC made the personal computer
even more affordable. We also saw the development of Graphical User Interfaces (GUIs)
and the mouse as a handheld input device. The number of personal computers in use more
than doubled from two million in 1981 to 5.5 million in 1982. Ten years later, 65 million
PCs were in use.
According to the October 2010 U.S. Census Bureau’s Current Population Survey, released
in July 2012, over 76% of households in the United States had computers.
Defining a fifth generation of systems is somewhat difficult because the generation is still
young. Computers can now accept spoken word instructions, imitate human reasoning
through artificial intelligence, and communicate with devices instantaneously around the
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
4 | Chapter 1: Introduction to Computing and Programming
globe by transmitting digital media. Mobile apps are growing. By applying problem-
solving steps, expert systems assist doctors in making diagnoses. Healthcare professionals
are now using handheld devices in patients’ rooms to retrieve and update patient records.
Using handheld devices, drivers of delivery trucks are accessing global positioning systems
(GPS) to verify locations of customers for pickups and deliveries. Sitting at a traffic light,
you can check your e-mail, make airline reservations, remotely monitor and manage
household appliances, and access your checking and savings accounts. Using wireless
networks, students can access a professor’s notes when they enter the classroom.
Major advances in software are anticipated as integrated development environments
(IDEs) such as Visual Studio make it easier to develop applications for the Internet
rapidly. Because of the programmability of the computer, the imagination of software
developers is set free to conjure the computing functions of the future.
The real power of the computer does not lie in the hardware, which comprises the
physical components that make up the system. The functionality lies in the software
available to make use of the hardware. The hardware processes complex patterns of 0s and
1s. The software actually transposes these 0s and 1s into text, images, and documents that
people can read. The next section begins the discussion on software.
System Software
System software is loaded when you power on the computer. When thinking of system
software, most people think of operating systems. Operating systems such as Windows 8,
Android, iOS, Windows 7, and Linux are types of programs that oversee and coordinate the
resources on the machine. Included are file system utilities, small programs that take care of
locating files and keeping up with the details of a file’s name, size, and date of creation.
System software programs perform a variety of other functions: setting up directories;
moving, copying, and deleting files; transferring data from secondary storage to primary
memory; formatting media; and displaying data on screens. Operating systems include
communication programs for connecting to the Internet or connecting to output devices
such as printers. They include user interface subsystems for managing the look and feel of
the system.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
System and Application Software | 5
Operating systems are one type of system software. They are utility programs that make it 1
easier for you to use the hardware.
Another type of system software includes compilers, interpreters, and assemblers. As you
begin learning software development, you will write instructions for the computer using a
programming language. Modern programming languages are designed to be easy to
read and write. They are called high-level languages because they are written in
English-like statements. The programming language you will be using is C#
(pronounced see sharp). Other high-level computer programming languages include
Visual Basic, FORTRAN, Pascal, C, C++, and Java.
Before the computer can execute the instructions written in a programming language such
as C#, the instructions must be translated into machine-readable format. A compiler
makes this conversion. Figure 1-1 shows what a machine language instruction looks like.
Just as the English language has rules for sentence construction, programming languages
such as C# have a set of rules, called syntax, that must be followed. Before translating
code into machine-readable form, a compiler checks for rule violations. Compilers do not
convert any statements into machine language until all syntax errors are removed. Code
can be interpreted as well as compiled. Intepreters translate one statement of code into
machine-readable form and then they execute that line. They then translate the next
instruction, execute it, and so on. Unlike compilers, which look at entire pieces of code,
interpreters check for rule violations line by line. If the line does not contain an error, it
is converted to machine language. Interpreters are normally slower than compilers. Many
languages offer both compilers and interpreters, including C, BASIC, Python, and Lisp.
Assemblers convert the assembly programming language, which is a low-level
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Roland
Furieux, tome 3
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Language: French
ROLAND FURIEUX
Traduction nouvelle
PAR
FRANCISQUE REYNARD
TOME TROISIÈME
PARIS
ALPHONSE LEMERRE, ÉDITEUR
27-31, PASSAGE CHOISEUL, 27-31
M DCCC LXXX
ROLAND FURIEUX
CHANT XXVI.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookgate.com