Documente Academic
Documente Profesional
Documente Cultură
Topics
Planning the Computer Program Flowchart Types of Logic used in Flowchart Examples Hierarchy of Programming languages Classification of programming language Popular programming language Program development process Characteristics of a Good Program Error in Programming
Algorithm
a precise rule (or set of rules) specifying how to solve some problem the set of simple instructions that combine to accomplish a task.
Programming
Program a set of detailed, step-by-step instructions that directs the computer to process data into information. Programming language a set of rules (syntax) and commands that provides a way of telling the computer what operations to perform. Programmer designs algorithm and converts it into computer instructions and tests programs as developed.
Define the problem Design the solution Code the program Test the program Document the program Implement the program
The phases will be reviewed over next few slides
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.
8
Begin or End
Processing
Decision
Program logic
Read the file If condition satisfy do the process Else do another process Go to first step to read the next record. Stop if all records are read.
Types of Logic
Straight Sequential Execution Transfer of Control Looping
13
14
15
Case Control
16
17
Should be written before a program is coded. Read from top to bottom unless a branch alters the normal flow. Each symbol represents a specific function. The note inside each symbol indicates the specific operation.
Advantages of flowchart: Communication: Flowcharts are better way of communicating the logic of a system to all concerned. Effective analysis: With the help of flowchart, problem can be analysed in more effective way. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase. Proper Debugging: The flowchart helps in debugging process. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part
Disadvantages of flowchart: Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. Alterations and Modifications: If alterations are required the flowchart may require re-drawing completely. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem. The essentials of what is done can easily be lost in the technical details of how it is done.
Draw a flowchart to find the selling price of an item, given percentage loss or gain and the cost price of an item. Draw a flowchart to compute and print the grades for an examination. Input is roll number, and marks of 5 subjects out of 100. Draw a flowchart to calculate the value of X power N, where X is an integer and N has a +ve integer. Draw a flowchart to find the sum of first 50 odd numbers.
Pseudocode
Pseudocode is a mixture of programming code and English like statements. Used when designing algorithms. When designing, we dont necessarily want to be concerned about specific method names. We want to concentrate on the design and logic. Later we can look up specific properties or method names.
30
34
Programming Language
A programming language is a set of written symbols that instruct the computer hardware to perform specified tasks. Basic instructions
Input/output instructions Arithmetic instruction Logic instruction Control instruction Data movements instructions Specification instructions
Assembly language
Machine language
Harware
Declarative language
Command languages which tells what to do instead of how to do it. Example SAS and SPSS.
Example: Statement:
a= a + b
Before b
10 7
a After b
17 7
Interpreter
A translator which translates a program into machine language one line at a time
Compiler
Translate a whole program at once into machine language. It can be executed any time. The source code remains intact and be updated.
LOAD BASEPAY
ADD OVERPAY STORE GROSSPAY
Visual Basic
COBOL Java
44
Common errors
Initialize variables counters and pointers Inverting conditions, such as jumping on zero instead of on not zero Reversing the order of operand Jumping on conditions that have been changed Confusing address and values Ignoring Overflow
Errors in programming
3 categories
Syntax errors
Misspelled keywords, missing commas Undefined
execution errors
Division by zero Number calculated exceeds the computer capacity Loss of significant digits
Logical errors
Sequence of statement
Trapezoidal rule
Exercise: Approximate using Simpson's Rule with n = 4. Answer x = (3 - 2)/4 = 0.25 y0 = f(a) = f(2) = 1/(2 + 1) = 0.3333333 y1 = f(a + x) = f(2.25) = 1/(2.25+1) = 0.3076923 y2 = f(a + 2x) = f(2.5) = 1/(2.5+1) = 0.2857142 y3 = f(a + 3x) = f(2.75) = 1/(2.75+1) = 0.2666667 y4 = f(b) = f(3) = 1/(3+1) = 0.25