Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

COMPUTER

PROGRAMMING 1
MODULE 1
INTRODUCTION TO
PROGRAMMING
Upon completion of this module, you will be able to:
• Define what is computer programming
• Define terms related to computer programming such as
source code, programs, etc.
• Know the difference between an Assembly Language and
Machine Language
• Describe what are the low and high-level languages
• Know the difference between procedural and object-
oriented programming
• Identify the steps in program development
Programming is a multistep
process for creating a program.

It is a way of giving computers


instructions about what they
should do next. These
instructions are known as code.
WHY PROGRAMMING IS IMPORTANT?

APPRECIATING THE ART OF


COMPUTER CODING
• Programming is important for
learning to innovate, create eco-
Programming is important
friendly solutions for global to automate, collect,
problems. manage, calculate, analyze
the processing of data and
• Programming is important for information accurately.
speeding up the input and
output processes in a machine.
COMPUTER PROGRAMMING TERMS
• A computer program is a list or sequence of instructions that
tell a computer what to do.
• Everything a computer does is done by using a computer
program.
• A computer program is written in a programming language.
• A programming language (PL) is a type of written language that
tells computers what to do in order to work.
• Programming languages are used to make all the computer
programs or software.
• Each PL has its own grammar called syntax. It consists of rules
governing the structure and content of the statement that should
be followed.
• A programmer writes source code using a programming
language to create programs.
• Source code is a well-written set of instructions and
statements to develop a program.
• Source code can be written in low-level or high-level
language.
• Source code must be translated to machine language
(binary form) using a language translator.
• Assembler translates a program written from an assembly
language to a low-level language.
• Interpreter translates each statement or one line at a time and
executed immediately after translation.
• Example: JavaScript, Python, Ruby
• Compiler translates all statements at one time. It provides all
the error messages – called diagnostics- at once.
• Example: C, C++, Java
• Low-level Language • High-level language
• uses instructions tied • uses English-like
directly to one type of instructions and can be
computer. run on a variety of
• often cryptic and not computer types.
human-readable.
Examples: Examples:
machine language, assembly Visual Basic, C, C++, Java
language
ASSEMBLY LANGUAGE C++ LANGUAGE

LOW-LEVEL HIGH-LEVEL
Within a computer, all data is
represented by microscopic • Instructions written in 0s and
1s are called machine
electronic switches that can language or machine code.
be either OFF or ON.
• Each class of computer has its
• OFF switch is designated by
a 0. own particular machine
• ON switch is designated by language
a 1. • Writing in machine language
Example: is tedious!
0100 0001 = capital ‘A’
A programming language with
Assembly language programs
symbolic names for opcodes,
must be translated into machine
and decimals or labels for
instructions, using an assembler.
memory addresses

Example:
ADD 1, 2
MUL 2, 3
PROGRAMMING PARADIGM
A programming paradigm is a style, or “way,” of
programming to solve problem using some programming
language.
It is an approach or method to solve a problem using tools
and techniques that are available to us following some
approach.
It is also a way to classify programming languages based on
their features.
• Procedure-oriented program, the programmer concentrates
on the major tasks that the program needs to perform. The
programmer must instruct the computer every step of the way,
from the start of the task to its completion.

Example:
In a payroll program, the program typically performs several
tasks, such as inputting the employee data, calculating the
gross pay, taxes, net pay, and outputting a paycheck.
• Object-oriented program requires the programmer to
focus on the objects that the program can use to
accomplish its goal. The objects can take on many different
forms.

Example:
In Windows-based program, it typically use objects such
as check boxes, list boxes, and buttons.
PROCEDURAL PROGRAMMING OBJECT-ORIENTED PROGRAMMING

Where:
Rotate(shapeNum) and
playsound(shapeNum) are functions
Where:
Shape is the class; Circle, Rectangle and Polygon are the objects.
PROGRAM DEVELOPMENT
When we want to develop a program using any programming
language, we follow a sequence of steps. These steps are
called phases in program development.

The program development life cycle is a set of steps or


phases that are used to develop a program in any
programming language.
1. Requirement Analysis
2. System Design
3. Coding or Writing The Program
4. Testing and Debugging
5. Documentation and Maintenance
• Requirement is a description of what a system should do.

• It involves the collection of information and the definition of the


characteristics or features of the desired system.
• Problem Analysis requires performing the following steps:
• Define the problem and the users.
• Determine the desired outputs.
• Determine the input to achieve the desired outputs.
• Determine the processes involve.
• Check the feasibility of implementing the program.
• Document the analysis.
• The program design process describes the algorithm for the
solution of the problem.
• An algorithm is the step-by-step sequence of instructions that
describe how data will be processed to produce the desired
output.
• To formulate the algorithm, a programmer may choose between
pseudocodes or flowcharts.
• Pseudocode is an algorithm written in normal Human language
statements to describe the logic and processing flow.
Example:
If the list of payroll tasks(algorithm) looks The pseudocode would look like this:
like this: READ name, hourly rate, hours worked,
• Get the employee name, hourly rate, deductions
hours worked, deductions CALCULATE: Gross pay = hourly rate times
• Calculate the gross pay and net pay hours worked
• Write name, gross pay and net pay CALCULATE: Net pay = Gross minus
deductions
WRITE name, Gross pay, Net pay
• Flowchart is a visual Example:
representation of the sequence
of steps and decisions needed
to perform a process.
• Each step in the sequence is
noted within a diagram shape.
• Steps are linked by connecting
lines and directional arrows.
• The actual writing of the program based on the design
specifications (coding).
• Construction requires performing the following steps:
• Select the appropriate programming language.
• Follow the syntax.
Program testing involves running various tests, such as desk
checking and debugging – called alpha testing, and then
running actual or real data to make sure the program works.

Testing and debugging requires the following steps:


1. Perform desk-checking
2. Debug the program
3. Run real data

Beta Testing is performed by real users of the software application


in a real environment.
1. Desk checking is manually testing the solution design to
make sure that it is free of errors and that the logic works.
2. Debugging means detecting, locating, and removing all errors
in a computer program.
Types of Errors
• Syntax Error is the most common error and incorrect use of
programming language statements.
• Run-time Error is a software error that occurs while a program is
being executed.
• Logical Error is a mistake in a program's source code that results in
incorrect or unexpected behavior.
3. Run real data
When the program is finalized, its documentation is prepared.
• Documentation is a written detailed description of the
programming cycle and specific facts about the program.
Also, it includes necessary instructions on the use and
maintenance of the program/software (product).
• Maintenance is any activity designed to keep programs
error-free, up-to-date and in good working condition.
• Cadenhead, R et. Al. (2016). C++ in 24 Hours, Sams Teach Yourself (6th
Edition). Sams Publishing
• McGrath, M. (2017). C++ programming in easy steps (5th ed.).
Warwickshire, United Kingdom: Easy Steps Limited
• Tale, T. (2016). C++: The Ultimate Beginners Guide to C++ Programing.
CreateSpace Independent Publishing Platform
• Cadenhead, R et. Al. (2016). C++ in 24 Hours, Sams Teach Yourself (6th
Edition).Sams Publishing
• McGrath, M. (2017). C++ Programming in Easy Steps (5th ed.).
Warwickshire, United Kingdom: Easy Steps Limited
• Deitel (2017), How to Program C++, 10th Edition

You might also like