Академический Документы
Профессиональный Документы
Культура Документы
Computer
something that computes takes input processes input (according to particular steps) produces output a sequence of instruction executed A set of detailed, step-by-step instruction that directs the computer what to do also called as software
Program
Computer Program
Terminologies Cont..
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. Creates computer program Requirement: analysis, logic, knowledge w/ programming language to use
Computer Programmer
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
Determine Output Identify Input Determine process necessary to turn given Input into desired Output
Identification and analysis of the problem Planning the solution Setting up an algorithm program Coding the program Program Compilation Running , testing and debugging Documentation
Programming Process
Compile Errors?
Run-Time Errors?
Create/Edit Program
Source Program
Compile Program
Object Program
Execute Program
Determine the ff: Input -> Data Output -> Information Purpose: to analyze thoroughly to understand the problem to identify the inputs and outputs
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
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
7,8,3,2,1 SUM = 7 + 8 + 3 + 2 + 1
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. Flowcharting Pseudocode
Tools
false code
involves actually writing a program, written in English rather than in a computer language.
We use algorithms almost daily in our lives without realizing it For example
an instruction manual a cooking recipe a knitting pattern
Flowcharting
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.
Flowchart Symbols
Begin or End
Input or Output
Processing
Decision
Flow control is the order in which statements are executed. There are four control structures. 1. Sequence Control 2. Selection Control
3. 4.
Input Weight
True
If weight < 10
Handling = 1.00
Output Handling
Example: Flowcharting
START
SUM = 7 + 8 + 3 +2 +1
END
Example: Psuedocode
Begin procedure Input 7,8,3,2,1 Sum = 7+8+3+2+1 Output SUM End procedure
Integrated Development Environment A comprehensive package that includes text editors, translation and debugging software
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. Flowcharting Psuedocode
Tools
false code
involves actually writing a program, written in English rather than in a computer language.
Program Compilation
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
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 the source code at a time. Interpreters run programs more slowly than compilers, but they are helpful programs for finding syntax errors, because they are interactive.
Check and corrects errors Types of errors Syntactical / Logical Errors Compile-time / Run-time Errors
Documentation
Syntactical errors
Logical Errors
Compile-time
Note: syntax error encountered during compilation is a compile-time error appears during execution or the program
Run-time error
Documentation
includes the pictorial and written descriptions of the software. It contains internal descriptions of programming commands and external descriptions and instructions.
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
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
Program Planning
A recipe is a good example of a plan Ingredients and amounts are determined by what you want to bake Ingredients are input The way you combine them is the processing What is baked is the output
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
Algorithms
A step by step series of instructions for solving a problem (a recipe is an example of an algorithm)
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.
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)
Flowcharts
Graphically depict the logical steps to carry out a task and show how the steps relate to each other.
Flowchart symbols
Flowchart example
Pseudocode
Pseudocode example
Determine the proper number of stamps for a letter Read Sheets (input) Set the number of stamps to Sheets / 5 (processing) Round the number of stamps up to the next whole number (processing) Display the number of stamps (output)
Hierarchy charts
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
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
Statement 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
Problem: Given a street number of a one-way street in New York, decide the direction of the street, either eastbound or westbound Discussion: in New York even numbered streets are Eastbound, odd numbered streets are Westbound
Flowchart
Pseudocode
Program: Determine the direction of a numbered NYC street Get street If street is even Then Display Eastbound Else Display Westbound End If
Hierarchy Chart
Flowchart
Pseudocode
Program: 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
Hierarchy Chart
Example 1: Write an algorithm to determine a students final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.
The Flowchart
A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next
Flowchart Symbols
Basic
Example 2
Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudocode: Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)
Example 2
Algorithm Step 1: Input Lft Step 2: Lcm n Lft x 30 Step 3: Print Lcm Flowchart
START
Input Lft
Lcm n Lft x 30
Print Lcm
STOP