0% found this document useful (0 votes)
2 views45 pages

Lecture 1 - Introduction to Programming

The document provides an introduction to computer programming, explaining the definition of a computer program, the programming process, and various programming languages including machine, assembly, and high-level languages. It outlines the programming cycle, which includes problem analysis, algorithm design, coding, and execution, as well as the concepts of syntax errors, debugging, and logical errors. Additionally, it discusses programming methodologies such as procedural and object-oriented programming, highlighting their characteristics and examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views45 pages

Lecture 1 - Introduction to Programming

The document provides an introduction to computer programming, explaining the definition of a computer program, the programming process, and various programming languages including machine, assembly, and high-level languages. It outlines the programming cycle, which includes problem analysis, algorithm design, coding, and execution, as well as the concepts of syntax errors, debugging, and logical errors. Additionally, it discusses programming methodologies such as procedural and object-oriented programming, highlighting their characteristics and examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Introduction to Comput

Programming
Programming
Computer Program
 Sequence of statements intended to
accomplish/perform certain task.
 It is a set of instructions for a computer to follow
Example of Computer
Program
 A computer program that compute the
numbers using basic arithmetic operator
 A program that accept input from the user
then print the summary of information
Programming
 Process of planning and creating a program
Machine Language
• The language that the computer can directly
understand.
Assembly Language
 Symbolic form of machine language that is
easier for people to read (for example ADD
AX DX).
 This makes use of instructions in mnemonic
form
 A program that translate assembly
languages instruction into language is
called assembler.
High Level languages
 Most modern programming language are
designed to be relatively easy. These are known
as high level languages.
 Each high-level language has its own syntax, or
rules of the languages (For example, the verb
print or write is used to produce an output)
 In programming, programmer writes a series of
program statements which carry out task the
program has to perform.
Compiler
 A program that translate a program written in a
high-level language into a low-level language
(such as machine language) before executing the
statements.
Interpreter
• Act as a compiler, but it translates one (1)
program statement at a time, this execute
statement as soon as it is translated.
Syntax Error
 In the process of translation, an invalid
program statement might be encountered
known as syntax error. (for example, the
mathematical expression 3+3 = 6 is written
incorrectly as 3#3=6.
Debugging
 The process/act of locating and repairing
the errors of program is called debugging.
Logical Error
 Apart from syntax error, logical error might
be encountered as well. Logical Error
(Semantic Error) occurs when the syntax of
the program is correct, but the expected
output is not.
Programming Cycle
Algorithm
 Step by step problem solving process in
which a solution is arrived at in a finite
amount of time.
The problem-solving process in the
programming environment involves the
following steps:
1. Problem Analysis: Analyze the problem and
outline
the problem and its solution requirements.
2. Analysis Algorithm: Design an algorithm to
solve a
problem.
3. Coding: implement the algorithm in programming

language.
4. Execution: Verify that the algorithm works.
Figure 1
Figure 1: Problem analysis-coding-execution cycle
(Malik, 2012)
• To develop a program that solves a problem, start
first by analyzing the problem, then outlining the
problem and the option for a solution. Then
design the algorithm, write the program
instructions, and enter the program into a
computer system.
Problem Analysis
This steps requires you to do the following:
1. Thoroughly understand the problem
2. Understand the problem requirements
3. If the program produces output, know the results
should be generated and formatted.
4. If the problem is complex, divide the problem into
sub-problems. Repeat Steps 1 and 2 by analyzing
and understanding each sub-problem.
Algorithm Design
• After analyzing the problem, the next step is to design an
algorithm to solve it. If the problem is broken down into sub
problems, there should be an algorithm for each sub
problem. You should check the algorithm for correctness
and integrate the solution to sub-problems.
Coding
• The next step is to convert the algorithm into a programming
language, usually a high-level language. A text editor or IDE
(Integrated Development Environment) is used to write a
program to make sure that the program follows the
language’s syntax.
• To ensure the syntax is correct, the code is run through a
compiler. If error messages are encountered, the errors
must be identified and resolved (debugging). When the
program is free from any syntax error, the compiler
generates the machine code.
Example of Algorithm:
• The following algorithm is design to know the
firstname, lastname and middlename. It is supposed
to concatenate the value of the fields to display the
fullname. The concatenation of fields is : fullname =
firstname + “ “ + middlename + “ “ + lastname
Example of Algorithm: Cont.
1. GET the firstname, lastname and middlename
2. Concatenate fields: fullname = firstname + “ “ +
middlename + “ “ + lastname
3. Display fullname
• In this example, the algorithm is designed to determine
whether a student fails or passes by computing the average
of his grades in three (3) subjects. Computer Programming
1, Communication Art 1 and Physical Education 1. If the
average is greater than or equal 75, the student passed,
otherwise the student failed.
The algorithm to determine whether a student is
passed or failed.
1. Get the student’s grade in Computer Programming
1, Communication Art 1, and Physical Education 1.
2. Compute the average using the formula : average =
subject1 + subject2 + subject 3 divide by total
number of subject.
3. Is average greater than or equal 75, if yes, then the
student passed, otherwise student failed.
Pseudocode
 Method of describing computer algorithms
using a combination of natural language
and programming language.
• Here are some rules that are frequently
followed when writing pseudocode.
 Symbols are used for operations
- Arithmetic Operations (+, - ,* ,/ .
- Assignment (=)
- Comparison (=, <,>, <=,>=)
- Logical (and, or)
 Certain keywords can be used as a
command, such as PRINT, WRITE, READ,
SET, etc.
 Indentation is used to indicate branches
and loops of instructions.
Example
• The following pseudocode is design to know the
firstname, lastname and middlename. It is supposed to
concatenate the value of the fields to display the fullname.
The concatenation of fields is : fullname = firstname + “ “ +
middlename + “ “ + lastname
• READ firstname
• READ lastname
• READ middlename
• SET fullname to firstname + “ “ +
middlename + “ “ + lastname
• Print fullname
• In this example, the pseudocode is designed to
determine and display whether a student fails or
passes by computing the average of his grades in
3 subjects: Computer Programming 1,
Communication Art 1, and Physical Education 1. If
the average is greater than or equal to 75, the
student passed, otherwise the student failed.
Flowchart
 Visual representation of an algorithm
 It contains symbols/shapes describing how
an algorithm or program operates.
 Each command/instruction is placed in an
appropriate shape, and arrows are used to
direct program flow.
Figure 2: Flowchart shapes and
functions
Example:
• Create a flowchart that computes and
display the average of a student’s scores for
3 quizzes.
• The flow chart to compute and display the
student’s average is shown
Example:
• In this example, the flowchart uses a predefined
process. A predefined process is commonly used
when a certain process is repeated. This process is
defined in a separate flowchart.
Example:
• Create a flow chart that determine whether the exam
score of a student is passed or failed. If the scores is
greater than or equal to 50, then the student passed,
otherwise failed.
Programming
Methodology
 Set of practices
 In programming, there are methodologies used to
deal with the analysis, designing, and
implementation of programs. These are called
programming methodologies.
There are 2 popular approaches to writing a
computer programs. These are:
• Procedural Programming: It is like assembling
code of blocks from beginning to end in a
procedural manner. Procedural Programming is
suitable only for small programs that have low of
complexity.

Example of Procedural Programming:


• A program that involves collecting data from the
user, perform calculations on the collected data,
and display the result of calculated data.
 Object Oriented Programming: It is possible to use
the same code from different program without copying
it. One of the advantage of OOP is the code reusability.

Example of Object Oriented Programming:


• In an inventory system, there should be entities like
customer, product, point of sales structure which
solution must be built.
END

You might also like