Sei sulla pagina 1di 29

Introduction to Computer Programming

Prepared by: LCLintag

Definition
Computer
Is a programmable electronic device that can process, store and retrieve data and/or information.

Program or Computer Program


Is a set of detailed, step-by-step instructions that directs the computer what you want it to do Notation for expressing instructions to be carried out by a computer Programs are written in a programming language Sets of rules that provides a way of telling the computer what operations to perform.
2

Program

a sequence of instruction executed


A computer program may also be called:
Project Application Solution

Computer Programmer
The person who creates computer program. Requirement: analysis, logic, knowledge w/ programming language to use

Program 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

Performing a Task on the Computer


Determine Output Identify Input Determine process necessary to turn given Input into desired Output

Steps in Program Development


1. 2. 3. 4. 5. 6. 7. Identification and analysis of the problem Planning the solution Setting up an algorithm Coding the program Program compilation Running, testing and debugging Documentation
6

Identification and analysis of the problem


Determines the data (input) necessary to produce the output. Defining the variable to represent the input is a part of this step. Determines the output as a solution to the problem. Defining the variable to represent the output is a part of this step.

Determine the ff: Input -> Data Output -> Information

Purpose: to analyze thoroughly to understand the problem to identify the inputs and outputs
7

1. Defining the Problem


Review program specs Meet with analysts / users Identify program components (IPO Input, Processing, Output))

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
9

Example: Identification and analysis of the problem 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

10

Example: IPO Table


Input Processing Output 7,8,3, SUM = 7 + 8 + 3 SUM 2,1 +2+1

11

Setting 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.

12

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.
13

Flowchart Symbols
Input or Output

Begin or End

Processing

Decision

Branch or Direction of Flow


14

Flow Control Structures


Flow control is the order in which statements are executed. There are four control structures.
1. Sequence Control 2. Selection Control
Also referred to as branching (if and if-else)

3. Case Control (similar to selection) 4. Repetition Control (loops)


15

Flowchart Sequence Control


Begin

Input price, qty

subtotal = price * qty;

Output subtotal
End
16

Calculate Handling based on total weight of the order


Input Weight

True
If weight < 10

Handling = 1.00

False Handling = 3.00

Output Handling
17

Flowchart Case Control

18

Flowchart Repetition Control (loops)

19

Example: Flowcharting
START

SUM = 7 + 8 + 3 +2 +1

END
20

Coding 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

This step involves translating the algorithm into a formal programming language.
21

Programming Process

Compile Errors?

Run-Time Errors?

Create/Edit Program

Source Program

Compile Program

Object Program

Execute Program

22

Example: Coding the Program


Algorithm Start Input Q1, Q2, Q3, Q4 Program main(){ int Q1, Q2, Q3, Q4 scanf(%d,&Q1); scanf(%d,&Q2); scanf(%d,&Q3); scanf(%d,&Q4); Average=(Q1+Q2+Q3+Q4)/4;

Compute Average= (Q1+Q2+Q3+Q4)/4

Output Average
printf(the Average is %d, Average);

23

Program Compilation
This is the phase where the programmer makes sure that there is no violation on the rules 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

24

Running, Testing and Debugging


This nest step is to execute and then run the program. The program upon execution is being subjected to different kinds of test data to anticipate and correct errors that might occur before releasing the program to the users.
25

Error Classification
Syntactical, (logical errors) Compile, (run-time errors)

26

ERRORS
Syntactical Errors are due to failure from following the syntax of a particular language. Syntax refers to the grammatical rules of the language defining its legal constructs. Logical Errors are difficult to identify. Such errors may occur during the formulation of algorithm, wrong analysis of the problem or the approach of the programmer on finding the right answer to the problem
27

Compile-time Errors halt the compilation of the program. Compilation means translating the program codes into a form that the physical computing machine can understand. Run-time Errors are errors that appear during the execution of the program. Once the program starts running, it means that the program is already free from syntax errors and compilation has already been successfully finished

28

Documentation
The programmer gathers all the materials generated during each step. The detailed problem definition, the algorithm, the error free source code and testing procedures are all part of the documentation package.

29

Potrebbero piacerti anche