Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Calculate
A program can instruct a computer to perform mathematical operations.
Store
A program will often instruct a computer to store intermediate results.
IF-THEN
Entry Test condition p
false true
Exit
True statement a
IF-THEN-ELSE
Entry Test condition p
false true
false statement a
Exit
true statement a
Iterate
A program loop is a form of iteration. A computer can be instructed to repeat instructions under certain conditions.
No
Leading Decisions
If the stop is at the beginning of the iteration, then the control is called a leading decision. The command WHILE performs the iteration and places the stop at the beginning.
WHILE Loop
Entry Exit Test condition p
Yes No
Loop statement a
Trailing Decisions
If the stop is at the end of the iteration, the control mechanism is called a trailing decision. The command DO UNTIL performs the iteration and puts the stop at the end of the loop.
DO UNTIL Loop
Entry
Exit
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.
In words
Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print FAIL else Print PASS
Logic Flowcharts
These represent the flow of logic in a program and help programmers see program design. It is a way of visually presenting the flow of data, the operations performed within the system and the sequence in which they are performed.
Advantages / Disadvantages
Advantages Provides convenient method to understand the solution. helps in debugging process Provide guide for coding. Disadvantages Not suitable for large programs.
Calculate Pay
The program computes the sum, average and product of three numbers:
Example
START Input M1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
IS GRADE<5 0
Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print FAIL else Print PASS endif
PRINT PASS
PRINT FAIL
STOP
Psuedocode
This device is not visual but is considered a first draft of the actual program. Pseudocode is written in the programmers native language and concentrates on the logic in a programnot the syntax of a programming language.
Pseudocode
Step 1: Step 2: Step 3: Input M1,M2,M3,M4 GRADE (M1+M2+M3+M4)/4 if (GRADE < 50) then Print FAIL else Print PASS endif
Calculate Pay
Practice
Practice Solution
Programs
A program is a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want. Computer programs are written in programming languages.
Programmer
A person who develops a program is called programmer. The programmer develops programs to instruct the computer how to process data to convert into information Programmers use programming languages to write programs
Programming Languages
A computer language is a means of communication between user and computer. A programming language is a set of rules that provides a way of telling a computer what operations to perform.
Machine Languages
different for each computer processor
0100 001101 100000 001101 110001 00101 10001 10000 01110 111001 . . .
2.Assembly Languages
It is low-level language It is one step higher than machine language In assembly language, symbols are used instead of binary code These symbols are called mnemonics For example: sub instruction is used to subtract two numbers. It is also called symbolic language It is mostly used for writing system software. Assembly language is also known as second generation language.
Assembly Languages
different for each computer processor
main
High-Level Languages
1.Procedural Languages: Procedural Languages are also known as third generation languages or 3GL. In these languages program are written in predefined set of instructions Computer execute these instruction in the same sequence in which these instructions are written. Each instruction in this language tells the computer what to do and how to do.
1.Procedural Languages:
Some procedural languages are as follows FORTRAN (Formula Translation) BASIC (Beginners All Purpose Symbolic Instruction Code) COBOL (Common Business Oriented Language) PASCAL C
Language Translator
Language processor or translator is software that converts these programs into machine language Each computer language has its own translators. Different types of language translator are : compilers Interpreters Assembler
Compiler
Translates the entire program to machine code before running it. A program written in high level language is called source program. The compiler convert source program in the machine code called object program. The object program can be executed many times. Compiler also checks syntax errors in the program A source program containing an error cannot be compiled
Interpreter
Translates instructions to machine code line-by-line or statement by statement. It executes statement before translating the next statement of the source program If there is an error in the statements , the interpreter stops working and displays an errors message. The disadvantage of interpreter is that it is not very efficient The interpreter does not produce an object code .it must convert the program each time it is executed . Visual Basic uses interpreter.
Programmers Lingo
Interpreter Process
Assembler
An assembler is a translating program that translates the instructions of a program written in assembly language into machine language.
Assembly language program code Object
Assembler
Programmers Lingo
Program - detailed set of instructions for a computer Programming Language - tool used to create a program; defined by semantics and syntax Semantics - the meaning of words in a language Syntax - rules for combining symbols of a language
Programmers Lingo
Source Code (code) - program you write using a programming language
ASSIGNMENT
1. Draw flowchart for calculating average of 25 exam scores. the