47
CSCI N201: CSCI N201: Programming Concepts Programming Concepts Copyright Copyright ©2005 ©2005 Department of Computer & Information Science Department of Computer & Information Science Introducing Introducing Programming Programming

CSCI N201: Programming Concepts Copyright ©2005 Department of Computer & Information Science Introducing Programming

Embed Size (px)

Citation preview

Page 1: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201:CSCI N201: Programming ConceptsProgramming Concepts

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Introducing ProgrammingIntroducing Programming

Page 2: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

GoalsGoals

By the end of this lecture, you should …By the end of this lecture, you should …• Understand the different types of Understand the different types of

programming languages.programming languages.• Understand the basic procedures in a Understand the basic procedures in a

program as input, processing and output.program as input, processing and output.• Understand the importance of variables.Understand the importance of variables.• Understand a basic map of the program Understand a basic map of the program

development cycle.development cycle.

Page 3: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Computer ComponentsComputer Components

• CPU Central Processing UnitCPU Central Processing Unit• RAM (Random Access Memory)RAM (Random Access Memory)• Mass storage devicesMass storage devices• Input devicesInput devices• Output DevicesOutput Devices

Page 4: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Storage CapacitiesStorage Capacities

• bit – smallest capacitybit – smallest capacity• nibble = 4 bitsnibble = 4 bits• byte = 2 nibbles = 8 bitsbyte = 2 nibbles = 8 bits

– storage for one characterstorage for one character

• 1 kilobyte (KB) = 1024 bytes1 kilobyte (KB) = 1024 bytes• 1 megabyte (MB) = 1024 KB1 megabyte (MB) = 1024 KB• 1 gigabyte (GB) = 1024 MB1 gigabyte (GB) = 1024 MB

Page 5: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

SoftwareSoftware

• Application Application Software Software – Word ProcessorsWord Processors– Database s/wDatabase s/w– SpreadsheetsSpreadsheets– Painting programsPainting programs– Web browsers, email Web browsers, email

programsprograms

• System SoftwareSystem Software– Operating SystemsOperating Systems

• WindowsWindows• Macintosh OSMacintosh OS• UnixUnix• LinuxLinux

– DriversDrivers

Software is comprised of instructions that get a computer to perform a task.

Page 6: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Programming LanguagesProgramming Languages

• Programming languages allow Programming languages allow programmers to code software.programmers to code software.

• The three major families of The three major families of languages are:languages are:– Machine languagesMachine languages– Assembly languagesAssembly languages– High-Level languagesHigh-Level languages

Page 7: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Machine LanguagesMachine Languages

• Comprised of 1s and 0sComprised of 1s and 0s• The “native” language of a computerThe “native” language of a computer• Difficult to program – one misplaced Difficult to program – one misplaced

1 or 0 will cause the program to fail.1 or 0 will cause the program to fail.• Example of code:Example of code:1110100010101 111010101110 1110100010101 111010101110 10111010110100 1010001111011110111010110100 10100011110111

Page 8: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Assembly LanguagesAssembly Languages

• Assembly languages are a step towards Assembly languages are a step towards easier programming. easier programming.

• Assembly languages are comprised of a Assembly languages are comprised of a set of elemental commands which are tied set of elemental commands which are tied to a specific processor.to a specific processor.

• Assembly language code needs to be Assembly language code needs to be translated to machine language before the translated to machine language before the computer processes it.computer processes it.

• Example:Example:ADD 1001010, 1011010ADD 1001010, 1011010

Page 9: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

High-Level LanguagesHigh-Level Languages

• High-level languages represent a giant High-level languages represent a giant leap towards easier programming.leap towards easier programming.

• The syntax of HL languages is similar The syntax of HL languages is similar to English. to English.

• Historically, we divide HL languages Historically, we divide HL languages into two groups:into two groups:– Procedural languagesProcedural languages– Object-Oriented languages (OOP)Object-Oriented languages (OOP)

Page 10: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Procedural LanguagesProcedural Languages

• Early high-level languages are Early high-level languages are typically called procedural languages.typically called procedural languages.

• Procedural languages are Procedural languages are characterized by sequential sets of characterized by sequential sets of linear commands. The focus of such linear commands. The focus of such languages is on languages is on structurestructure..

• Examples include C, COBOL, Fortran, Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScriptLISP, Perl, HTML, VBScript

Page 11: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Object-Oriented LanguagesObject-Oriented Languages

• Most object-oriented languages are Most object-oriented languages are high-level languages.high-level languages.

• The focus of OOP languages is not on The focus of OOP languages is not on structure, but on structure, but on modeling datamodeling data..

• Programmers code using “blueprints” Programmers code using “blueprints” of data models called of data models called classesclasses..

• Examples of OOP languages include Examples of OOP languages include C++, Visual Basic.NET and Java.C++, Visual Basic.NET and Java.

Page 12: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

CompilingCompiling

• Regardless of the HL Language, all HL Regardless of the HL Language, all HL programs need to be translated to machine programs need to be translated to machine code so that a computer can process the code so that a computer can process the program.program.

• Some programs are translated using a Some programs are translated using a compilercompiler. When programs are compiled, . When programs are compiled, they are translated all at once. Compiled they are translated all at once. Compiled programs typically execute more quickly programs typically execute more quickly than interpreted programs, but have a than interpreted programs, but have a slower translation speed.slower translation speed.

Page 13: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

InterpretingInterpreting

• Some programs are translated using Some programs are translated using an an interpreterinterpreter. Such programs are . Such programs are translated line-by-line instead of all translated line-by-line instead of all at once (like compiled programs). at once (like compiled programs). Interpreted programs generally Interpreted programs generally translate quicker than compiled translate quicker than compiled programs, but have a slower programs, but have a slower execution speed.execution speed.

Page 14: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Programming ExampleProgramming Example

• Simple programming problem: Simple programming problem: Convert a Convert a price from British pounds into Dollars.price from British pounds into Dollars.

• PseudocodePseudocodeInput the price of the item, PoundPrice, in poundsInput the price of the item, PoundPrice, in pounds

Compute the price of the item in dollars:Compute the price of the item in dollars:

Set DollarPrice = 1.62 * PoundPriceSet DollarPrice = 1.62 * PoundPrice

Write DollarPriceWrite DollarPrice

Page 15: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Programming ExampleProgramming Example

• Translating to Basic:Translating to Basic:INPUT PoundPriceINPUT PoundPrice

LET DollarPrice = 1.62 * PoundPriceLET DollarPrice = 1.62 * PoundPrice

PRINT DollarPricePRINT DollarPrice

ENDEND

Page 16: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Input & VariablesInput & Variables

• Input operations get data into the programsInput operations get data into the programs• A user is A user is prompted prompted to enter data:to enter data:

Write “Enter the price in pounds”Write “Enter the price in pounds”

Input PoundPriceInput PoundPrice

• Computer programs store data in named Computer programs store data in named sections of memory called sections of memory called variablesvariables. In the . In the example above, the variable is named example above, the variable is named PoundPricePoundPrice. The value of a variable can, and . The value of a variable can, and often does, change throughout a program.often does, change throughout a program.

Page 17: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Types of DataTypes of Data

• Numeric DataNumeric Data– Integer data, I.e., whole numbers, 10 25 -45 0Integer data, I.e., whole numbers, 10 25 -45 0– Floating point data – have a decimal point 23.0, -Floating point data – have a decimal point 23.0, -

5.05.0

• Character data (alphanumeric)Character data (alphanumeric)– All the characters you can type at the keyboardAll the characters you can type at the keyboard– Letters & numbers not used in calculationsLetters & numbers not used in calculations

• Boolean data Boolean data – TRUE/FALSETRUE/FALSE

Page 18: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Data Processing and OutputData Processing and Output

Set DollarPrice = 1.62 * PoundPriceSet DollarPrice = 1.62 * PoundPrice• The above statement is a processing The above statement is a processing

statement. Take the value in the variable statement. Take the value in the variable PoundPricePoundPrice, multiply by 1.62, and set the , multiply by 1.62, and set the variable variable DollarPriceDollarPrice to the result of the to the result of the multiplication.multiplication.

Write DollarPriceWrite DollarPrice• Output the value in Output the value in DollarPriceDollarPrice to the to the

monitor.monitor.

Page 19: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Assignment OperationsAssignment Operations

Set counter = counter + 1Set counter = counter + 1• Assignment statements change the value Assignment statements change the value

in a variable Take the value of in a variable Take the value of countercounter, , add 1, and store the result back in the add 1, and store the result back in the same variable.same variable.

Page 20: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Arithmetic OperationsArithmetic Operations

NameName SymbolSymbol ExampleExample ResultResult

ExponentiationExponentiation ^̂ 4^24^2 1616

MultiplicationMultiplication ** 16*216*2 3232

DivisionDivision // 16/216/2 88

AdditionAddition ++ 16+216+2 1818

SubtractionSubtraction -- 16-216-2 1414

Page 21: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Data HierarchyData Hierarchy

1.1. ParenthesisParenthesis

2.2. ExponentiationExponentiation

3.3. Multiplication/DivisionMultiplication/Division

4.4. Addition/SubtractionAddition/Subtraction

Page 22: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Hierarchy of Operations Hierarchy of Operations ExampleExample

3 * (6 + 2) / 12 – (7 – 5) ^ 2 * 3 ( ) first

= 3 * 8 / 12 – 2 ^ 2 * 3 ^ next

= 3 * 8 / 12 – 4 * 3 Mult/Div (L to R)

= 24 / 12 – 4 * 3 Mult/Div (L to R)

= 2 – 12 Add/Subtr

= -10

Page 23: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Data OutputData Output

• Send information from the program to the Send information from the program to the screen, or printer, or disk file.screen, or printer, or disk file.

Write DollarPriceWrite DollarPrice • The computer displays the value of the The computer displays the value of the

variable variable DollarPriceDollarPrice to the screen and the to the screen and the cursor goes to the next line.cursor goes to the next line.

Page 24: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Data OutputData Output

Write “The price in Dollars is”, Write “The price in Dollars is”, DollarPriceDollarPrice

• The output looks like this:The output looks like this:

The price in Dollars is 162The price in Dollars is 162

• The text inside the “ ” is output to the user The text inside the “ ” is output to the user “as is,” and it is the “as is,” and it is the valuevalue in the variable that in the variable that is output.is output.

Page 25: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

2.12.1The Program The Program Development CycleDevelopment Cycle

Page 26: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Programming as Problem Programming as Problem SolvingSolving

• Problem solving Problem solving principles:principles:

1.1. Completely understand Completely understand the problemthe problem

2.2. Devise a plan to solve Devise a plan to solve it it

3.3. Carry out the planCarry out the plan

4.4. Review the resultsReview the results

• Developing a Developing a Program:Program:

1.1. Analyze the problemAnalyze the problem

2.2. Design the programDesign the program

3.3. Code the programCode the program

4.4. Test the programTest the program

An example of programming as problem solving, Brewster’s Thousands follows …

Page 27: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

1) Analyze the Problem1) Analyze the Problem

• Brewster’s ThousandsBrewster’s Thousands– The problem: Brewster wants to invest money at The problem: Brewster wants to invest money at

a local bank. There are many options such as a local bank. There are many options such as interest rates, terms of deposit, compounding interest rates, terms of deposit, compounding frequencies. He needs a program to compute, frequencies. He needs a program to compute, for any given initial investment, the final for any given initial investment, the final maturity (value) of the deposit.maturity (value) of the deposit.• What are the inputs? (given data)What are the inputs? (given data)• What are the outputs? (required data)What are the outputs? (required data)• How will we calculate the required outputs from the How will we calculate the required outputs from the

given inputs?given inputs?

Page 28: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

2) Design the Program2) Design the Program

• Create an outline of the programCreate an outline of the program• An An algorithm – algorithm – a step by step a step by step

procedure that will provide the procedure that will provide the required results from the given required results from the given inputs.inputs.

• Algorithm Examples: Instructions on Algorithm Examples: Instructions on how to make a cake, use the bank’s how to make a cake, use the bank’s ATM, etc.ATM, etc.

Page 29: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

3) Code the Program3) Code the Program

• Once the design is completed, write Once the design is completed, write the program the program codecode. .

• Code is written in some programming Code is written in some programming language such as BASIC, Pascal, C++, language such as BASIC, Pascal, C++, Java, etc.Java, etc.In this course we write code in pseudo-In this course we write code in pseudo-code, developing the skills to be used code, developing the skills to be used when studying the specific languages.when studying the specific languages.

Page 30: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

4) Testing the program4) Testing the program

• Locate any errors (bugs)Locate any errors (bugs)• Testing is done throughout the development Testing is done throughout the development

cyclecycle• Desk-checkingDesk-checking, or code , or code walkthrough walkthrough is is

performed to locate errors in the code.performed to locate errors in the code.– Pretend you are the computer and execute your own code. Pretend you are the computer and execute your own code.

• Ultimate test is to run the program to see if Ultimate test is to run the program to see if the outputs are correct for the given inputs.the outputs are correct for the given inputs.

Page 31: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Modular ProgrammingModular Programming

• Determine the major tasks that the Determine the major tasks that the program must accomplish. Each of these program must accomplish. Each of these tasks will be a tasks will be a modulemodule..

• Some modules will be complex Some modules will be complex themselves, and they will be broken into themselves, and they will be broken into sub-modules, sub-modules, and those sub-modules may and those sub-modules may also be broken into even smaller modules.also be broken into even smaller modules.

• This is called This is called top-down designtop-down design

Page 32: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Mapping ModulesMapping Modules

InputsInputs ProcessesProcesses OutputsOutputs

Input Input Variables:Variables:PrincipalPrincipalPercentageRatePercentageRateTermTermFrequencyFrequency

Rate of Interest:Rate of Interest:Set Rate = Set Rate = PercentageRate/100PercentageRate/100

Display:Display:Write Write FinalValueFinalValue

Final Value:Final Value:Set FinalValue = Principal *Set FinalValue = Principal *(1 + Rate / Frequency) ^ (1 + Rate / Frequency) ^ (Frequency * Term)(Frequency * Term)

Page 33: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Code ModulesCode Modules

• A module is an independent, self-A module is an independent, self-contained section of code that contained section of code that performs a single task.performs a single task.

• The The main modulemain module is the module that is the module that drives the application. It “controls” drives the application. It “controls” all other modules. Typically, the main all other modules. Typically, the main module calls other modules in order module calls other modules in order to have them perform certain tasks.to have them perform certain tasks.

Page 34: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Program Control & ModulesProgram Control & Modules

• When the main module calls another When the main module calls another module, program control transfers to module, program control transfers to the called module. Program control the called module. Program control cedes back to the main module when cedes back to the main module when the called module finishes.the called module finishes.

Page 35: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Main moduleMain moduleDisplay program title and brief description of programDisplay program title and brief description of programCall Input Data ModuleCall Input Data ModuleCall Perform Calculations moduleCall Perform Calculations moduleCall Output Results ModuleCall Output Results Module

End ProgramEnd Program

Input Data moduleInput Data modulePrompt for Principal, PercentageRate, Term, FrequencyPrompt for Principal, PercentageRate, Term, FrequencyInput Principal, PercentageRate, Term, FrequencyInput Principal, PercentageRate, Term, Frequency

End moduleEnd module

Perform Calculations modulePerform Calculations moduleSet Rate = PercentageRate / 100Set Rate = PercentageRate / 100Set FinalValue = Principal * (1 + Rate / Frequency) ^ (Frequency * Term)Set FinalValue = Principal * (1 + Rate / Frequency) ^ (Frequency * Term)

End moduleEnd module

Output Results ModuleOutput Results ModuleWrite Principal, PercentageRate, Term, FrequencyWrite Principal, PercentageRate, Term, FrequencyWrite FinalValueWrite FinalValue

End moduleEnd module

Page 36: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Hierarchy Chart (HIPO Hierarchy Chart (HIPO Chart)Chart)

• A HIPO Chart (“Hierarchy of Inputs, A HIPO Chart (“Hierarchy of Inputs, Processes & Outputs”) is similar to an Processes & Outputs”) is similar to an organization chart – it shows what organization chart – it shows what modules exist and how they are related.modules exist and how they are related.

• It’s a good idea to keep modules short – It’s a good idea to keep modules short – about 1 page per module.about 1 page per module.

• We will have very small modules while We will have very small modules while getting comfortable using these tools.getting comfortable using these tools.

Page 37: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

HIPO Chart for HIPO Chart for Brewster’s Thousands Brewster’s Thousands

ExampleExample

Main Module

Input Data

Perform Calculations

Output Results

Page 38: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

CodingCoding

• Coding is done in a specific programming Coding is done in a specific programming language. In this part of the course, we language. In this part of the course, we will use pseudocode. Later, we’ll adapt our will use pseudocode. Later, we’ll adapt our pseudocode to write in JavaScript.pseudocode to write in JavaScript.

• Coding before finishing a solid algorithm is Coding before finishing a solid algorithm is a lot like putting the cart before the horse a lot like putting the cart before the horse and usually spells disaster. Time well-and usually spells disaster. Time well-spent in the design phase will head off spent in the design phase will head off problems in coding!problems in coding!

Page 39: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

DocumentationDocumentation

• Internal Documentation Internal Documentation – Comments explain to the reader the logic and Comments explain to the reader the logic and

decision processes of the programmer. Comments decision processes of the programmer. Comments are ignored by an interpreter or compiler.are ignored by an interpreter or compiler.

– Types of comments include code comments, Types of comments include code comments, documentation comments & module comments.documentation comments & module comments.

• External DocumentationExternal Documentation– External documentation includes a External documentation includes a user’s guide user’s guide

and, typically, a more technical and, typically, a more technical system system administrator’s guideadministrator’s guide..

Page 40: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

TestingTesting

• Most of the work should be done before Most of the work should be done before the phase begins – creating of a testing the phase begins – creating of a testing document.document.

• Two types of testing:Two types of testing:– Testing for errorsTesting for errors– Quality/Usability testingQuality/Usability testing

• Two phases of testing:Two phases of testing:– Alpha testing (Internal testing)Alpha testing (Internal testing)– Beta testing (Testing at the customer site w/ live data)Beta testing (Testing at the customer site w/ live data)

Page 41: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Types of ErrorsTypes of Errors

• Syntax – wrong grammar, i.e., breaking Syntax – wrong grammar, i.e., breaking the rules of how to write the languagethe rules of how to write the language– Forgetting punctuation, misspelling keywordForgetting punctuation, misspelling keyword– The program will not run at all with syntax The program will not run at all with syntax

errorserrors

• Logic - the program runs, but does not Logic - the program runs, but does not produce the expected results.produce the expected results.– Using an incorrect formula, incorrect sequence Using an incorrect formula, incorrect sequence

of statements, etc.of statements, etc.

Page 42: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Structured ProgrammingStructured Programming

• A method for designing and coding A method for designing and coding programs in a systematic, organized programs in a systematic, organized manner. manner.

• It combines the principles of top-It combines the principles of top-down design, modularity and the use down design, modularity and the use of the three accepted control of the three accepted control structures of structures of sequencesequence, , repetitionrepetition and and selectionselection..

Page 43: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Control StructuresControl Structures

• SequenceSequence –in sequential order. –in sequential order. – The simplest of control structures – start The simplest of control structures – start

at the beginning and continue in at the beginning and continue in sequential order.sequential order.

• SelectionSelection – selectively execute – selectively execute statementsstatements– Called a Called a branchbranch, it requires a condition to , it requires a condition to

determine when to execute statements.determine when to execute statements.

Page 44: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Control StructuresControl Structures

• RepetitionRepetition – repeat statements – repeat statements more than oncemore than once– Called a Called a looploop, it needs a stop condition, , it needs a stop condition,

I.e, the program will continue to loop I.e, the program will continue to loop until some condition is met.until some condition is met.

Page 45: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Event-Driven ProgrammingEvent-Driven Programming

• In an In an event-driven event-driven program, the flow of program, the flow of control is based on the user’s clicking on control is based on the user’s clicking on menus and buttons, etc. These user menus and buttons, etc. These user actions are called actions are called eventsevents..

• Event-driven programming still uses the Event-driven programming still uses the basic principles of structured programming basic principles of structured programming – program modules, control structures, – program modules, control structures, good programming style, and program good programming style, and program testing.testing.

Page 46: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

Questions?Questions?

Page 47: CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming

CSCI N201: Programming ConceptsCSCI N201: Programming ConceptsCopyright Copyright ©2004 ©2004 Department of Computer & Information ScienceDepartment of Computer & Information Science

ResourcesResources

• Venit, Stewart. Venit, Stewart. Extended Prelude to Extended Prelude to Programming: Concepts and Design.Programming: Concepts and Design. Scott/Jones, Inc., 2002.Scott/Jones, Inc., 2002.