Upload
maizie-planillo
View
235
Download
0
Embed Size (px)
Citation preview
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 1/69
Introduction to Computer Introduction to Computer ProgrammingProgramming
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 2/69
Review on Computer TerminologiesReview on Computer Terminologies
Computer something that ³computes´
takes input
processes input (according to particular steps )
produces output
Program a sequence of instruction executed
Computer P
rogram A set of detailed, step-by-step instruction that
directs the computer what to do also called assoftware
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 3/69
Terminologies Cont..Terminologies Cont..
A computer program may also be called:
Project
Application
Solution
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 4/69
Review on Computer TerminologiesReview on Computer Terminologies
Programming Language
A set of rules that provides a way of telling the computer
what operations to perform
is a set of syntactic and semantic rules used to define
computer programs. Computer Programmer
Creates computer program
Requirement: analysis, logic, knowledge w/ programming
language to use
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 5/69
Program Development CycleProgram Development Cycle
Software refers to a collection of instructions for the
computer
The computer only knows how to do what the
programmer tells it to do
Therefore, the programmer has to know how to
solve problems
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 6/69
Performing a Task on the Computer Performing a Task on the Computer
Determine Output
Identify Input
Determine process necessary to turn given Input
into desired Output
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 7/69
Steps in Program DevelopmentSteps in Program Development
1. Identification and analysis of the problem
2. Planning the solution
3. Setting up an algorithm program
4. Coding the program5. Program Compilation
6. Running , testing and debugging
7. Documentation
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 8/69
Programming ProcessProgramming Process
Create/Edit
Program
Compile
Program
Execute
Program
Compile Errors? Run-Time Errors?
Source
Program
Object
Program
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 9/69
Identification and analysis of the problemIdentification and analysis of the problem
Determine the ff:
Input -> Data
Output -> Information
Purpose: to analyze thoroughly
to understand the problem
to identify the inputs and outputs
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 10/69
Review program specs
Meet with analysts / users
Identify program components
(IPO ± Input, Processing, Output))
1. Defining the Problem1. Defining the Problem
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 11/69
2. Planning the Solution (Design)2. Planning the Solution (Design)
Design the algorithm
An algorithm is a finite series of logical steps
required to solve a particular problem.
Items covered in a next few slides
Use flowcharts and pseudocode.
Use the appropriate programming flow control
structures in the design
Desk check the solution
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 12/69
Example: Identification and analysis of theExample: Identification and analysis of theproblemproblem
Problem 1:
Write a program to will compute and display the
sum of five (5) number
Inputs:
7,8,3,2,1
Process
7+8+3+2+1
Output SUM
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 13/69
SUMSUM = 7 + 8 + 3 + 2 + 17,8,3,2,1
OutputProcessingInput
Example: IPO TableExample: IPO Table
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 14/69
Setting up an algorithm programSetting up an algorithm program
Design an Algorithms
A detailed, step by step solution to a program
the a straight forward sequence of logical / mathematical
instructions that must terminate (return 0) and describes
data to be processed to produce a desired options. Tools
Flowcharting
Pseudocode
³ false´ code
involves actually writing a program, written in English
rather than in a computer language.
See slides of analysis of algo
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 15/69
Algorithms in The Real World Algorithms in The Real World
We use algorithms almost daily in our lives
without realizing it
For example
an instruction manual
a cooking recipe
a knitting pattern
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 16/69
FlowchartingFlowcharting
A flowchart is a pictorial representation of an
algorithm or logical steps.
Each step is represented by a symbol and the
arrows indicate the flow and order of the steps.
The shape of the symbol indicates the type of
operation that is to occur.
Flowcharts may help the more visual students learn
and understand logic.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 17/69
Flowchart SymbolsFlowchart Symbols
Begin or End Input or Output
ProcessingDecision
Branch or Direction of Flow
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 18/69
Flow Control StructuresFlow Control Structures
Flow control is the order in which statements are
executed.
There are four control structures.
1. Sequence Control2. Selection Control
Also referred to as branching (if and if-else)
3. Case Control (similar to selection)
4. Repetition Control (loops)
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 19/69
FlowchartFlowchart ± ± Sequence ControlSequence Control
Begin
Input
price, qty
subtotal =
price * qty;
Output
subtotal
End
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 20/69
FlowchartFlowchart ± ± Selection ControlSelection ControlCalculate Handling based on total weight of the order Calculate Handling based on total weight of the order
If weight < 10
Handling = 3.00
Handling = 1.00
Output Handling
True
False
InputWeight
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 21/69
FlowchartFlowchart ± ± Case ControlCase Control
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 22/69
FlowchartFlowchart ± ± Repetition Control (loops)Repetition Control (loops)
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 23/69
Example: FlowchartingExample: Flowcharting
START
SUM = 7 + 8 + 3 +2 +1
END
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 24/69
Example: PsuedocodeExample: Psuedocode
Begin procedure
Input 7,8,3,2,1
Sum = 7+8+3+2+1
Output SUM
End procedure
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 25/69
Coding the programCoding the program
Translating algorithms into a formal programming
language
IDE / Programming Environment
Integrated Development Environment
A comprehensive package that includes text editors,
translation and debugging software
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 26/69
Setting up an algorithm programSetting up an algorithm program
Design an Algorithms
A detailed, step by step solution to a program
the a straight forward sequence of logical / mathematical
instructions that must terminate (return 0) and describes
data to be processed to produce a desired options. Tools
Flowcharting
Psuedocode
³ false´ code
involves actually writing a program, written in English
rather than in a computer language.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 27/69
SUMSUM = 7 + 8 +
3 + 2 + 1
7,8,3
,2,1
OutputProcessingInput
Example: IPO TableExample: IPO Table
/*
* A C program example
*/
#include <stdio.h>
main()
{
SUM = 7 + 8 + 3 + 2 + 1;
printf(³The sum is %d³,
SUM);
}
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 28/69
Program CompilationProgram Compilation
Checks that there is no violation of programming
language
Compiler
reads entire source code the converts it to object code,
which then it is now executed by the computer
Interpreter
reads source code one line at a time, and perform the
specific instruction contained in one line
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 29/69
Compilers & InterpretersCompilers & Interpreters
A compiler translates all of the source
code into object code, an executable
program. During this translation process,
a program listing of any syntax errors is
produced.
An interpreter translates one line of thesource code at a time. Interpreters run
programs more slowly than compilers,
but they are helpful programs for finding
syntax errors, because they are
interactive.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 30/69
Running Testing and DebuggingRunning Testing and Debugging
Check and corrects errors
Types of errors
Syntactical / Logical Errors
Compile-time /R
un-time Errors
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 31/69
DocumentationDocumentation
Syntactical / Logical Errors Syntactical errors
are due failure from ff the syntax
Syntax grammatical rules of the language defining its legal constructs
Logical Errors formulation of algorithms, wrong analysis / approach
Compile / Run-time Errors Compile-time
halt compilations
Compilation method in translating program codes into machine codes
Note: syntax error encountered during compilation is a compile-timeerror
Run-time error appears during execution or the program
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 32/69
DocumentationDocumentation
includes the pictorial and written descriptions of the software.
It contains internal descriptions of programming commands
and external descriptions and instructions.
Problem definition, algorithms, error-free source code, testing
procedures
Documentation is necessary since, sooner or later, the
program will need to be maintained (correct bugs, add new
features, handle problems not thought of previously, etc. This
is very difficult without documentation
Examples
books, manuals, and pamphlets
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 33/69
ProblemProblem--solving approach like algebrasolving approach like algebraclassclass
How fast is a car traveling if it goes 50 miles in 2
hours?
Output: a number giving the rate of speed in miles
per hour
Input: the distance and time the car has traveled
Process: rate = distance/time
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 34/69
Pictorial representation of the problemPictorial representation of the problemsolving processsolving process
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 35/69
Program PlanningProgram Planning
A recipe is a good example of a plan
Ingredients and amounts are determined bywhat you want to bake
Ingredients are input
The way you combine them is the processing What is baked is the output
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 36/69
Program Planning TipsProgram Planning Tips
Always have a plan before trying to write a
program
The more complicated the problem, the
more complex the plan must be
Planning and testing before coding saves
time coding
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 37/69
Program development cyclProgram development cyclee
1. Analyze: Define the problem.
2. Design: Plan the solution to the problem.
3. Choose t he interface: Select the objects
(text boxes, buttons, etc.).
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 38/69
Program development cycleProgram development cyclecontinuedcontinued
4. Cod e: Translate the algorithm into aprogramming language.
5. T est and d ebug : Locate and remove anyerrors in the program.
6. Complete t he docu mentati on: Organize allthe material that describes the program.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 39/69
2.2 Programming Tools2.2 Programming Tools
Three tools used to convert algorithms intocomputer programs:
Flowcharts - Graphically depict the logical steps to carry out atask and show how the steps relate to each other.
Pseudocode - Uses English-like phrases with some VB.NET
terms to outline the program. Hierarchy charts - Show how the different parts of a program
relate to each other.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 40/69
Algorithms Algorithms
A step by step series of instructions for solving a
problem (a recipe is an example of an algorithm)
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 41/69
Problem solving exampleProblem solving example
How many stamps do you use when mailing a
letter?
One rule of thumb is to use one stamp for every five
sheets of paper or fraction thereof.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 42/69
Algorithm Algorithm
1. Request the number of sheets of paper; call it
Sheets. ( input )
2. Divide Sheets by 5. ( processing )
3. Round the quotient up to the next highest whole
number; call it Stamps. ( processing )
4. Reply with the number Stamps. ( output )
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 43/69
FlowchartsFlowcharts
Graphically depict the logical steps to carry out a
task and show how the steps relate to each other.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 44/69
Flowchart symbolsFlowchart symbols
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 45/69
Flowchart symbols continuedFlowchart symbols continued
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 46/69
FlowchartFlowchartexampleexample
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 47/69
PseudocodePseudocode
Uses English-like phrases with some VB terms to
outline the task.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 48/69
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 49/69
HierarchyHierarchy chartscharts
Show how the different parts of a program relate to each other
Hierarchy charts may also be called
structure charts
HIPO (Hierarchy plus Input-Process-Output) charts
top-down charts VTOC (Visual Table of Contents) charts
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 50/69
Hierarchy charts exampleHierarchy charts example
Each entryrepresents a
module
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 51/69
DivideDivide--andand--conquer conquer methodmethod
Used in problem solving ± take a large problem and
break it into smaller problems solving the small
ones first
Breaks a problem down into modules
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 52/69
Statement structureStatement structure
Sequence ± follow instructions from one line to the next
without skipping over any lines
Decision - if the answer to a question is ³Yes´ then one
group of instructions is executed. If the answer is ³No,´ then
another is executed
Looping ± a series of instructions are executed over and
over
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 53/69
SequenceSequenceflow chartflow chart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 54/69
Decision flow chartDecision flow chart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 55/69
Looping flow chartLooping flow chart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 56/69
Direction of Numbered NYC StreetsDirection of Numbered NYC Streets Algorithm Algorithm
P r oblem: Given a street number of a one-way
street in New York, decide the direction of the
street, either eastbound or westbound
Discussi on: in New York even numbered streets
are Eastbound, odd numbered streets areWestbound
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 57/69
FlowchartFlowchart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 58/69
PseudocodePseudocode
Program: Determine the direction of a numbered NYC street
Get street
If street is even Then
Display Eastbound
ElseDisplay Westbound
End If
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 59/69
Hierarchy ChartHierarchy Chart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 60/69
Class Average AlgorithmClass Average Algorithm
P r oblem: Calculate and report the grade-point average for aclass
Discussi on: The average grade equals the sum of all gradesdivided by the number of students
O ut put: Average grade
In put: Student gradesP r ocessing: Find the sum of the grades; count the number of
students; calculate average
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 61/69
FlowchartFlowchart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 62/69
PseudocodePseudocode
P r ogram: Determine the average grade of a class
Initialize Counter and Sum to 0
Do While there are more data
Get the next Grade
Add the Grade to the Sum
Increment the Counter
Loop
Computer Average = Sum/Counter
Display Average
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 63/69
Hierarchy ChartHierarchy Chart
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 64/69
PseudocodePseudocode & Algorithm& Algorithm
Example 1: Write an algorithm to determine a
student¶s final grade and indicate whether it is
passing or failing. The final grade is calculated as
the average of four marks.
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 65/69
PseudocodePseudocode & Algorithm& Algorithm
Pseudocode:
I nput a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
P rint ³FAIL´
else
P rint ³ P ASS ́
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 66/69
The FlowchartThe Flowchart
A Flowchart
shows logic of an algorithm
emphasizes individual steps and their
interconnections
e.g. control flow from one action to the next
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 67/69
Flowchart SymbolsFlowchart Symbols
Basic
8/3/2019 1) Introduction to Computer Programming
http://slidepdf.com/reader/full/1-introduction-to-computer-programming 68/69