[go: up one dir, main page]

0% found this document useful (0 votes)
10 views33 pages

CSC126 CH1

The document provides an introduction to programming, covering key concepts such as computer programs, the Program Development Life Cycle (PDLC), and basic control structures. It explains the roles of hardware and software, detailing components like the CPU, memory, and types of software. Additionally, it outlines the steps involved in problem analysis, algorithm design, implementation, testing, and maintenance.

Uploaded by

2024223538
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views33 pages

CSC126 CH1

The document provides an introduction to programming, covering key concepts such as computer programs, the Program Development Life Cycle (PDLC), and basic control structures. It explains the roles of hardware and software, detailing components like the CPU, memory, and types of software. Additionally, it outlines the steps involved in problem analysis, algorithm design, implementation, testing, and maintenance.

Uploaded by

2024223538
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

TOPIC 1:

INTRODUCTION TO
PROGRAMMING
CSC126 | FUNDAMENTALS OF
ALGORITHMS AND COMPUTER
PROBLEM SOLVING
Topics
• Introduction to computer program
• Program Development Life Cycle (PDLC)
• Details of problem analysis
• Algorithm Design & Implementation
• Basic control structures
INTRODUCTION TO
COMPUTER
PROGRAMS
Computer Programs
• Program: A set of instructions that the computer needs to follow to
process the data into information.
• Computer program: A sequence of instructions that the computer
carries out to fulfill the task.
• Computer programmer: A person who writes a computer program.
• Computer programming: The act of designing and implementing
computer programs using the programming languages.
• Programming language: Provides a way to program a computer using
instructions that can be understood by computers and human. It has
its own vocabulary and rules of usage.
Computer Programs
Computer :
• An electronic machine, operating under the control of instruction stored
in its own memory
• Machine that obtains data as input, processes the data and produces
valuable output. Output will be stored in various storage.

Basic components of a computer systems :

•Hardware : An equipment that processes data to create info. includes input, output,
storage and processing device.

•Software (called as a program) :


•Step by step instruction that tell the computer how to do the work
•It’s purpose to convert data to useful info.
Hardware vs Software

Computer Hardware Computer Software


Input System Software
Device Application Software
CPU
Primary Storage
Output Device
Secondary
Device
Computer Hardware
Input Device
• A device that feed/enter data and program into computer.
• Eg: keyboard, mouse and secondary storage.

Central Processing Unit (CPU)


• The brain of computer and single most expensive piece of hardware.
• Its function is to carry out the instructions of computer program by performing the basic arithmetic,
logical, and input/output operations of the system.
• There are THREE (3) main component of CPU:
• Control Unit (CU): fetch and decode the instruction, control flow of data in and out of main
memory, and control the operation of CPU’s internal component
• Arithmetic Logic Unit (ALU): carries out all arithmetic and logical operations.
• Register: has special purposes, for exp:
✓ Instruction Register (IR) holds the instruction currently being executed.
✓ Program Counter (PC) points to the next instruction to be executed.
Computer Hardware
Primary storage (main memory / RAM)
• Directly connected to CPU.
• All programs must be loaded into main memory before they can be executed.
• An ordered sequence of cell (called memory cell). Each cell has a unique location in main memory
(called address), that helps stored information.

Output device
• A device that computer uses to display results.
• Eg: monitor and printer.

Secondary storage
• A device that stores information permanently.
• Eg: hard disk, floppy disk, CD-ROMs and pendrive
Computer Software
System Software
• Consists of programs that manage the hardware resources of computer and perform required info
processing tasks.
• Provides an environment for user to execute the application software (interface between the
hardware and theusers).
• Enable the application software to interact with computer hardware.
• Eg: Operating System (provides services such as a user interface, file and database access and
interfaces to communication systems).

Application Software
• End user software.
A program that performs a common task to the user.
Eg: Word, Excel.
Program Development Life
Cycle (PDLC)
5. Program
maintenanc e
1. Problem 3. Algorithm and
analysis implementation doc umentation

2. Algorithm 4. Program
design testing and
debugging
This methodology consist of steps
programmers use to build
computer programs.
Program
Development The steps:
Life Cycle • 1. Problem analysis
(PDLC) • 2. Algorithm design
• 3. Algorithm implementation
• 4. Program testing and debugging
• 5. Program maintenance and
documentation
Program Development Life Cycle
(PDLC)
Step 1: Problem Analysis
• Problem is defined to obtain a clear understanding of the
problem requirement
• Define what the job is, NOT HOW.
• What program is to accomplish:
• What is the output
• What is the input
• What formula (process(s)) is to be used?
• What other assumptions or constraints can be made?
• What is the expected output screen?
Mission…
Input Output

Process:
Example: problem that can be solved
by computer

To calculate and display age.


Step 1: Problem Analysis

To calculate and display age.

List out

Input: current year, year born


Output: age
Process/ formula: IPO chart
age = current year – year born
Input Process/ Output
formula
Step 2: Design an algorithm
Algorithm
• A set of sequential instructions that are followed to solve a problem.
• Involves decisions to change the actions or cause parts of algorithm to be repeated.
• An Algorithm can be represented by a pseudocode or flowchart.

Pseudocode
O A precise algorithmic description of a program logic.
O Expresses an algorithm in everyday English rather than programming language
O Describe instructions in your own word.

Flowchart
O A diagram to represent a flow of an algorithm.
Step 2: Design an algorithm
Flowchart
O A diagram to represent a flow of an algorithm.

Symbols Descriptions
O Basic flowchart:
Terminal symbol - indicates the beginning and
end points of an algorithm.
Input-output symbol - shows an input or an output
operation.

Process symbol - shows an instruction other than


input, output or selection.

Decision symbol - shows a selection process


for two-way selection.

On-page connector - provides continuation


of logical path at another point in the same
page.

Flow lines - indicate the logical sequence of


execution steps in the algorithm
Step 2: Design an algorithm
Algorithm

1. Get/ Input/ Enter year born and current year


2. Calculate age
age = current year – year born
3. Print/ Display age

Pseudocode

Begin
Get/ Input/ Enter year born and current year
Calculate age
age = current year – year born
Print/ Display age
End
Step 2: Design an algorithm
Flowchart

Start

Input year
born, current year

Age = current year


– year born

Print age

End
Step 3: Implementation
• The process of writing the code that translate the design
into a computer program using a programming language.
• Different languages have different syntax.
• A language syntax’s is the set of grammar and rules that
specifies how to write instructions for an algorithm.
Step 3: Implementation
• Source code/ program
Step 4: Testing and Debugging
• Program testing requires testing the completed program to
verify that it produces expected output. A different set of
testing data is normally used to verify that the program
works properly and that it is indeed solving the given
problem.
• Also involve with process of running the program and
checking for errors. This is to ensure that the programs
works like it supposed to.
• Debugging: Process of locating and correcting errors in a
program.
Step 5: Documentation & Maintenance
Documentation

• Written description of a program, what it does and how to use.


• Purpose for reference to other programmers if any maintenance to be taken.

Maintenance

• Any activities to keep the program in good working condition, error free and up-to-date.
• Involves any amendments, additional coding or repairs to the programs.
BASIC CONTROL
STRUCTURE
Program control structures
• Program control structure controls the flow of execution of
program statement. C++ provides structures that will allow
an instruction or a block of instruction to be executed,
repeated or skipped.
• There are three control structures:
• Sequential structure
• Selection structure (by making a choice, which called a branch).
• Repetition structure (by executing a statement over and over using
a structure called a loop or by calling a function).
Sequential Structure
• The simplest of all the structures
• The program instruction has one starting point and one
ending point.
• Each step is carried out in order of their position and is
only done once.
Selection Control
Structure
• The selection structure allows comparison of
expression, and based on the comparison, to select
certain course of action
Selection Control Structure
• Example:

F Telephone T
rings?

Continue reading Answer phone


Repetition Control Structure
• The repetition structure allow a sequence of instructions to
be executed repeatedly until a certain condition is achieved.
Repetition Control Structure

false beg
has
items?
true

Take item out

You might also like