Visual C# Tony Gaddis. Haywood Community College STARTING OUT WITH. Piyali Sengupta. Third Edition. Global Edition contributions by.

Similar documents
ony Gaddis Haywood Community College STARTING OUT WITH PEARSON Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto

Prelude to Programming

Database Concepts. David M. Kroenke UNIVERSITATSBIBLIOTHEK HANNOVER

PROBLEM SOLVING USING JAVA WITH DATA STRUCTURES. A Multimedia Approach. Mark Guzdial and Barbara Ericson PEARSON. College of Computing

THE AVR MICROCONTROLLER AND EMBEDDED SYSTEMS. Using Assembly and С

World Wide Web PROGRAMMING THE PEARSON EIGHTH EDITION. University of Colorado at Colorado Springs

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY

Access ComprehGnsiwG. Shelley Gaskin, Carolyn McLellan, and. Nancy Graviett. with Microsoft

Data Structures and Abstractions with Java

This page intentionally left blank

Essentials of Database Management

Business Driven Data Communications

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

This page intentionally left blank

Search Engines Information Retrieval in Practice

Objects First with Java

DATA AND COMPUTER COMMUNICATIONS

Systems:;-'./'--'.; r. Ramez Elmasri Department of Computer Science and Engineering The University of Texas at Arlington

Data Structures and Abstractions with Java

CJT^jL rafting Cm ompiler

Integrated Approach. Operating Systems COMPUTER SYSTEMS. LEAHY, Jr. Georgia Institute of Technology. Umakishore RAMACHANDRAN. William D.

Programming in Python 3

HCS12 Microcontroller and Embedded Systems: Using Assembly and C with CodeWarrior 1 st Edition

Real-Time Systems and Programming Languages

FUNDAMENTALS OF. Database S wctpmc. Shamkant B. Navathe College of Computing Georgia Institute of Technology. Addison-Wesley

CRYPTOGRAPHY AND NETWORK SECURITY

Contributor. International Edition contributions by. Piyali Sengupta PEARSON. New York San Francisco Upper

Framework Design Guidelines

MACHINES AND MECHANISMS

AND ASSURANCE AN INTEGRATED APPROACH SIXTEENTH EDITION GLOBAL EDITION

PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN

DB2 SQL Tuning Tips for z/os Developers

DATA ABSTRACTION AND PROBLEM SOLVING WITH JAVA

FUNDAMENTALS OF SEVENTH EDITION

Networking Security Essentials 4th Edition Solution Manual

The Unified Modeling Language User Guide

MECHATRONICS. William Bolton. Sixth Edition ELECTRONIC CONTROL SYSTEMS ENGINEERING IN MECHANICAL AND ELECTRICAL PEARSON

^l^s^^^^^^^^^^s^^^ ^.1^L^ gs *^gs (s^s^^^^s^^ ^S^^^^ls

JAVASCRIPT FOR PROGRAMMERS

Starting Out With C From Control Structures To Objects Plus Myprogramminglab With Pearson Etext Access Card Package 8th Edition

CLASSIC DATA STRUCTURES IN JAVA

Software Engineering Ian Sommerville Pearson Education File Type

DATABASE SYSTEM CONCEPTS

MyProgram m i ng Lab. get with the programming. Through the power of practice and immediate personalized

Web Development and Design Foundations with HTML5

Microsoft Visual Studio 2010

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez

An Introduction to Search Engines and Web Navigation

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Application Programming

MODERN DATABASE MANAGEMENT

Workbook for C++ THIRD EDITION. Yedidyah Langsam, Ph.D. Brooklyn College of the City University of New York. Custom Publishing

Virtualization from the Trenches

\ Smart Client 0" Deploymentwith v^ ClickOnce

Welcome to Starting Out with Programming Logic and Design, Third Edition.

Domain-Specific. Languages. Martin Fowler. AAddison-Wesley. Sydney Tokyo. With Rebecca Parsons

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition

Core Java Volume Ii Advanced Features 10th Edition

Cloud Computing and SOA Convergence in Your Enterprise

IPHONE FOR PROGRAMMERS: AN APP-DRIVEN APPROACH

This page intentionally left blank

AssEivibly LANquAqE for

ECLIPSE RICH CLIENT PLATFORM

Fundamentals of. Database Systems. Shamkant B. Navathe. College of Computing Georgia Institute of Technology PEARSON.

C++ Primer, Fifth Edition

Modern Information Retrieval

Harvey Deitel. Abbey Deitel

Quality Code. Software Testing Principles, Practices, and Patterns. Stephen Vance. AAddison-Wesley

C for Electronic Engineering

Digital System Design with SystemVerilog

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

VHDL. Douglas L. Perry. Third Edition

The Java Tutorial. A Short Course on the Basics. Raymond Gallardo. Sowmya Kannan. AAddison-Wesley. Sharon Biocca Zakhour.

Object-Oriented Programming in C# (VS 2015)

FrontPage 98: The Complete Reference

Object-Oriented Programming in C# (VS 2012)

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

1. A Web Form created in Visual Basic can only be displayed in Internet Explorer. True False

Software Engineering Ian Sommerville 7th Edition

egensburg, February 1st, 2005

LATEX. Leslie Lamport. Digital Equipment Corporation. Illustrations by Duane Bibby. v ADDISON-WESLEY

Networking. Second Edition. Jeffrey S. Beasley. New Mexico State University

Fit for Developing Software

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

C# 2008 and.net Programming for Electronic Engineers - Elektor - ISBN

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at

DATA STRUCTURES AND PROBLEM SOLVING USING JAVA

Refactoring HTML. Improving the Design of Existing Web Applications. Elliotte Rusty Harold. TT rvaddison-wesley

Programming Wireless Devices with the Java 2 Platform, Micro Edition

Essentials. Oracle Solaris Cluster. Tim Read. Upper Saddle River, NJ Boston Indianapolis San Francisco. Capetown Sydney Tokyo Singapore Mexico City

Oracle Certified Associate Java Se 7 Programmer Study Guide

Elements Of Programming Interviews In Python The Insiders Guide

Simulation Modeling and Analysis

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. AAddison-Wesley

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. .~Addison-Wesley

Opengl Programming On Mac Os X Architecture Performance

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu

ECLIPSE MODELING PROJECT

Transcription:

STARTING OUT WITH Visual C# 2012 Third Edition Global Edition Tony Gaddis Haywood Community College Global Edition contributions by Piyali Sengupta PEARSON Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo

Contents Preface 11 Attention Students 16 Chapter 1 Introduction to Computers and Programming 17 1.1 Introduction 17 1.2 Hardware and Software 19 1.3 How Computers Store Data 23 1.4 How a Program Works 27 1.5 Graphical User Interfaces 34 1.6 Objects 37 1.7 The Program Development Process 39 1.8 Getting Started with the Visual Studio Environment 43 TUTORIAL 1-1: Starting Visual Studio and Setting Up the En vironment 44 TUTORIAL 1-2; Starting a New Visual C# Project 47 TUTORIAL 1-3: Saving and Closing a Project 49 TUTORIAL 1-4: Opening an Existing Project 57 TUTORIAL 1-5: Getting Familiar with the Visual Studio Environment 59 Key Terms 60 Review Questions 61 Programming Problems 66 Chapter 2 Introduction to Visual C# 69 2.1 Getting Started with Forms and Controls 69 2.2 Creating the GUI for Your First Visual C# Application: The Hello World Application 78 TUTORIAL 2-1: Creating the GUI for the Hello World Application...,.,... 79 2.3 Introduction to C# Code 83 2.4 Writing Code for the Hello World Application 93 TUTORIAL 2 2: Writing Code for the Hello World... Application 93 2.5 Label Controls 96 TUTORIAL 2-3: Creating the Language Translator Application 104 2.6 Making Sense of IntelliSense 107 2.7 PictureBox Controls 108 TUTORIAL 2-4: Creating the Flags Application 112 TUTORIAL 2-5: Creating the Card flip Application 116 2.8 Comments, Blank Lines, and Indentation 120 2.9 Writing the Code to Close an Application's Form 122 2.10 Dealing with Syntax Errors 123 Key Terms 125 Review Questions 125 Programming Problems 130 6

Contents 7 Chapter 3 Processing Data 135 3.1 Reading Input with TextBox Controls 135 3.2 A First Look at Variables 137 TUTORIAL 3-1: The Birth Date String Application 144 3.3 Numeric Data Types and Variables 149 3.4 Performing Calculations 154 3.5 Inputting and Outputting Numeric Values 159 TUTORIAL 3-2: Calculating Fuel Economy 164 3.6 Formatting Numbers with the Tostring Method 167 TUTORIAL 3-3: Creating the Sale Price Calculator Application with Currency Formatting 170 3.7 Simple Exception Handling 174 TUTORIAL 3-4: Creating the Test Average Application with Exception Handling.. 178 3.8 Using Named Constants 182 3.9 Declaring Variables as Fields 183 TUTORIAL 3-5: Creating the Change Counter Application 187 3.10 Using the Math Class 191 3.11 More GUI Details 193 Key Terms 203 Review Questions 203 Programming Problems 208 Chapter 4 Making Decisions 213 4.1 Decision Structures and the if Statement 213 TUTORIAL 4-1: Completing the Test Score Average Application 218 4.2 The if-eise Statement 222 TUTORIAL 4-2: Completing the Payroll with Overtime Application 224 4.3 Nested Decision Structures 228 TUTORIAL 4-3: Completing the Loan Qualifier Application 230 4.4 Logical Operators 239 4.5 bool Variables and Flags 244 4.6 Comparing Strings 244 4.7 Preventing Data Conversion Exceptions with the TryParse Methods... 248 TUTORIAL 4-4: Calculating Fuel Economy 253 4.8 Input Validation 256 4.9 Radio Buttons and Check Boxes 257 TUTORIAL 4-5: Creating the Color Theme Application 262 4.10 The switch Statement 264 4.11 Introduction to List Boxes 267 TUTORIAL 4-6: Creating the Time Zone Application 269 Key Terms 273 Review Questions 273 Programming Problems 277 Chapter 5 Loops, Files, and Random Numbers 283 5.1 More about ListBoxes 283 5.2 The while Loop 285 TUTORIAL 5-1: Using a Loop to Calculate an Account Balance 289 TUTORIAL 5-2: Enhancing the Ending Balance Application 292

8 Contents 5.3 The ++ and - operators 296-5.4 The for Loop 297 TUTORIAL 5-3: Using the for Loop 302 5.5 The do-while Loop 305 5.6 Using Files for Data Storage 307 TUTORIAL 5-4: Writing Data to a Text File 313 TUTORIAL 5-5: Appending Data co the Frienci.txt File 318 TUTORIAL 5-6: Using a Loop to Read to the End of a File 326 TUTORIAL 5-7: Calculating a Running Total 330 5.7 The OpenFileDialog and SaveFileDialog Controls 333 5.8 Random Numbers 339 TUTORIAL 5-8: Simulating Coin Tosses 341 5.9 The Load Event 344 TUTORIAL 5-9: Creating a Load Event Handler 345 Key Terms 348 Review Questions 348 Programming Problems 351 Chapter 6 Modularizing Your Code with Methods 355 6.1 Introduction to Methods 355 6.2 void Methods 357 TUTORIAL 6-1: Creating and Calling Methods 361 6.3 Passing Arguments to Methods 365 TUTORIAL 6-2: Passing an Argument to a Method 368 6.4 Passing Arguments by Reference 376 TUTORIAL 6-3: Using an Output Parameter 379 6.5 Value-Returning Methods 383 TUTORIAL 6-4: Writing a Value-Returning Method 388 TUTORIAL 6-5: Modularizing Input Validation with a Boolean Method 391 Key Terms 397 Review Questions 397 Programming Problems 400 Chapter 7 Arrays and Lists 405 7.1 Value Types and Reference Types 405 7.2 Array Basics 408 TUTORIAL 7-1: Using an Array to Hold a List of Random Lottery Numbers 415 7.3 Working with Files and Arrays 420 7.4 Passing Arrays as Arguments to Methods 423 7.5 Some Useful Array Algorithms 430 TUTORIAL 7-2: Processing an Array 440 7.6 Advanced Algorithms for Sorting and Searching Arrays 445 7.7 Two-Dimensional Arrays 452 TUTORIAL 7-3: Completing the Seating Chart Application 455 7.8 Jagged Arrays 461 7.9 The List Collection 462 TUTORIAL 7-4: Completing the Test Score List Application 468 Key Terms 474 Review Questions 474 Programming Problems 477

Contents 9 Chapter 8 More about Processing Data 481 8.1 Introduction 481 8.2 String and Character Processing 481 TUTORIAL 8-1: Completing the Password Validation Application 487 TUTORIAL 8-2: Completing the Telephone format Application 500 TUTORIAL 8-3: Completing the Telephone Unformat Application 504 TUTORIAL 8-4: Completing the CSV Reader Application 510 8.3 Structures 515 TUTORIAL 8-5: Completing the Phonebook Application 525 8.4 Enumerated Types 530 TUTORIAL 8-6: Completing the Color Spectrum Application 533 8.5 The ImageList Control 538 TUTORIAL 8-7: Completing the Random Card Application 540 Key Terms 543 Review Questions 543 Programming Problems 547 Chapter 9 Classes and Multiform Projects 551 9.1 Introduction to Classes 551 TUTORIAL 9-1: Creating and Using the Coin Class 558 9.2 563 Properties TUTORIAL 9-2: Creating and Using the CellPhone Class 566 9.3 Parameterized Constructors and Overloading 571 TUTORIAL 9-3: Creating and Using the BankAccount Class 572 9.4 Storing Class Type Objects in Arrays and Lists 578 TUTORIAL 9-4: Completing the Cell Phone Inventory Application 580 9.5 Finding the Classes and Their Responsibilities in a Problem 584 9.6 Creating Multiple Forms in a Project 592 TUTORIAL 9-5: Creating an Application with Two Forms 597 Key Terms 602 Review Questions 602 Programming Problems 606 Chapter 10 Inheritance and Polymorphism 609 10.1 Inheritance 609 TUTORIAL 10-1: Creating and Testing the SavingsAccount and CDAccount Classes 619 10.2 Polymorphism 627 TUTORIAL 10-2: Completing the Polymorphism Application 632 10.3 Abstract Classes 637 TUTORIAL 10-3: Completing the Computer Science Student Application 639 Key Terms 644 Review Questions 644 Programming Problems 647 Chapter 11 Databases 649 11.1 Introduction to Database Management Systems 649 11.2 Tables, Rows, and Columns 651 11.3 Creating a Database in Visual Studio 654

10 Contents TUTORIAL 11-1: Starting the Phone Book Application and Creating the Phonelist.mdf Database 655 11.4 The DataG ridview Control 664 TUTORIAL 11-2: Completing the Phone Book Application 664 11.5 Connecting to an Existing Database and Using... Details View Controls 672 TUTORIAL 11-3: Creating the Products Application and Using a Details View... 673 11.6 More about Data-Bound Controls 681 TUTORIAL 11-4: Creating the Product Lookup Application 685 TUTORIAL 11-5: Creating the Multiform Products Application 688 11.7 Selecting Data with the SQL Select Statement 693 TUTORIAL 11-6: Creating the Product Queries Applicarion 700 TUTORIAL 11-7: Creating the Product Queries Application 709 TUTORIAL 11-8: Creating the Product Search Application 713 Key Terms 719 Review Questions 719 Programming Problems 723 Appendix A C# Primitive Data Types 725 Appendix B Additional User Interface Controls 727 Appendix C ASCII/Unicode Characters 747 Appendix D Answers to Checkpoint Questions 749 Index 769