Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … …...

Preview:

Citation preview

Introducing Computer Introducing Computer Science & AlgorithmsScience & Algorithms

GoalsGoalsBy the end of this lecture you

should …… understand Computer Science

as the study of algorithms… understand the difference

between procedural-type languages and object-oriented languages

… understand the program development cycle

Types of ComputersTypes of Computers

Personal Computer - a computer operated by one person at a time. AKA “Client” computers.

Server – a computer whose resources and processors are shared by multiple users

VB.Net concerns itself mainly with programming for the client computer

Computer use is PervasiveComputer use is PervasiveBanking Air TrafficSpace TravelCommerceMedicinePublic SafetyEducation

Computer ComponentsComputer ComponentsHardware

◦ Physical components of a computer◦ Examples: Mouse, keyboard, RAM, hard drives,

processor, monitorSoftware

◦ Instructions that get the computer to do something◦ Operating Systems & Applications◦ Examples: Windows 2000, Microsoft Excel,

WordPerfect, Netscape, Internet Explorer

What is Computer What is Computer Science?Science?

NOT about coding or hardware or software!

Computer Science is about PROBLEM SOLVING

Computer Science is about DEVELOPING ALGORITHMS to solve complex problems

Computers are merely tools for solving problems!

AlgorithmsAlgorithms

Well-developed, organized approaches to solving complex problems

Test of a good algorithm:◦Does the algorithm solve the stated

problem?◦Is the algorithm well-defined?◦Does the algorithm produce an output?◦Does the algorithm end in a reasonable

length of time?

Developing an AlgorithmDeveloping an Algorithm1. Identify the Inputs

◦ What data do I need?◦ How will I get the data?◦ In what format will the data be?

2. Identify the Processes:◦ How can I manipulate data to produce

meaningful results?

3. Identify Outputs:◦ What outputs do I need to return to the user?◦ What format should the outputs take?

Developing an AlgorithmDeveloping an Algorithm

PROBLEM

INPUT PROCESSES OUTPUT

MODULE MODULE MODULE MODULE MODULE MODULE

4. Develop a HIPO chart

Developing an AlgorithmDeveloping an Algorithm

5. Identify relevant modules◦ How can I break larger problems

into smaller, more manageable pieces?

◦ What inputs do the modules need?◦ What processes need to happen in

the modules?◦ What outputs are produced by the

modules?

ProgramsProgramsSets of instructions that get the

computer to do somethingInstructions are translated,

eventually, to machine language using an interpreter or a compiler

Programs may be a few lines or millions of lines of code

Programming TasksProgramming TasksAll computer programs are written so

they can take data, manipulate and then produce a result.

This process uses three distinct tasks:◦ INPUT – getting data from an external source (the

user, a database, a file, etc.)◦ PROCESSING – actual manipulation of the data◦ OUTPUT – reporting the results of data

manipulation back (using the monitor, writing information to a database, etc.)

Relationships in Relationships in ProgrammingProgrammingProgrammer – The person who

solves a problem by providing a solution through writing instructions (the program) for the computer. (AKA – The developer)

User – Any person who uses a program written by a programmer

Categories of LanguagesCategories of LanguagesMachine Language

◦ Binary digits (bits – 1s and 0s) which are translated to electrical impulses that get the computer to do something

◦ “Native” language of computersAssembly Languages

◦ Group of basic commands which are more like English

◦ Tied to specific processors◦ Still need to be translated to machine language

Categories of LanguagesCategories of LanguagesHigh Level Languages

◦In terms of syntax, very close to human language (mostly English)

◦Lower error rate than writing machine language or assembly language programs

◦Need to be translated to machine language before execution Compilers Interpreters

More on High-Level More on High-Level LanguagesLanguagesOperations common to all HL

languages:◦Sequential Operations – Operations in

which lines of code execute in order, one right after another

◦Conditional Operations – Operations in which execution depends on the outcome of a previous condition (usually evaluated to be TRUE or FALSE)

◦Looping Operations – Operations designed to repeat until a given condition is satisfied.

More on High-Level More on High-Level LanguagesLanguagesProcedural Languages

◦Early high level languages◦Focus on structures◦Examples include QuickBasic, Fortran,

Pascal, Visual Basic (early versions)Object-Oriented languages (OOP)

◦More recent development◦Focus on data, not structures

(Primacy of Data)◦Examples include Java, C#, C++,

Visual Basic.Net

Object Oriented Object Oriented ProgrammingProgrammingObject – Unique programming

entity that has methods, has attributes and can react to events.

Method – Things which an object can do; the “verbs” of objects. In code, usually can be identified by an “action” word -- Hide, Show

Object Oriented Object Oriented ProgrammingProgrammingAttribute – Things which describe

an object; the “adjectives” of objects. In code, usually can be identified by a “descriptive” word – Enabled, BackColor

Events – Forces external to an object to which that object can react. In code, usually attached to an event procedure

Object Oriented Object Oriented ProgrammingProgrammingClass – Provides a way to create

new objects based on a “meta-definition” of an object (Example: The automobile class)

Constructors – Special methods used to create new instances of a class (Example: A Honda Civic is an instance of the automobile class.)

OOP - EncapsulationOOP - EncapsulationIncorporation into a class of data & operations in one package

Data can only be accessed through that package

“Information Hiding”

OOP - InheritanceOOP - InheritanceAllows programmers to create

new classes based on an existing class

Methods and attributes from the parent class are inherited by the newly-created class

New methods and attributes can be created in the new class, but don’t affect the parent class’s definition

OOP - PolymorphismOOP - PolymorphismCreating methods which describe the way to do some general function (Example: The “drive” method in the automobile class)

Polymorphic methods can adapt to specific types of objects.

The Programming The Programming Development CycleDevelopment Cycle

Done after identifying inputs, processing & outputs

Steps1. Analyze the problem2. Plan a solution to the problem

(algorithm)3. Design the user interface

The VB.NET Programming The VB.NET Programming Development CycleDevelopment Cycle

Steps (continued)4. Code the solution5. Test and debug the solution6. Complete program documentation7. Begin to plan for next release

(start Cycle again)

1. Analyze the Problem1. Analyze the ProblemQuestions to ask:

◦Who is my intended audience?◦What SPECIFIC outcomes does my

audience expect?◦What business rules is my audience

expecting to have incorporated into the solution?

◦What is the SCOPE of the problem?

2. Plan a Solution 2. Plan a Solution (Algorithm)(Algorithm)What types of programming structures

are needed?◦ Sequential structures◦ Conditional structures◦ Looping structures

What data structures are needed?◦ Variables◦ Lists◦ Arrays

3. Design the User 3. Design the User InterfaceInterfaceAKA – The “UI”Is the UI “learnable”?Is it simple? (Limit user choices)Does the UI promote error-proof

use?Is the layout of the UI arranged in

a fashion conducive to the user’s culture and expectations?

4. Code the Solution4. Code the SolutionDevelop an actual program from

an algorithmShould be the “easiest” part of

the process – all the work should already be done!

5. Test & Debug the 5. Test & Debug the SolutionSolutionAlpha Testing – Internal testing done

with expected client data (NOT LIVE DATA)

Beta Testing – Testing done at the client site with their data (USUALLY LIVE DATA)

Try to predict common user errorsTest subjects should be Power Users,

Normal Users and Neophytes

6. Complete 6. Complete DocumentationDocumentationUser Documentation:

◦ User Manual◦ Technical Documentation (for System

Administrators)

Internal Documentation:◦ Documentation comments◦ Code comments◦ Procedural comments◦ Should be done while coding!

7. Plan Next Release7. Plan Next ReleaseWhat bugs need to be fixed?

◦Are bugs “critical”? (Need to be fixed in a minor release)

◦If bugs are not critical, they can be fixed in next major release

What product enhancements do the users want for the next release?

Internal CommentingInternal CommentingComments are non-executable lines (the

computer ignores them) which are used to communicate valuable information about code to others

Types of Internal Commenting:◦ Documentation Comments◦ Code Comments◦ Procedural Comments

Comment Syntax:◦ C-like Syntax (C, C++, Java, JavaScript):

/* This is a comment */ ◦ Visual Basic Syntax:

‘This is a comment

Documentation Documentation CommentsCommentsUsed to given specific

information about a programUsually found at the beginning of

a code windowInclude information about the

author, creation date, purpose, modification date & modification history

Documentation CommentDocumentation Comment'TITLE: Hello World, v2.0'AUTHOR: Bob Molnar'PURPOSE: To demonstrate changing of textbox 'properties using event procedures.'CREATED ON: 09.10.2002'LAST MODIFIED ON: 09.18.2002'LAST MODIFIED BY: RSM'MODIFICATION HISTORY:' 09.12.2002 - Renamed form to frmMain to' conform with accepted naming standards (MJK) ' 09.18.2002 - Created a Clear Button enabling' users to clear output (RSM)

NOTE: Example uses Visual Basic SyntaxNOTE: Example uses Visual Basic Syntax

Code CommentsCode Comments“Tell the story” of the code, in

EnglishFor this class, you should use

code comments to indicate what lines of code do

Code CommentsCode Comments

/* Initialize loop counter to 1 */counter = 1;/* Set loop to repeat 10 times */while(counter <= 10){ /* Prompt for input */ printf("Enter grade: "); /* Get user's input, store in the variable grade */ scanf("%d", &grade);} /* end while */

NOTE: Example uses C SyntaxNOTE: Example uses C Syntax

Procedural CommentsProcedural CommentsIdentify purpose, arguments &

return values for proceduresCan be used in:

◦Event Procedures◦Sub-Procedures◦Function Procedures

Procedural CommentsProcedural Comments' PROCEDURE: btnClear_Click' TYPE: Event Procedure' ARGUMENTS: VB-Generated' PROCEDURE: btnClear_Click' RETURNS: Nothing' PURPOSE: Re-sets the value of the textbox ' txtDspMsg to null when the button btnClear ' clickedPrivate Sub btnClear_Click(...) Handles _ btnClear.Click txtDspMsg.Text = ""End Sub

NOTE: Example uses Visual Basic SyntaxNOTE: Example uses Visual Basic Syntax

Questions?Questions?

ResourcesResourcesBob Molnar, N201 Lecture NotesVisual Basic.NET Primer Plus by

Jack Purdum (Sams Publishing, 2003)

An Introduction to Programming Using Visual Basic.NET Fifth Edition by David I. Schneider (Prentice Hall, 2003)

C: How to Program by Deitel & Deitel (Prentice Hall, 2004)

Recommended