41
Introducing Computer Introducing Computer Science & Algorithms Science & Algorithms

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

Embed Size (px)

Citation preview

Page 1: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

Introducing Computer Introducing Computer Science & AlgorithmsScience & Algorithms

Page 2: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 3: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 4: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

Computer use is PervasiveComputer use is PervasiveBanking Air TrafficSpace TravelCommerceMedicinePublic SafetyEducation

Page 5: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 6: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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!

Page 7: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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?

Page 8: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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?

Page 9: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

Developing an AlgorithmDeveloping an Algorithm

PROBLEM

INPUT PROCESSES OUTPUT

MODULE MODULE MODULE MODULE MODULE MODULE

4. Develop a HIPO chart

Page 10: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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?

Page 11: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 12: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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.)

Page 13: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 14: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 15: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 16: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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.

Page 17: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 18: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 19: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 20: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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.)

Page 21: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Data can only be accessed through that package

“Information Hiding”

Page 22: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 23: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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.

Page 24: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 25: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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)

Page 26: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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?

Page 27: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 28: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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?

Page 29: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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!

Page 30: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 31: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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!

Page 32: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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?

Page 33: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 34: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 35: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 36: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 37: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 38: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

Procedural CommentsProcedural CommentsIdentify purpose, arguments &

return values for proceduresCan be used in:

◦Event Procedures◦Sub-Procedures◦Function Procedures

Page 39: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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

Page 40: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

Questions?Questions?

Page 41: Introducing Computer Science & Algorithms. Goals By the end of this lecture you should … … understand Computer Science as the study of algorithms … understand

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)