You are on page 1of 43

CHAPTER 1

INTRODUCTION TO
COMPUTER PROGRAMMING
PROF. DARWIN C. LLAVORE, MIT
CSCC 102- Fundamentals of Programming/
Computer Programming 1
TOPIC OUTLINE
❑Basic Terminologies
❑Overview of Computer Programming
❑History of Programming and C Programming
Language
What is a computer?

■ Electronic device capable of


storing, processing and
retrieving data.
■ A machine that performs a
variety of tasks according to
specific instruction
■ A machine that performs
tasks, such as calculations or
electronic communication,
under the control of a set of
instructions called a program.
What is a Hardware and Software?

■ Hardware – It refers to the ■ Software –It is a collection of


physical components of a programs, data, and instructions
computer or any electronic that are intangible. It consists of
device. These are tangible, lines of code and instructions that
tell the hardware what to do.
mechanical, and electronic parts Software can be stored
that you can touch and see, electronically and is not
such as the CPU (Central something you can physically
Processing Unit), memory touch.
modules, storage devices,
input/output devices (keyboard,
mouse, monitor), and
motherboard.
What is a Hardware and Software?

■ Hardware – It performs the ■ Software –It provides the


physical operations and instructions that guide the
computations of a computer hardware's behavior. It controls how
system. It processes data, stores data is processed, manages
information, and interacts with the hardware resources, and allows
user through input and output users to interact with the computer
devices. It's responsible for the system. Software tells the hardware
execution of software instructions. what tasks to perform.
What is a Hardware and Software?

■ Hardware – Examples of hardware ■ Software –Examples of software


components include the computer's include the operating system (e.g.,
CPU, RAM, hard drive, graphics Windows, macOS, Linux), word
card, keyboard, and monitor. processing programs (e.g.,
Microsoft Word), web browsers (e.g.,
Google Chrome), and video games.
What is a computer program?

■ Set of instructions and commands for the computer to execute.


■ Set of instructions that directs a computer to perform some
processing function or combination of functions.
Who is a computer programmer?

■ A person who writes programs


in various programming
languages, some directly
understandable by computers
and others requiring
intermediate translation steps.
■ Computer programmers use
programming languages to
write, test, and maintain code.
What is a programming language?

■ a standardized communication technique for expressing instructions


to a computer
■ Like human languages, each language has its own syntax and
grammar
■ There are different types of programming languages that can be used
to create programs, but regardless of what language you use, these
instructions are translated into machine language that can be
understood by computers.
Sample Programming Languages
Categories of Programming Languages

■ High-level Programming Languages


– a programming language that is more user-friendly, to
some extent platform-independent, and abstract from
low-level computer processor operations such as
memory accesses
– A programming statement may be translated into one or
several machine instructions by a compiler.
Examples: Java, C, C++, Basic, Fortran
Sample program written in HL Language
List of High-level Languages
Programming
Description
Language
Fortran FORmula TRANslator was developed by IBM Corporation in the mid-1950s to
be used for scientific and engineering applications that require complex
mathematical computations.
COBOL COmmon Business Oriented Language was developed in the late 1950s by
computer manufacturers, the U.S. government and industrial computer users
based on a language developed by Grace Hopper, a career U.S. Navy officer
and computer scientist. COBOL is still widely used for commercial applications
that require precise and efficient manipulation of large amounts of data. Its
latest version supports object-oriented programming.
Pascal It was designed for teaching structured programming and was popular in
college courses for several decades.
Basic Basic was developed in the 1960s at Dartmouth College to introduce novices
to programming.
High-level Programming Languages
Programming
Description
Language
C C was implemented in 1972 by Dennis Ritchie at Bell Laboratories.
It initially became widely known as the UNIX operating system’s
development language. Today, most of the code for general-purpose
operating systems is written in C or C++.
C++ C++, an extension of C, was developed by Bjarne Stroustrup in the
early 1980s at Bell Laboratories. C++ provides a number of
features that “spruce up” the C language, but more important, it
provides capabilities for object-oriented programming.
Visual Basic Microsoft’s Visual Basic language was introduced in the early
1990s to simplify the development of Microsoft Windows
applications.
High-level Programming Languages
Programming
Description
Language
PHP An “open-source” scripting language supported by a
community of users and developers and is used by numerous
websites including Wikipedia and Facebook.
Java Sun Microsystems in 1991 funded an internal corporate
research project led by James Gosling, which resulted in a
C++-based object-oriented programming language that Sun
called Java.
Categories of Programming Languages

■ Low-level Programming Languages


– Assembly languages are similar to machine languages,
but they are much easier to program because they allow
a programmer to substitute names for numbers
– Assembly languages are available for each CPU family,
and each assembly instruction is translated into one
machine instruction by an assembler program
Sample Assembly Language
Sample Machine Language
What is Computer Programming?

■ It is the process of designing and building an executable


computer program for accomplishing a specific computing
task.
■ It involves expressing the problem at hand in a language
that the computer can understand.
■ It is a problem solving activity.
PROGRAM DEVELOPMENT LIFE CYCLE

■ Basic steps in to solve a machine problem:


1. Problem Definition
2. Problem Analysis
3. Algorithm design and representation
(Pseudocode or flowchart)
4. Coding and debugging
PROGRAM DEVELOPMENT LIFE CYCLE
1. Problem Definition
■ A clearly defined problem is already half the solution.
■ Computer programming requires us to define the problem
first before we even try to create a solution.

Let us now define our example problem:


“Create a program that will determine the highest value from the two numbers
entered by the user.”
PROGRAM DEVELOPMENT LIFE CYCLE
2. Problem Analysis
■ After the problem has been adequately defined, the simplest and yet the most
efficient and effective approach to solve the problem must be formulated.
■ Usually, this step involves breaking up the problem into smaller and simpler
sub problems.
Problem:
“Create a program that will determine the highest value from the two numbers entered by the user.”
ANALYSIS: Identify the IOP(Input-Output-Process) components of the problem.
■ INPUT to the program:
– Two numbers (let’s call it num1 and num2)
■ OUTPUT of the program:
– Display the highest entered number or give a message that the numbers are equal.
PROGRAM DEVELOPMENT LIFE CYCLE
3. Algorithm and Design Representation
■ Algorithm
– a clear and unambiguous specification of the steps needed to
solve a problem.
■ It may be expressed in either :
– Human language (English, Tagalog)
– Graphical representation like a flowchart
– Pseudocode - which is a cross between human language and a
programming language
3. Algorithm and Design Representation
Start
Get first number, call it as variable num1
Get the second number, call it as variable num2
if num1 is greater than num2
display num1
else if num2 is greater than num1
display num2
else
display the text “num1 and num2 are equal”
End
3. Algorithm and Design Representation
Problem: Create a program that accepts two
numbers and displays the product.

Start
Input first number, call it variable n1.
Input second number, call it variable n2.
Multiply n1 and n2, name it as product
Output product
End
3. Algorithm and Design Representation
Problem: Create a program that computes for the
area of the rectangle and displays the result.

Start
Input length of rectangle, call it variable l.
Input width of rectangle, call it variable w.
Multiply l and w, name it as variable area.
Display area.
End
3. Algorithm Design and Representation
Flowchart. A design tool to graphically represent
the logic in a solution.

Symbol Name Meaning

Also known as an “Action


Process Symbol,” this shape
Symbol represents a process, action,
or function. It’s the most
widely-used symbol in
flowcharting.
Symbol Name Meaning
Algorithm Design and Representation
Data/Input/ Represents an I/O function, which makes
data available for processing (input) or
Output Symbol displaying (output) of processed information
Input – data to be entered into the computer
Output – information that is displayed on the
computer screen
This shows the direction of the flowchart.

Flowlines
Symbol
A diamond shaped symbol used to indicate
decisions. Done in question form and is
Decision Symbol answerable by yes or no. Uses logical
relations such as equal (=), not equal (!), >, <,
>= and <=.
3. Algorithm and Design Representation
Symbol Name Meaning
Preparation This symbol is used to
Symbol initialize the value/s of the
variable/s to be used.

Usually used within more


On-Page complex charts, this symbol
A
connects separate elements
Connector Symbol
across one page.
Off-Page This symbol connects separate
A elements across separate pages.
Connector
Begin

Input num1

Input num2

yes num1 no num2 yes


> > Display num2
num2 num1

no
Display num1
Display num1 and
num2 are equal

End
Your turn…
Create the algorithm for the following problem.
■ Compute for the area of the rectangle and displays the result.
■ Convert the entered meter to kilometer.
■ Convert the entered Celsius to Fahrenheit.
PROGRAM DEVELOPMENT LIFE CYCLE
4. Coding and Debugging
❑ Coding is the act of writing or creating the source
code based from the algorithm design and
representation using the chosen programming
language.
Problem: “Create a
program that will
determine the
highest value from
the two numbers
entered by the user.”
Problem: Create a program that accepts two numbers and displays the
product.
Problem: Create a program that computes for the area of the rectangle and
displays the result.
Problem: Create a program that computes for the area of a circle and displays
the result.
PROGRAM DEVELOPMENT CYCLE
4. Coding and Debugging
❑ Debugging is the process of fixing errors/bugs in
the program.
PROGRAM DEVELOPMENT CYCLE
4. Coding and Debugging
❑ Two Types of Errors
1. Syntax Error
➢ It is checked during compile-time.
➢ Violation of the rules on how we write statements in a
particular programming.
➢ Ex. Misspelled keywords, use of incorrect symbols or
character, omission of symbols etc.
PROGRAM DEVELOPMENT CYCLE
4. Coding and Debugging
❑ Two Types of Errors
2. Logic Error
➢ It is checked during execution-time.
➢ A bug in a program that causes it to operate incorrectly, but
not to terminate abnormally (or crash). It produces an
incorrect result or output.
Example Output: Enter a number: 3
The cube of 3 is 45. Incorrect result!
End of Lecture

■ Darwin C. Llavore
■ Email: dllavore@dmmmsu.edu.ph

You might also like