Chapter 1: Introduction to Visual Basic .NET:
Background and Perspective
Visual Basic .NET Programming:
From Problem Analysis to Program Design
Visual Basic .NET Programming: From Problem Analysis to Program Design 2
Objectives
• Learn basic computer terminology and component architecture
• Explore the history of programming languages
• Recognize the similarities between programming languages and spoken languages
• Solve problems and develop algorithms
Visual Basic .NET Programming: From Problem Analysis to Program Design 3
Objectives (continued)
• Identify basic object-oriented programming concepts
• Examine the benefits of the object-oriented approach
Visual Basic .NET Programming: From Problem Analysis to Program Design 4
Understanding Basic Computer Terminology And Component
Architecture
• Understand basic computer terms
• Fundamentals of how computer works
• Computer requires:
• Hardware
• Software
Visual Basic .NET Programming: From Problem Analysis to Program Design 5
Understanding Basic Computer Terminology And Component
Architecture (continued)• Hardware
– Physical components of computer
• Architecture
– Arrangement of hardware components within computer
Visual Basic .NET Programming: From Problem Analysis to Program Design 6
Visual Basic .NET Programming: From Problem Analysis to Program Design 7
Understanding Basic Computer Terminology And Component
Architecture (continued)• Primary computer components:
– Input/output devices
– Memory
• Read-only memory (ROM)
• Random access memory (RAM)
Visual Basic .NET Programming: From Problem Analysis to Program Design 8
Understanding Basic Computer Terminology And Component
Architecture (continued)
• Primary computer components (continued):
– Central processing unit
• Registers
• Arithmetic logic unit (ALU)
• Control unit
• Software
– Computer programs that are executed by hardware
Visual Basic .NET Programming: From Problem Analysis to Program Design 9
Exploring the History of Programming Languages
• Modern programming languages
– Very powerful
– Enable you to develop sophisticated applications with relative ease
– Bear little resemblance to early counterparts
• HOWEVER, principal underpinnings remain unchanged
Visual Basic .NET Programming: From Problem Analysis to Program Design 10
Machine Language
• Earliest programming languages• Consist of only 0’s and 1’s• Bit
– Binary digit of either 0 or 1– At machine level, computers only truly understand
bits
• Bit patterns– Used to represent other pieces of information
• Example: characters
Visual Basic .NET Programming: From Problem Analysis to Program Design 11
Machine Language (continued)
• Memory location
– Can be represented as binary number using combination of bits
Visual Basic .NET Programming: From Problem Analysis to Program Design 12
Visual Basic .NET Programming: From Problem Analysis to Program Design 13
Assembly Language
• Provides one-to-one correspondence between each machine language instruction and a mnemonic
• Mnemonic
– Word or character string that represents an instruction
• Requires writing set of single-step instructions
• Easier for people to read and write
Visual Basic .NET Programming: From Problem Analysis to Program Design 14
Assembly Language (continued)
• Sample instructions:
– CLR Clear the accumulator
– ADD A Add the contents of memory location A to the accumulator
– SUB G Subtract the contents of memory location G from the accumulator
– STO E Store the contents of the accumulator in memory location E
Visual Basic .NET Programming: From Problem Analysis to Program Design 15
Assembly Language (continued)
• Assembler
– Translates mnemonics and memory location names into underlying machine code
• Program written for one computer architecture
– Usually will not run on different computer architecture
– Drawback of assembly language
Visual Basic .NET Programming: From Problem Analysis to Program Design 16
High-level Languages
• Evolved due to needs for:
– Portability
– More expressive languages
• Easier to read, write, and maintain
• Less efficient in terms of:
– CPU time
– Memory
Visual Basic .NET Programming: From Problem Analysis to Program Design 17
High-level Languages (continued)
• Compiler
– Translate program to machine code
• Linker
– Combines object code with other programs in class libraries
• Loader
– Loads object code into memory
– Executes program
Visual Basic .NET Programming: From Problem Analysis to Program Design 18
High-level Languages (continued)
• Source code
– Program written by programmer
• Class library
– Collection of object files
– Support features and functions of a high-level language
Visual Basic .NET Programming: From Problem Analysis to Program Design 19
Visual Basic .NET Programming: From Problem Analysis to Program Design 20
Learning a Programming Language
• Understand basic vocabulary• Keywords
– Words built into language– Also called reserved words
• Statements– Consist of:
• Keywords
• Identifiers
• Symbols
Visual Basic .NET Programming: From Problem Analysis to Program Design 21
Learning a Programming Language (continued)
• Procedures
– One or more related statements
– Work together to perform specific task
• Modules
– Self-sufficient group of related procedures
– Can combine with other modules to create applications
Visual Basic .NET Programming: From Problem Analysis to Program Design 22
Learning a Programming Language (continued)
• Syntax
– Rules of language
– Includes:
• Spelling
• Punctuation
• Grammar
– Each programming language has own unique syntax and structure
Visual Basic .NET Programming: From Problem Analysis to Program Design 23
Learning a Programming Language (continued)
• Syntax error
– Mistake in program
• Violates language rules
– Compiler checks for syntax errors
Visual Basic .NET Programming: From Problem Analysis to Program Design 24
Learning a Programming Language
• Logic error
– Mistake in program
• Executes and produces incorrect result
– Also known as bugs
– Not checked by compiler
Visual Basic .NET Programming: From Problem Analysis to Program Design 25
Solving Problems and Developing Algorithms
• Computer programming is problem solving
• Problems solved by programs
– Require inputs
– Produce outputs
• Algorithm
– Sequence of steps used to transform input(s) into desired output(s)
Visual Basic .NET Programming: From Problem Analysis to Program Design 26
Visual Basic .NET Programming: From Problem Analysis to Program Design 27
Solving Problems and Developing Algorithms
(continued)
• Critical that programmers embrace problem-solving approach
• Before writing code, programmer must:
– Understand problem at hand
– Properly identify inputs and outputs
– Develop transformation algorithm
Visual Basic .NET Programming: From Problem Analysis to Program Design 28
Example 1-1: Creating a GPA Algorithm
Set TotalPoints,TotalHours, and GPA equal to 0
For each course
Get Grade and CreditHours
Add CreditHours to TotalHours
If Grade is an ‘A’, multiply CreditHours by 4 and add result to TotalPoints
If Grade is a ‘B’, multiply CreditHours by 3 and add result to TotalPoints
Visual Basic .NET Programming: From Problem Analysis to Program Design 29
Example 1-1: Creating a GPA Algorithm (continued)
If Grade is a ‘C’, multiply CreditHours by 2 and add result to TotalPoints
If Grade is a ‘D’, multiply CreditHours by 1 and add result to TotalPoints
When no more courses
If TotalHours is not 0, calculate GPA = TotalPoints/TotalHours
Visual Basic .NET Programming: From Problem Analysis to Program Design 30
Solving Problems and Developing Algorithms
(continued)
• Desk-checking:
– Draw columns by hand that correspond to items in algorithm
– Create set of test data
– Step through algorithm
– Record changing values for each item
Visual Basic .NET Programming: From Problem Analysis to Program Design 31
Example 1-2: Desk-Checking the Algorithm
Visual Basic .NET Programming: From Problem Analysis to Program Design 32
Example 1-2: Desk-Checking the Algorithm (continued)
Visual Basic .NET Programming: From Problem Analysis to Program Design 33
Identifying Basic Object-oriented Programming
Concepts
• Procedural programming
– Defining set of steps to transform inputs into outputs
– Translating steps into code
• Object-oriented programming
– Defining collection of objects that work together to solve problem
Visual Basic .NET Programming: From Problem Analysis to Program Design 34
Identifying Basic Object-oriented Programming
Concepts (continued)
• Object-oriented programming languages:– Becoming more popular
– Examples:• Java
• VB .NET
• Object – Thing that has characteristics and behaviors
Visual Basic .NET Programming: From Problem Analysis to Program Design 35
Identifying Basic Object-oriented Programming
Concepts (continued)
• Attributes
– Characteristics of an object
• Methods
– Behaviors of an object
• Problem domain objects
– Objects specific to problem being solved
Visual Basic .NET Programming: From Problem Analysis to Program Design 36
Visual Basic .NET Programming: From Problem Analysis to Program Design 37
Identifying Basic Object-oriented Programming
Concepts (continued)
• Message
– Asks object to invoke one of its methods
• Encapsulation
– Attributes and methods of object are packaged into single unit
– Do not need to know internal structure of object to send messages to it
Visual Basic .NET Programming: From Problem Analysis to Program Design 38
Identifying Basic Object-oriented Programming
Concepts (continued)
• Class
– Defines what all objects of group have in common
• Instance
– Specific member of group
– Example:
• Cheeseburger is an instance of food class
Visual Basic .NET Programming: From Problem Analysis to Program Design 39
Identifying Basic Object-oriented Programming
Concepts (continued)
• Inheritance
– Class of objects takes on characteristics of another class
• Extends them as necessary
– Subclasses
– Superclass
Visual Basic .NET Programming: From Problem Analysis to Program Design 40
Visual Basic .NET Programming: From Problem Analysis to Program Design 41
Identifying Basic Object-oriented Programming
Concepts (continued)
• Polymorphism
– Different objects can respond in own way to same message
– Related to inheritance of methods
Visual Basic .NET Programming: From Problem Analysis to Program Design 42
Examining the Benefits of the Object-oriented Approach
• Advantages:
– Naturalness
– Reusability
• OO approach still requires algorithm design:
– To define methods of object
Visual Basic .NET Programming: From Problem Analysis to Program Design 43
Summary
• Computer consists of:
– Hardware
– Software
• Programming languages:
– Machine language
– Assembly language
– High-level languages
Visual Basic .NET Programming: From Problem Analysis to Program Design 44
Summary (continued)
• Writing a program:
– Understand problem
– Develop algorithm
– Desk-check
– Write code
• Object-oriented programming
– Defines a collection of objects that work together to solve a problem