Programming Part 1
Programming Part 1
Day: SAT
Time: 11:00-2:00
Instructor: Percival A. Fernandez, MSIT
OBJECTIVES:
❖To help students achieve a reasonable level of competence in
both problem solving and writing computer programs using C++
programming language.
❖To encourage students to appreciate the value of adopting good
programming style and taking a structured modular approach to
the design of programs.
WHAT IS A COMPUTER?
WHAT IS A COMPUTER?
▪ It is an electronic device capable of performing complex
computations in a short time.
▪ It is a fast, electronic calculating machine that accepts
input information, processes it according to a list of
internally stored instructions called a program, and
produces the resultant output information.
COMPONENTS OF A COMPUTER:
HARDWARE
▪ The physical equipment of a computer system, including
the monitor, keyboard, central processing unit and
storage devices.
SOFTWARE
▪ Refers to one or more computer programs and data
held in the storage of a computer for some purpose.
WHAT IS A PROGRAM?
WHAT IS A PROGRAM?
▪ is a set of instructions telling a computer what to do or
how to behave.
• The term program refers to a set of instructions that
instructs a computer on what to do. Programs are Solutions
to Problems and they are written using programming
languages.
WHAT IS A PROGRAM?
• A program can instruct a computer to:
–Read/ accept Input data
–Calculate or compare
–Store data
–Write or display Output and communication messages.
The term software refers to a computer program or set of
programs and its associated documentation such as user
guide, technical manual
WHAT IS PROGRAMMING?
WHAT IS PROGRAMMING?
▪ is the craft of implementing one or more interrelated
abstract algorithms using a particular programming
language to produce a concrete computer program.
▪ This refers to the process of writing computer programs
using a programming language.
▪ The person who write such instructions is a programmer.
WHAT IS A
PROGRAMMING LANGUAGE?
WHAT IS PROGRAMMING LANGUAGE?
• Each natural language has a systematic method of using
symbols of a language. This is dictated by rules of
grammar – semantic (structure)and syntax (words and
symbols)
• Similarly, computer programming languages are
governed by the structure and syntax.
WHAT IS PROGRAMMING LANGUAGE?
• In natural languages one can break the syntax rule such
but we can use inference (guesswork) to get what the
person means.
• However, computer being a machine are receptive to only
the exact syntax rules of the language being used.
TYPES OF PROGRAMMING LANGUAGE:
Programming languages can be classified into two broad
categories namely:
Low level languages further classified into two generations
namely:
• First Generation- Machine languages
• Second Generation -Assembly languages
TYPES OF PROGRAMMING LANGUAGE:
High-level languages further classified into three
generations namely:
– Third Generation- Procedural languages
– Fourth Generation - Problem-oriented languages
– Fifth Generation - Natural languages
LOW LEVEL LANGUAGE:
MACHINE LANGUAGES (1GL)
• This is the oldest form of computer programming. Plug boards
were used to represent data in binary (machine) form in the
computer circuitry. Data represented in 1s and 0s are said to be
written in machine language. For example, the code below
represent a segment of a machine code:
• 1011010100
• 1010111101
• 1000100100
• Machine language also varies according to make of computer –
another characteristic that make them hard to work with.
LOW LEVEL LANGUAGE:
ASSEMBLY LANGUAGES (2GL)
- use mnemonics such as ADD that are automatically
converted to the appropriate sequence of 1s and 0s by a
translator called assembler. Compared to machine
languages, assembly languages are much easier for humans
to understand and to use. The machine language code we
gave above could be expressed in assembly languages as:
• ADD 210(8,13),02B(4,7)
• PACK 218(8,13),02F(4,7)
• MP 212(6,13),21D(3,13)
ADVANTAGES OF LOW LEVEL
LANGUAGE:
• They are executed very fast since no translator or minimum
translation is involved.
10010101001010001010100
Object Code 10101010100011101111011
(machine language)) 10110111100011100101011
PROGRAM-ORIENTED LANGUAGE:
• Unlike general purpose languages, problem-oriented
languages are designed to solve specific problems. While
3rd GLs focus on procedures and how a program will
accomplish a specific task, 4th GLs are non-procedural
and focus on specifying what the program is to
accomplish.
• 4th GLs are more English-like, easier to program, and
widely used by non-programmers . Some of these 4thGLs,
are used for very specific applications. 4th GLs includes
query languages e.g. SQL and application generators eg
Visual Basic
NATURAL PROGRAMMING LANGUAGES (5 GL) :
• The standard definition of a 5th GL is a computer
language that incorporates the concepts of artificial
intelligence to allow direct human communication.
Examples are PROLOG, LISP etc.
• Additionally, these languages would enable a computer
to run and to apply new information as people do.
ADVANTAGES OF HIGH LEVEL LANGUAGES:
• English-like phrasing of high level languages makes them
easy to understand.
• High level languages are portable i.e They are
transferable from one computer to another.
• They are user-friendly and easy to use and learn.
• They are more flexible, hence they enhance creativity of
the programmer and increase productivity in the work
place.
• High level languages are far much more easy to debug.
DISADVANTAGES OF HIGH LEVEL LANGUAGES:
• Their nature encourages loading of instructions in a word
or statement hence the complexity of these instructions
cause slower program processing.
• They have to be interpreted or compiled for translation to
machine language before the computer can trace them.
PROGRAMMING FUNDAMENTALS :
Only about 100 instructions that the computer
understands - Different programs will just use these
instructions in different orders and combinations.
The most valuable part of learning to program is
learning how to think about arranging the sequence of
instructions to solve the problem or carry out the task
PROGRAMMING FUNDAMENTALS:
PUTTING THE INSTRUCTIONS TOGETHER
• Sequential Processing
• A List of Instructions
• Conditional Execution
• Ifs
• Repetition
• Looping / Repeating
• Stepwise Refinement / Top-Down Design
• Breaking Things into Smaller Pieces
• Calling Methods / Functions / Procedures / Subroutines
• Calling a segment of code located elsewhere
• Reuse of previously coded code segment
METHODS OF PROGRAMMING:
• Procedural
• Defining set of steps to transform inputs into outputs
• Translating steps into code
• Constructed as a set of procedures
• Each procedure is a set of instructions
METHODS OF PROGRAMMING:
• Object-Oriented
• Defining/utilizing objects to represent real-world
entities that work together to solve problem
• Basic O-O Programming Components
• Class
• Object/Instance
• Properties
• Methods
PROBLEM SOLVING:
The process of defining a problem, searching for relevant
information and resources about the problem, and of
discovering, designing, and evaluating the solutions for
further opportunities. Includes:
▪ Finding an Answer to a Question
▪ Figuring out how to Perform a Task
▪ Figure out how to Make Things Work
PROBLEM SOLVING:
Not enough to know a particular programming
language… Must be able to problem solve…
Very desirable to be a good Problem Solver in any CIS
discipline.
POLYA’S 4 STEPS OF PROBLEM SOLVING:
• U – Understand the Problem
• D – Devise a Good Plan to Solve
• I – Implement the Plan
• E – Evaluate the Solution
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.
DEVISE A PLAN :
• Find connections between the knowns and unknowns.
• Simplify: Break the problem into smaller sub-problems
• Design a solution
• Make a plan or list of actions to implement the solution
• Algorithm / Flowchart / Psuedocode
DEVISE A PLAN :
• 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
DEVISE A PLAN :
• Pseudocode
• Written like program code but more “English Like” and
doesn’t have to conform to language syntax
• Flowchart
• Diagram that visually represents the steps to be
performed to arrive at solution.
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
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?
REFERENCES:
• Introduction to Programming - Mr. G. Mariga
• Computer Programming 1 -
https://www.scribd.com/document_downloads/direct/378715003?extension=p
ptx&ft=1599234095<=1599237705&user_id=389262235&uahk=HRswl7
YFfm7Ly4PjhbrD8X5B8fU
• Introduction to Programming - Debra Chapman
• A Beginner's Introduction to Computer Programming - Francis Glassborow &
Roberta Allen