Computer Science

Contents

Chapters 16–31 are PDF documents posted online at the book’s Companion Website (located at  www.pearsonhighered.com/deitel/ ).

Preface

Before You Begin

1 Introduction to Computers, the Internet and Visual Basic

1.1 Introduction

1.2 Hardware and Moore’s Law

1.3 Data Hierarchy

1.4 Computer Organization

1.5 Machine Languages, Assembly Languages and High-Level Languages

1.6 Object Technology

1.7 Internet and World Wide Web

1.8 Visual Basic

1.8.1 Object-Oriented Programming

1.8.2 Event-Driven Programming

1.8.3 Visual Programming

1.8.4 Internet and Web Programming

1.8.5 Other Key Contemporary Programming Languages

1.9 Microsoft’s .NET

1.9.1 .NET Framework

1.9.2 Common Language Runtime

1.10 Microsoft’s Windows® Operating System

1.11 Windows Phone 8 for Smartphones

1.11.1 Selling Your Apps in the Windows Phone Marketplace

1.11.2 Free vs. Paid Apps

1.11.3 Testing Your Windows Phone Apps

1.12 Windows Azure™ and Cloud Computing

1.13 Visual Studio Integrated Development Environment

1.14 Test-Driving the Visual Basic Advanced Painter App in Visual Studio 2012

2 Dive Into® Visual Studio Express 2012 for Windows Desktop

2.1 Introduction

2.2 Overview of the Visual Studio 2012 IDE

2.3 Menu Bar and Toolbar

2.4 Navigating the Visual Studio IDE

2.4.1 Solution Explorer

2.4.2 Toolbox

2.4.3 Properties Window

2.5 Using Help

2.6 Using Visual App Development to Create a Simple App that Displays Text and an Image

2.7 Wrap-Up

2.8 Web Resources

3 Introduction to Visual Basic Programming

3.1 Introduction

3.2 Programmatically Displaying Text in a Label

3.2.1 Analyzing the Program

3.2.2 Modifying ASimpleApp to Programmatically Change the Label’s Text Property

3.3 Addition Program

3.4 Building the Addition Program

3.5 Memory Concepts

3.6 Arithmetic

3.7 Decision Making: Equality and Relational Operators

3.8 Wrap-Up

4 Introduction to Problem Solving and Control Statements

4.1 Introduction

4.2 Algorithms

4.3 Pseudocode Algorithm

4.4 Control Structures

4.5 If…Then Selection Statement

4.6 If…Then…Else Selection Statement

4.7 Nested If…Then…Else Selection Statements

4.8 Repetition Statements

4.9 Compound Assignment Operators

4.10 Formulating Algorithms: Counter-Controlled Repetition

4.11 Formulating Algorithms: Nested Control Statements

4.12 Using the Debugger: Locating a Logic Error

4.12.1 Breakpoints and Running the Program

4.12.2 Data Tip Box

4.12.3 Locals Window

4.12.4 Using the Step Over Command to Execute Statements

4.13 Wrap-Up

5 Problem Solving and Control Statements: Part 2

5.1 Introduction

5.2 For…Next Repetition Statement

5.2.1 For…Next Statement Header Components

5.2.2 General Form of a For…Next Statement

5.2.3 Declaring the Control Variable Before a For…Next Statement

5.2.4 Using Expressions in the For…Next Statement’s Header

5.2.5 For…Next Statement UML Activity Diagram

5.2.6 Local Type Inference

5.3 Examples Using the For…Next Statement

5.4 App: Interest Calculator

5.5 Formulating Algorithms: Nested Repetition Statements

5.6 Select…Case Multiple-Selection Statement

5.7 Do…Loop While and Do…Loop Until Repetition Statements

5.8 Using Exit to Terminate Repetition Statements

5.9 Using Continue in Repetition Statements

5.10 Logical Operators

5.11 App: Dental Payment Calculator

5.12 Wrap-Up

6 Methods

6.1 Introduction

6.2 Classes and Methods

6.3 Subroutines: Methods That Do Not Return a Value

6.4 Functions: Methods That Return a Value

6.5 Implicit Argument Conversions

6.6 Option Strict and Data-Type Conversions

6.7 Passing Arguments: Pass-by-Value vs. Pass-by-Reference

6.8 Scope of Declarations

6.9 Case Study: Random-Number Generation

6.9.1 Scaling and Shifting of Random Numbers

6.9.2 Randomly Selecting Images

6.9.3 Rolling Dice Repeatedly and Displaying Statistics

6.10 Case Study: A Game of Chance

6.11 Method Overloading

6.12 Optional Parameters

6.13 Using the Debugger: Debugging Commands

6.14 Wrap-Up

7 Arrays

7.1 Introduction

7.2 Arrays

7.3 Declaring and Allocating Arrays

7.4 Initializing the Values in an Array

7.5 Summing the Elements of an Array

7.6 Using Arrays to Analyze Survey Results

7.7 Die-Rolling App with an Array of Counters

7.8 Case Study: Flag Quiz

7.9 Passing an Array to a Method

7.10 For Each…Next Repetition Statement

7.11 Sorting an Array with Method Sort of Class Array

7.12 Searching an Array with Linear Search

7.13 Searching a Sorted Array with Array Method BinarySearch

7.14 Rectangular Arrays

7.15 Case Study: Maintaining Grades Using a Rectangular Array

7.16 Resizing an Array with the ReDim Statement

7.17 Wrap-Up

8 Files

8.1 Introduction

8.2 Data Hierarchy

8.3 Files and Streams

8.4 Test-Driving the Credit Inquiry App

8.5 Writing Data Sequentially to a Text File

8.5.1 Class CreateAccounts

8.5.2 Opening the File

8.5.3 Managing Resources with the Using Statement

8.5.4 Adding an Account to the File

8.5.5 Closing the File and Terminating the App

8.6 Building Menus with the Windows Forms Designer

8.7 Credit Inquiry App: Reading Data Sequentially from a Text File

8.7.1 Implementing the Credit Inquiry App

8.7.2 Selecting the File to Process

8.7.3 Specifying the Type of Records to Display

8.7.4 Displaying the Records

8.8 Wrap-Up

9 Object-Oriented Programming: Classes and Objects

9.1 Introduction

9.2 Classes, Objects, Methods and Instance Variables

9.3 Account Class

9.4 Value Types and Reference Types

9.5 Case Study: Card Shuffling and Dealing Simulation

9.6 Case Study: Time Class

9.7 Class Scope

9.8 Object Initializers

9.9 Auto-Implemented Properties

9.10 Using Me to Access the Current Object

9.11 Garbage Collection

9.12 Shared Class Members

9.13 Const and ReadOnly Fields

9.14 Shared Methods and Class Math

9.15 Object Browser

9.16 Wrap-Up

10 Object-Oriented Programming: Inheritance and Polymorphism

10.1 Introduction

10.2 Base Classes and Derived Classes

10.3 Business Case Study: Commission Employees Class Hierarchy

10.3.1 Creating Base Class CommissionEmployee

10.3.2 Creating Derived Class BasePlusCommissionEmployee

10.3.3 Testing Class BasePlusCommissionEmployee

10.4 Constructors in Derived Classes

10.5 Protected Members

10.6 Introduction to Polymorphism: A Polymorphic Video Game

10.7 Abstract Classes and Methods

10.8 Case Study: Payroll System Class Hierarchy Using Polymorphism

10.8.1 Abstract Base Class Employee

10.8.2 Concrete Derived Class SalariedEmployee

10.8.3 Concrete Derived Class CommissionEmployee

10.8.4 Indirect Concrete Derived Class BasePlusCommissionEmployee

10.8.5 Demonstrating Polymorphic Processing

10.9 Online Case Study: Interfaces

10.10 Wrap-Up

11 Introduction to LINQ

11.1 Introduction

11.2 Querying an Array of Primitive-Type Elements Using LINQ

11.3 Querying an Array of Reference-Type Elements Using LINQ

11.4 Deferred Execution and Transforming Query Results

11.5 LINQ Resource Center

11.6 Wrap-Up

12 Databases and LINQ

12.1 Introduction

12.2 Relational Databases

12.3 A Books Database

12.4 LINQ to Entities and the ADO.NET Entity Framework

12.5 Querying a Database with LINQ

12.5.1 Creating the ADO.NET Entity Data Model Class Library

12.5.2 Creating a Windows Forms Project and Configuring It to Use the Entity Data Model

12.5.3 Data Bindings Between Controls and the Entity Data Model

12.6 Dynamically Binding Query Results

12.6.1 Creating the Display Query Results GUI

12.6.2 Coding the Display Query Results App

12.7 Retrieving Data from Multiple Tables with LINQ

12.8 Creating a Master/Detail View App

12.8.1 Creating the Master/Detail GUI

12.8.2 Coding the Master/Detail App

12.9 Address Book Case Study

12.9.1 Creating the Address Book App’s GUI

12.9.2 Coding the Address Book App

12.10 Tools and Web Resources

12.11 Wrap-Up

13 Web App Development with ASP.NET

13.1 Introduction

13.2 Web Basics

13.3 Multitier App Architecture

13.4 Your First Web App

13.4.1 Building the WebTime App

13.4.2 Examining WebTime.aspx’s Code-Behind File

13.5 Standard Web Controls: Designing a Form

13.6 Validation Controls

13.7 Session Tracking

13.7.1 Cookies

13.7.2 Session Tracking with HttpSessionState

13.7.3 Options.aspx: Selecting a Programming Language

13.7.4 Recommendations.aspx: Displaying Recommendations Based on Session Values

13.8 Case Study: Database-Driven ASP.NET Guestbook

13.8.1 Building a Web Form that Displays Data from a Database

13.8.2 Modifying the Code-Behind File for the Guestbook App

13.9 Online Case Study: ASP.NET AJAX

13.10 Online Case Study: Password-Protected Books Database App

13.11 Wrap-Up

14 Windows Forms GUI: A Deeper Look

14.1 Introduction

14.2 Controls and Components

14.3 Creating Event Handlers

14.4 Control Properties and Layout

14.5 GroupBoxes and Panels

14.6 ToolTips

14.7 Mouse-Event Handling

14.8 Keyboard-Event Handling

14.9 Menus

14.10 MonthCalendar Control

14.11 DateTimePicker Control

14.12 LinkLabel Control

14.13 ListBox and CheckedListBox Controls

14.14 Multiple Document Interface (MDI) Windows

14.15 Visual Inheritance

14.16 Animation with the Timer Component

14.17 Wrap-Up

15 Graphics and Multimedia

15.1 Introduction

15.2 Drawing Classes and the Coordinate System

15.3 Graphics Contexts and Graphics Objects

15.4 Colors

15.5 Fonts

15.6 Drawing Lines, Rectangles and Ovals

15.7 Drawing Arcs

15.8 Drawing Polygons and Polylines

15.9 Additional Brush Types

15.10 Loading, Displaying and Scaling Images

15.11 Windows Media Player

15.12 Printing

15.13 Wrap-Up

1. Introduction to Computers, the Internet and Visual Basic

The chief merit of language is clearness.

—Galen

Our life is frittered away with detail. . . . Simplify, simplify.

—Henry David Thoreau

Man is still the most extraordinary computer of all.

—John F. Kennedy

Objectives

In this chapter you’ll learn:

• Basic hardware, software and data concepts.

• The different types of programming languages.

• The history of the Visual Basic programming language and the Windows operating system.

• What cloud computing with Windows Azure™ is.

• Basics of object technology.

• The history of the Internet and the World Wide Web.

• The parts that Windows, .NET, Visual Studio 2012 and Visual Basic 2012 play in the Visual Basic ecosystem.

• To test-drive a Visual Basic 2012 drawing app.

Outline

1.1 Introduction

1.2 Hardware and Moore’s Law

1.3 Data Hierarchy

1.4 Computer Organization

1.5 Machine Languages, Assembly Languages and High-Level Languages

1.6 Object Technology

1.7 Internet and World Wide Web

1.8 Visual Basic

1.8.1 Object-Oriented Programming

1.8.2 Event-Driven Programming

1.8.3 Visual Programming

1.8.4 Internet and Web Programming

1.8.5 Other Key Contemporary Programming Languages

1.9 Microsoft’s .NET

1.9.1 .NET Framework

1.9.2 Common Language Runtime

1.10 Microsoft’s Windows® Operating System

1.11 Windows Phone 8 for Smartphones

1.11.1 Selling Your Apps in the Windows Phone Marketplace

1.11.2 Free vs. Paid Apps

1.11.3 Testing Your Windows Phone Apps

1.12 Windows Azure™ and Cloud Computing

1.13 Visual Studio Integrated Development Environment

1.14 Test-Driving the Visual Basic Advanced Painter App in Visual Studio 2012

Self-Review Exercises  |  Answers to Self-Review Exercises  |  Exercises  |  Making a Difference Exercises

1.1. INTRODUCTION

Welcome to Visual Basic 2012 which, from this point forward, we’ll refer to simply as Visual Basic. Visual Basic is a powerful computer programming language that’s appropriate for building substantial information systems. This book explains how to develop software with Visual Basic.

You’re already familiar with the powerful tasks computers perform. Using this textbook, you’ll write instructions commanding computers to perform those kinds of tasks and you’ll prepare yourself to address new challenges.

Computers process data under the control of sequences of instructions called computer programs. These programs guide the computer through actions specified by people called computer programmers. The programs that run on a computer are referred to as software. In this book, you’ll learn object-oriented programming—today’s key programming methodology that’s enhancing programmer productivity and reducing software development costs. You’ll create many software objects that model both abstract and real-world things. And you’ll build Visual Basic apps (applications) for a variety of environments including the desktop and tablets—and new to this edition of the book—“the cloud” and even mobile devices like smartphones.

1.2. HARDWARE AND MOORE’S LAW

A computer consists of various devices referred to as hardware, such as the keyboard, screen, mouse, hard disks, memory, DVD drives, printer and processing units. Every year or two, the capacities of computer hardware have approximately doubled inexpensively. This remarkable trend often is calledMoore’s Law, named for the person who identified it, Gordon Moore, co-founder of Intel—the leading manufacturer of the processors in to-day’s computers and embedded systems, such as smartphones, appliances, game controllers, cable set-top boxes and automobiles.

Moore’s Law and related observations apply especially to

• the amount of memory that computers have for running programs and processing data

• the amount of secondary storage (such as hard disk storage) they have to hold programs and data over longer periods of time

• their processor speeds—the speeds at which computers execute their programs (i.e., do their work).

Similar growth has occurred in the communications field, in which costs have plummeted as enormous demand for communications bandwidth (i.e., information-carrying capacity) has attracted intense competition. We know of no other fields in which technology improves so quickly and costs fall so rapidly. Such phenomenal improvement is truly fostering the Information Revolution and creating significant career opportunities.

1.3. DATA HIERARCHY

Data items processed by computers form a data hierarchy that becomes larger and more complex in structure as we progress from the simplest data items (called “bits”) to richer data items, such as characters, fields, and so on. Figure 1.1 illustrates a portion of the data hierarchy.

Image

Fig. 1.1. Data hierarchy.

Bits

The smallest data item in a computer can assume the value 0 or the value 1. Such a data item is called abit (short for “binary digit”—a digit that can assume either of two values). It’s remarkable that the impressive functions performed by computers involve only the simplest manipulations of 0s and 1s—examining a bit’s value, setting a bit’s value and reversing a bit’s value (from 1 to 0 or from 0 to 1). We discuss binary numbers in more detail in Appendix C, Number Systems.

Characters

It’s tedious for people to work with data in the low-level form of bits. Instead, we prefer to work withdecimal digits (0–9), uppercase letters (A–Z), lowercase letters (a–z), and special symbols (e.g., $, @, %, &, *, (, ), –, +, “, :, ? and / ). Digits, letters and special symbols are known as characters. The computer’s character set is the set of all the characters used to write programs and represent data items on that device. Computers process only 1s and 0s, so every character is represented as a pattern of 1s and 0s. The Unicode character set contains characters for many of the world’s languages. Visual Basic supports several character sets, including 16-bit Unicode® characters that are composed of twobytes—each byte is composed of eight bits. See Appendix D for more information on the ASCII (American Standard Code for Information Interchange) character set—the popular subset of Unicode that represents uppercase and lowercase letters in the English alphabet, digits and some common special characters.

Fields

Just as characters are composed of bits, fields are composed of characters or bytes. A field is a group of characters or bytes that conveys meaning. For example, a field consisting of uppercase and lowercase letters could be used to represent a person’s name, and a field consisting of decimal digits could represent a person’s age.

Records

Several related fields can be used to compose a record. In a payroll system, for example, the record for an employee might consist of the following fields (possible types for these fields are shown in parentheses):

• Employee identification number (a whole number)

• Name (a string of characters)

• Address (a string of characters)

• Hourly pay rate (a number with a decimal point)

• Year-to-date earnings (a number with a decimal point)

• Amount of taxes withheld (a number with a decimal point)

Thus, a record is a group of related fields. In the preceding example, all the fields belong to the sameemployee. A company might have many employees and a payroll record for each one.

Files

file is a group of related records. [Note: More generally, a file contains arbitrary data in arbitrary formats. In some operating systems, a file is viewed simply as a sequence of bytes—any organization of the bytes in a file, such as organizing the data into records, is a view created by the programmer.] It’s not unusual for an organization to have thousands or even millions of files, some containing billions or even trillions of characters of information. You’ll work with files in Chapter 8.

Database

database is a collection of data that’s organized for easy access and manipulation. The most popular database model is the relational database in which data is stored in simple tables. A table includesrecords composed of fields. For example, a table of students might include first name, last name, major, year, student ID number and grade point average fields. The data for each student is a record, and the individual pieces of information in each record are the fields. You can search, sort and otherwise manipulate the data based on its relationship to multiple tables or databases. For example, a university might use data from the student database in combination with data from databases of courses, on-campus housing, meal plans, etc. We discuss databases in Chapters 12–13.

Big Data

The amount of data being produced worldwide is enormous and growing explosively. Figure 1.2 shows various common byte measurements. According to IBM, approximately 2.5 quintillion bytes (2.5exabytes) of data are created daily and 90% of the world’s data was created in just the past two years!1According to an IDC study, approximately 1.8 zettabytes (equal to 1.8 trillion gigabytes) of data was used worldwide in 2011.2

1. www-01.ibm.com/software/data/bigdata/.

2. www.emc.com/collateral/about/news/idc-emc-digital-universe-2011-infographic.pdf.

Image

Fig. 1.2. Byte measurements.

1.4. COMPUTER ORGANIZATION

Regardless of differences in physical appearance, computers can be envisioned as divided into variouslogical units or sections.

Input Unit

This “receiving” section obtains information (data and computer programs) from input devices and places it at the disposal of the other units for processing. Most information is entered into computers through keyboards, touch screens and mouse devices. Other forms of input include receiving voice commands, scanning images and barcodes, reading from secondary storage devices (such as hard drives, DVD drives, Blu-ray Disc™ drives and USB flash drives—also called “thumb drives” or “memory sticks”), receiving video from a webcam or smartphone and having your computer receive information from the Internet (such as when you download videos from YouTube or e-books from Amazon). Newer forms of input include position data from GPS devices, and motion and orientation information from accelerometers in smartphones or game controllers (such as Microsoft® Kinect™, Nintendo’s Wii™ Remote and Sony’s PlayStation® Move).

Output Unit

This “shipping” section takes information that the computer has processed and places it on variousoutput devices to make it available for use outside the computer. Most information that’s output from computers today is displayed on screens; printed on paper (“going green” discourages this); played as audio or video on PCs and media players (such as Apple’s iPods) and giant screens in sports stadiums; transmitted over the Internet or used to control other devices, such as robots, 3D printers and “intelligent” appliances.

Memory Unit

This rapid-access, relatively low-capacity “warehouse” section retains information that’s entered through the input unit, making it immediately available for processing when needed. The memory unit also retains processed information until it can be placed on output devices by the output unit. Information in the memory unit is volatile—it’s typically lost when the computer’s power is turned off. The memory unit is often called either memory or primary memory—on desktop and notebook computers it commonly contains as much as 16 GB (gigabytes).

Arithmetic and Logic Unit (ALU)

This “manufacturing” section performs calculations, such as addition, subtraction, multiplication and division. It also contains the decision mechanisms that allow the computer, for example, to comparetwo items from the memory unit to determine whether they’re equal. In today’s systems, the ALU is usually implemented as part of the next logical unit, the CPU.

Central Processing Unit (CPU)

This “administrative” section supervises the operation of the other sections. The CPU tells the input unit when information should be read into the memory unit, tells the ALU when information from the memory unit should be used in calculations and tells the output unit when to send information from the memory unit to certain output devices. Many of today’s computers have multiple CPUs and, hence, can perform many operations simultaneously. A multi-core processor implements multiple CPUs on a single “microchip”—a dual-core processor has two CPUs and a quad-core processor has fourCPUs. Many of today’s desktop computers have quad-core processors that can execute billions of instructions per second. In this book you’ll use Microsoft’s new Async technology to write programs that can keep CPUs running in parallel to get your computing tasks done faster.

Secondary Storage Unit

This is the long-term, high-capacity “warehousing” section. Programs or data not actively being used by the other units normally are placed on secondary storage devices (such as your hard drive) until they’re again needed, possibly hours, days, months or even years later. Information on secondary storage devices is persistent—it’s preserved even when the computer’s power is turned off. Secondary storage data takes much longer to access than information in primary memory, but the cost per unit of secondary storage is much less than that of primary memory. Examples of secondary storage devices include CD drives, DVD drives and flash drives, some of which can hold up to 768 GB. Typical hard drives on desktop and notebook computers can hold up to 2 TB. New to this edition, you’ll see that storage in the cloud can be viewed as additional secondary storage accessible by your Visual Basic apps.

1.5. MACHINE LANGUAGES, ASSEMBLY LANGUAGES AND HIGH-LEVEL LANGUAGES

Programmers write instructions in various programming languages (such as Visual Basic), some directly understandable by computers and others requiring intermediate translation steps.

Machine Languages

Any computer can directly understand only its own machine language, defined by its hardware architecture. Machine languages generally consist of numbers, ultimately reduced to 1s and 0s. Such languages are cumbersome for humans, who prefer meaningful words like “add” and “subtract” to indicate the operations to be performed, so the machine language numeric versions of these instructions are referred to as code. The term “code” has become more broadly used and now refers to the program instructions in all levels of programming languages.

Assembly Languages and Assemblers

Machine language was simply too slow and tedious for programmers to work with. Instead, they began using English-like abbreviations to represent elementary operations. These abbreviations form the basis of assembly languages. Translator programs called assemblers convert assembly-language code to machine language code quickly. Although assembly-language code is clearer to humans, it’s incomprehensible to computers until translated to machine language code.

High-Level Languages, Compilers and Interpreters

To speed the programming process even further, high-level languages were developed in which single statements could be written to accomplish substantial tasks. High-level languages, such as Visual Basic, C#, C++, C, Objective-C and Java, allow you to write instructions that look almost like everyday English and contain commonly used mathematical expressions. Translator programs calledcompilers convert high-level language code into machine language code.

The process of compiling a large high-level language program into machine language can take a considerable amount of computer time. Interpreter programs were developed to execute high-level language programs directly (without the need for compilation), although more slowly than compiled programs.

1.6. OBJECT TECHNOLOGY

Visual Basic is an object-oriented programming language. In this section we’ll introduce the basics of object technology.

Building software quickly, correctly and economically remains an elusive goal at a time when demands for new and more powerful software are soaring. Objects, or more precisely the classes objects come from, are essentially reusable software components. There are date objects, time objects, audio objects, video objects, automobile objects, people objects, etc. Almost any noun can be reasonably represented as a software object in terms of attributes (such as name, color and size) and behaviors (such as calculating, moving and communicating). Software developers have discovered that using a modular, object-oriented design and implementation approach can make software-development groups much more productive than was possible with earlier techniques—object-oriented programs are often easier to understand, correct and modify.

The Automobile as an Object

Let’s begin with a simple analogy. Suppose you want to drive a car and make it go faster by pressing its accelerator pedal. What must happen before you can do this? Well, before you can drive a car, someone has to design it. A car typically begins as engineering drawings, similar to the blueprints that describe the design of a house. These drawings include the design for an accelerator pedal. The pedalhides from the driver the complex mechanisms that actually make the car go faster, just as the brake pedal hides the mechanisms that slow the car, and the steering wheel hides the mechanisms that turn the car. This enables people with little or no knowledge of how engines, braking and steering mechanisms work to drive a car easily.

Before you can drive a car, it must be built from the engineering drawings that describe it. A completed car has an actual accelerator pedal to make the car go faster, but even that’s not enough—the car won’t accelerate on its own (we hope), so the driver must press the pedal to accelerate the car.

Methods and Classes

Let’s use our car example to introduce some key object-oriented programming concepts. Performing a task in a program requires a method. The method houses the program statements that actually perform the task. It hides these statements from its user, just as a car’s accelerator pedal hides from the driver the mechanisms of making the car go faster. In object-oriented programming languages, we create a program unit called a class to house the set of methods that perform the class’s tasks. For example, a class that represents a bank account might contain one method to deposit money to an account, another to withdraw money from an account and a third to inquire what the account’s current balance is. A class that represents a car might contain methods for accelerating, breaking and turning. A class is similar in concept to a car’s engineering drawings, which house the design of an accelerator pedal, steering wheel, and so on.

Making Objects from Classes

Just as someone has to build a car from its engineering drawings before you can actually drive a car, you must build an object from a class before a program can perform the tasks that the class’s methods define. The process of doing this is called instantiation. An object is then referred to as an instance of its class.

Reuse

Just as a car’s engineering drawings can be reused many times to build many cars, you can reuse a class many times to build many objects. Reuse of existing classes when building new classes and programs saves time and effort. Reuse also helps you build more reliable and effective systems, because existing classes and components often have gone through extensive testing (to locate problems),debugging (to correct those problems) and performance tuning. Just as the notion of interchangeable parts was crucial to the Industrial Revolution, reusable classes are crucial to the software revolution that’s been spurred by object technology.

Image Software Engineering Observation 1.1

Use a building-block approach to creating your programs. Avoid reinventing the wheel—use existing pieces wherever possible. This software reuse is a key benefit of object-oriented programming.

Messages and Method Calls

When you drive a car, pressing its gas pedal sends a message to the car to perform a task—that is, to go faster. Similarly, you send messages to an object. Each message is implemented as a method call that tells a method of the object to perform its task. For example, a program might call a particular bank-account object’s deposit method to increase the account’s balance.

Attributes and Instance Variables

A car, besides having capabilities to accomplish tasks, also has attributes, such as its color, its number of doors, the amount of gas in its tank, its current speed and its record of total miles driven (i.e., its odometer reading). Like its capabilities, the car’s attributes are represented as part of its design in its engineering diagrams (which, for example, include an odometer and a fuel gauge). As you drive an actual car, these attributes are carried along with the car. Every car maintains its own attributes. For example, each car knows how much gas is in its own gas tank, but not how much is in the tanks of othercars.

An object, similarly, has attributes that it carries along as it’s used in a program. These attributes are specified as part of the object’s class. For example, a bank-account object has a balance attribute that represents the amount of money in the account. Each bank-account object knows the balance in the account it represents, but not the balances of the other accounts in the bank. Attributes are specified by the class’s instance variables.

Encapsulation

Classes encapsulate (i.e., wrap) attributes and methods into objects—an object’s attributes and operations are intimately related. Objects may communicate with one another, but they’re normally not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves. This information hiding, as we’ll see, is crucial to good software engineering.

Inheritance

A new class of objects can be created quickly and conveniently by inheritance—the new class absorbs the characteristics of an existing class, possibly customizing them and adding unique characteristics of its own. In our car analogy, an object of class “convertible” certainly is an object of the more generalclass “automobile,” but more specifically, the roof can be raised or lowered.

Object-Oriented Analysis and Design (OOAD)

Soon you’ll be writing programs in Visual Basic. Perhaps, like many programmers, you’ll simply turn on your computer and start typing. This approach may work for small programs (like the ones we present in the early chapters of this book), but what if you were asked to create a software system to control thousands of automated teller machines for a major bank? Or suppose you were asked to work on a team of thousands of software developers building the next U.S. air traffic control system? For projects so large and complex, you should not simply sit down and start writing programs.

To create the best solutions, you should follow a detailed analysis process for determining your project’s requirements (i.e., defining what the system is supposed to do) and developing a designthat satisfies them (i.e., deciding how the system should do it). Ideally, you’d go through this process and carefully review the design (and have your design reviewed by other software professionals) before writing any code. If this process involves analyzing and designing your system from an object-oriented point of view, it’s called an object-oriented analysis and design (OOAD) process. Languages like Visual Basic are object oriented. Programming in such a language, called object-oriented programming (OOP), allows you to implement an object-oriented design as a working system.

The UML (Unified Modeling Language)

Although many different OOAD processes exist, a single graphical language for communicating the results of any OOAD process has come into wide use. This language, known as the Unified Modeling Language (UML), is now the most widely used graphical scheme for modeling object-oriented systems. We present our first simple UML diagrams in Chapters 4 and 5, then use them in our deeper treatment of object-oriented programming. In our optional ATM Software Engineering Case Study in Chapters 30–31 we present a subset of the UML’s features as we guide you through a simple object-oriented design experience.

1.7. INTERNET AND WORLD WIDE WEB

In the late 1960s, ARPA—the Advanced Research Projects Agency of the United States Department of Defense—rolled out plans to network the main computer systems of approximately a dozen ARPA-funded universities and research institutions. The computers were to be connected with communications lines operating at a then-stunning 56 Kbps (1 Kbps is equal to 1,024 bits per second), at a time when most people (of the few who even had networking access) were connecting over telephone lines to computers at a rate of 110 bits per second. Academic research was about to take a giant leap forward. ARPA proceeded to implement what quickly became known as the ARPAnet, the precursor of today’s Internet.

Things worked out differently from the original plan. Although the ARPAnet enabled researchers to network their computers, its main benefit proved to be the capability for quick and easy communication via what came to be known as electronic mail (e-mail). This is true even on today’s Internet, with e-mail, instant messaging, file transfer and social media such as Facebook and Twitter, enabling billions of people worldwide to communicate quickly and easily.

The protocol (set of rules) for communicating over the ARPAnet became known as the Transmission Control Protocol (TCP). TCP ensured that messages, consisting of sequentially numbered pieces called packets, were properly routed from sender to receiver, arrived intact and were assembled in the correct order.

Order now and get 10% discount on all orders above $50 now!!The professional are ready and willing handle your assignment.

ORDER NOW »»