You are on page 1of 42

Quarter I

Introduction to
Programming

What is Programming?
Computer

programming or
programmingis the craft of writing useful,
maintainable, and extensible source code
which can be interpreted or compiled by a
computing system to perform a meaningful
task.
It is also a method of solving a problem.
Programming uses algorithms.

Seven Basic Programming Elements


Input:

getting data and commands into the


computer
Data Types: definition of a set of data that
specifies the possible range of values of the
set, the operations that can be performed on
the values, and the way in which the values
are stored in memory.
Arithmetic: performing mathematical
calculations on your data
Output: getting your results out of the
computer

Seven Basic Programming Elements


Conditional:

testing to see if a condition is

true or false
Looping: cycling through a set of
instructions until condition is met
Subroutines or Functions: usually
performs a single task.

What is a Programming Language?


Aprogramming

languageis a special
languageprogrammersuse to develop
software programs,scripts, or other sets
of instructions for computers to execute.

Reference:

http://www.computerhope.com/jargon/p/p
roglang.htm

Three Major Categories of


Programming Languages
Machine

Language
Assembly Language
High Level Language

Machine Language
Machine

language is the only language a


computer is capable of understanding.
A computer cannot directly understand the
programming languages used to create
computer programs, so the program code
must be compiled. Once a program's code is
compiled, the computer can understand it
because the program's code has been turned
into machine language.

Assembly Language
Sometimes

referred to
as assembly or ASL,assembly language is
a low-level programming language used to
interface with computer hardware.

High Level Language

Sometimes abbreviated as HLL, a high-level


language is a computer programming language that
isn't limited by the computer, designed for a specific
job, and is easier to understand. It is more like human
language and less like machine language. However,
for a computer to understand and run a program
created with a high-level language, it must be
compiled into machine language.
The first high-level languages were introduced in the
1950's. Today, there are many high-level languages in
use,including BASIC, C, C+
+, Cobol, FORTRAN, Java, Pascal, Perl, PHP,
Python, Ruby, and Visual Basic.

What was the first computer


programming
language?
Officially, the first programming
language for a computer was Plankalkl,
developed byKonrad Zusefor the Z3
between 1943 and 1945. However, it
was not implemented until1998.

Who was the first computer


programmer?
Ada

Lovelace or Augusta Ada Byron is


credited as being the worlds first computer
programmer.

Program and Algorithm


Program

is a list of organized instructions


that the computer must follow in order to
process data into information.

Algorithm

is a well-defined procedure that


allows a computer to solve a problem.

Polyas 4 Steps of Problem


Solving
U

Understand the Problem

Devise a Good Plan to Solve

Implement the Plan

Evaluate the Solution

Applying Polyas Problem Solving to Programming


Step 1 - Understand the Problem
What

is the Problem to be solved? What is the


unknown? What is the condition? What is the data?
What is needed to solve the problem? What actions
need to take place?
Identify the inputs and outputs
Identify the processes needed to produce the
outputs from the given inputs
Draw a figure. Introduce suitable notation.
Isolate Principle parts of the problem.

Applying Polyas Problem Solving to Programming


Step 2 - Devise a Plan
Find

connections between the knowns and


unknowns.
Simplify: Break the problem into smaller subproblems
Design a solution
Make a plan or list of actions to implement the
solution

Algorithm / Flowchart / Pseudocode

Applying Polyas Problem Solving to Programming


Step 2 - Devise a Plan (Cont.)
Algorithm
A FINITE set of clear, executable steps that will
eventually terminate to produce the desired outcome
Logical design used to solve problems usually a list
of actions required to perform task
Pseudocode
Written like program code but more English Like
and doesnt have to conform to language syntax
Flowchart
Diagram that visually represents the steps to be
performed to arrive at solution.

Algorithm
Derived

from the name of the mathematician


Muhammed ibn-Musa Al-Khowarizmi,
an algorithm is a solution to a problem that
meets the following criteria.

list of instructions, procedures, or formula


that solves a problem.
Can be proven.
Something that always finishes and works.

Examples of Algorithm Used


Today

Computers use algorithms to convert data (e.g.


converting decimal into binary).
Google search uses the PageRank algorithm to sort search
results.
Encryption to encrypt and decrypt information and keep
data safe is an algorithm.
GPS uses algorithms to find the best route to a destination.
There are dozens of sort algorithms that are used to sort
data.
Smartphones, Wi-Fi, and wireless communication use
algorithms to communicate.
E-mail spam detection uses algorithms to filter out bad emails.
Data compression for getting information faster (e.g.
YouTube video) use algorithms.

Pseudocode and Flowchart

Pseudocode (pseudo means fake) is an


algorithm written in normal human-language
statements to describe the logic and
processing flow.
Flowchart is a visual outline of an algorithm in
which the steps and processes to be followed
are represented by symbols.

Two Kinds of Flowcharts


1. System Flowchart
2. Program Flowchart

1. System Flowchart is a diagrammatic


representation of the broad flow of work,
documents, and operations.

2. Program Flowchart is a diagrammatic


representation of a solution to a given
problem for which the program is written.

Pseudocode

Problem:
Get the following data from the user: employees
name, hourly rate, number of hours worked, and
deductions. Calculate the employees gross pay and
net pay. Display the employees name, gross pay,
and net pay

Pseudocode:
READ name, hourly rate, hours worked, deductions
CALCULATE: Gross pay-hourly rate multiplied by
number of hours worked
CALCULATE: Net pay=Gross pay minus deductions
WRITE name, Gross pay, Net pay

Flowchart

Start
Input
Name, HrlyRate,
HrsWork, Deductn
GrossPay= HrlyRate * HrsWork

NetPay= GrossPay - Deductn


Print
Name,
GrossPay,
NetPay
End

Flowchart Symbols
Symbol

Name

Description

Terminal

Marks the beginning (START) and


the end (END,STOP) of the
program

Preparation

Contains the initial values of


variables or variable declarations

Input/Output
(I/O)

Contains any statement that


causes data to be inputted and
outputted to a program

Process

Contains an operation that shows


tasks, such as calculation or an
assignment of a value to a
variable

Decision

Contains a question or condition


that requires a yes/no or
true/false response and leads to
one of two or have alternative
course of action

Flowchart Symbols
Symbol

Name

Description

Secondary
Storage

Used as an input/output symbol


specifically for data moving in and
out of secondary storage

Predefined
Process

Contains the name assigned to a set


of instructions that are separated
from but maybe called within the
main program

On-page
connector

Connects two flowcharts segments


that are found on the same page to
eliminate lengthy flow lines

Off-page
connector

Connects 2 flowchart segments that


are found on different pages.

Flowlines and
Arrowheads

Connect symbols and indicate the


sequence of operations.

Applying Polyas Problem Solving to Programming


Step 3 - Implement the Plan
Implement

in a Programming Language
Carry out the plan checking the preliminary
results at each step.
Code A Little Test A lot

Applying Polyas Problem Solving to Programming


Step 4 - Evaluate the Solution
Run

the Code
Check results repeatedly and thoroughly
Use numerous test cases or data sets
Use highly varied test case, including expected as
well as and unexpected cases

Look

for new solutions

Is there a better, easier, or more efficient solution

Can

other problems be solved using these


techniques?

3 Types of Program Errors


Syntax

error is the most common error that


you will encounter in the programming. It is
caused by typographical errors and/or failure
to strictly follow the syntax of the
programming language.
Run-time error is a software error that
occurs while a program is being executed, as
detected by a compiler or other supervisory
programs.

Summary
U

- Read the Problem Statement


Identify the inputs, outputs, and processes

- Decide how to Solve the Problem


Create an Algorithm / Flowchart / Psuedocode

- Program the Code

Implement in Programming Language

- Test the Solution


Run the Code using numerous, varied test cases

Lecture Ends Here


Thank

you. Have a great day!

Steps in programming
1. Problem Analysis is defined by the
development

American National Standards Institute (ANSI)


as the methodical investigation of a problem
and the separation of the problems into a
smaller related units for further detailed
study.
2. Program Design process describes the
algorithm for the solution of the problem.
ex. Top-down design a program design
methodology that starts with defining
program at the highest level and then break
down each task into lower tasks.

Top-down design

Steps in programming
1. Program Coding the logic requirements
development

from pseudocode or flowcharts are translated


into lines of instructions using a
programming language.
Ex. Qbasic, Turbo C, Visual Basic, Java
2. Program Testing and Debugging involves
running various tests, such as desk-checking
and debugging (alpha testing) and then
running actual or real data to make sure the
program works (beta testing)

Steps in programming
1. Program Documentation and Maintenance
development
Documentation is the set of instructions
shipped with a program or piece of hardware.
Documentation usually includes necessary
instructions on the use and maintenance of
the product.

Syntax
Syntax

is the grammar of a language. It


consists of the rules governing the structure
and content of the statements.

3 Types of Program Errors


Logic

errors are caused by incorrect use of


control structures. These errors are much
more difficult to detect than syntax errors
because the computer cannot tell an error in
logic in a program

You might also like