0% found this document useful (0 votes)
17 views

Topic2 Program Development Life Cycle

notes

Uploaded by

elnini8412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Topic2 Program Development Life Cycle

notes

Uploaded by

elnini8412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

CHAPTER 2:

PROGRAM DEVELOPMENT
LIFE CYCLE

Prepared for:
CSC 402 – Programming I

© Najwa Abd Ghafar – UiTM Johor


© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

OBJECTIVES OF THIS CHAPTER

In this chapter, you will learn about:


 The steps to do programming
 How to develop an algorithm
 How to write simple computer program in C++
 Syntax and logic error
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

COMPUTER SYSTEM

What is a Programming
Language?

Programming Language:
 Is used by programmers to write computer programs
 It is used to write instructions written by programmer in order to
tell the computer what to do
 Most people refer programming language to high level language
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

HOW A C++ PROGRAM IS PROCESSED

MyProgram.exe
MyProgram.cpp MyProgram.obj
Program is combined with
Program is Program is translated programs from library and is
written in C++ into Machine Language ready for execution

SOURCE CODE OBJECT CODE EXCECUTABLE FILE


(.cpp) (.obj) (.exe)

Compiler Linker
Translates source program Link the object program with other
into Machine Language programs from the library
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROBLEM SOLVING PROCESS

What is Computer
Programming?

Programming:
 Is a process of designing and building and executable computer program
for accomplishing a specific task
 Is a process of PROBLEM SOLVING
 Before you can write your codes inside the computer,
you NEED TO KNOW HOW TO SOLVE the problem first
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROBLEM SOLVING PROCESS

To solve a problem, you should follow the steps below:


1. Analyze the Problem
 Start by outlining the problem
 Design an algorithm
2. Implement the Algorithm
 Use a programming language to prove that the algorithm works
3. Maintain the Program
 Modify the program wherever necessary
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPEMENT LIFE CYCLE


Program Development Life Cycle (PDLC):
 Act as a guide for programmers when building a program

Analysis

Maintenance Design

Testing Implementation
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

1. Problem Analysis:
 When analyzing a problem, you need to determine:
1. Input:
What kind of data do you need from the user
2. Process:
What do you need to do get your output
3. Output:
What do you want to display to the user

INPUT PROCESS OUTPUT


© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

EXAMPLE

Analyze the following problem:


Find the summation of 2 numbers

Use an IPO table for Problem Analysis

2 3 1
Input Process Output
 1st number sum = 1st number + 2nd number  “The sum of 2 numbers is”,
 2nd number sum
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Analyze the following problem:


The program should print out your name and the phrase
“C++ is my favourite subject!”
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Analyze the following problem:


Find the total of days within the month of June, July and
December.
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Analyze the following problem:


Find the perimeter of a rectangle
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

2. Algorithm Design:

What is an ALGORITHM?

Algorithm:
 Is a set of sequential instructions that are followed to solve a problem
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

Algorithm for finding the summation of 2 numbers


(BEFORE refinement as pseudocode):

1. Read 2 numbers
2. The summation of 2 numbers is calculated by adding up the 1st number and the
2nd number
3. Display the summation of 2 numbers that was calculated

Basically, algorithm is a STEP-BY-STEP instructions on how to solve a problem

HOWEVER, when human language is used,


the meaning of the sentence can be imprecise at times
(what is written might be different than how it is read)
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

2. Algorithm Design:
 Therefore in order to make an algorithm more precise,
there are 2 ways an algorithm can be designed:

1. Pseudocode:
In written form These algorithm design is more precise
because:
2. Flowchart:
 Uses limited vocabulary
In a graphical form
 Make use of variables
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

2. Algorithm Design:
 Pseudocode:
 Is an algorithm in written form (text-based) by using a human
language
 The flow of algorithm should be written in sequence with:
 A start
 An end
 TIP:
The flow of your pseudocode can clearly be seen when you do
numbering for each step
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PSEUDOCODE

 Uses short English statements to show the steps the


computer must take to accomplish the program’s
goal.
 Consists of natural language-like statements that
precisely describe the steps of an algorithm or
program
 Statements describe actions
 Focuses on the logic of the algorithm or program
 Avoids language-specific elements
 Written at a level so that the desired programming
code can be generated almost automatically from
each statement
 Steps are numbered. Subordinate numbers and/or
indentation are used for dependent statements in
selection and repetition structures.
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PSEUDOCODE CONSTRUCT

Computation/Assignment
Compute var1 as the sum of x and y
Assign expression to var2
Increment counter1

Input/Output
Input: Read var1, var2, …
Output: Display var1, var2, …
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PSEUDOCODE CONSTRUCT

SELECTION
1. One Way Selection
2. IF condition THEN
2.1 statement 1
2.2 etc.
2. Two Way Selection
3. IF condition THEN
3.1 statement 1
3.2 etc.
4. ELSE
4.1 statement 2
4.2 statement 3
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PSEUDOCODE CONSTRUCT

REPEATITION
1. WHILE structure
5.5. WHILE condition (while condition is true, then do
subordinate statements)
5.1 statement 1
5.2 etc.
2. DO – WHILE construct
6. DO
6.1 statement 1
6.2 etc.
7. WHILE condition
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PSEUDOCODE CONSTRUCT

REPEATITION
3. FOR structure
8. FOR bounds on repetition
8.1 statement 1
8.2 etc.
7. WHILE condition
© Najwa Abd Ghafar – UiTM Johor

EXAMPLE © Rose Hafsah Ab. Rauf – UiTM Shah Alam

Design a pseudocode for the following problem:


Find the summation of 2 numbers

1. Start
2. Display “Enter the 1st number”
3. Read num1 INPUT
4. Display “Enter the 2nd number”
5. Read num2
6. sum = num1+ num2 PROCESS
7. Display “The sum of 2 numbers is” and sum OUTPUT
8. End
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

The following pseudocode algorithm has an error. The program is supposed


to ask the user for the length and width of a rectangular room, and then
display the room’s area. The program must multiply the width by the
length in order to determine the area.
Find the error.
1. Begin
2. area = width x length
3. Read width
4. Read length
5. Display “The area of the room is” and area
6. End
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a pseudocode for the following problem:


The program should print out your name and the phrase “C++
is my favourite subject!”
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a pseudocode for the following problem:


The program should find the total of days within the month
of June, July and December.
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a pseudocode for the following problem:


The program should find the perimeter of a rectangle
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a pseudocode for the following problem:


Determine whether a person is eligible to enter the theme park
based on their age. Appropriate message should be given to that
person:

Age Description
Less than 10 Not eligible because you’re too young
Between 10 and 49 Eligible to enter
50 or more Not eligible because it might be dangerous
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

2. Algorithm Design:
 Flowchart:
 Is an algorithm in graphical form which is made up of symbols
 The flow of algorithm should be written in sequence with:
 A start
 An end
 This algorithm design allow us to see the actual “flow” of the
program
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE


Flowchart Symbols:
Symbols Use of Symbols
Start / End

Input / Output

Process

Decision

Module / Function

Connector

Flow Line
© Najwa Abd Ghafar – UiTM Johor

EXAMPLE
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

Design a flowchart for the following problem:


Find the summation of 2 numbers

Start A

Read num1, num2 Display “The sum of 2 numbers is” , sum

sum = num1 + num2 End

A
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a flowchart for the following problem:


The program should ask for the user’s age and display the
following message “This year you are ____ years old”.
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a flowchart for the following problem:


Find the average of 5 numbers.
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a flowchart for the following problem:


Determine whether a person is eligible to enter the theme park
based on their age. Appropriate message should be given to that
person:

Age Description
Less than 10 Not eligible because you’re too young
Between 10 and 49 Eligible to enter
50 or more Not eligible because it might be dangerous
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Design a flowchart for the following problem:


Find the largest of 3 numbers.
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

3. Algorithm Implementation:
 Once the algorithm is designed and has been correctly verified, the
algorithm can now be implemented
 But HOW?

This is when you do your CODING inside the computer


by FOLLOWING the algorithm that you have designed
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

EXAMPLE

The following is a program that will find the summation of 2 numbers:

#include <iostream>
using namespace std;

int main()
{
int num1, num2, sum

cout << "Enter the 1st number: ";


cin >> num1;
cout << "Enter the 2nd number: ";
INPUT
cin >> num2;

sum = num1 + num2; PROCESS

cout << "The sum of 2 numbers is : "<< sum OUTPUT


return 0;
}
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

Compiling:
 Once you have finished writing your codes, you can try and run your
program
 But WHAT DO YOU NEED to run your program?

COMPILER:
Will ensures that your program follows the constructs of the language
(a.k.a NO SYNTAX ERROR!!)

When there are no syntax error, it will then translate the program into
machine code
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

4. Program Testing:
 Your program should be tested with all types of data and cases
so that you can find and eliminate errors
 Errors is also known as bugs
 The process of removing bugs is called debugging
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

Possible Errors in a Program:


1. Syntax Error:
 Also known as compile-time error
 Occurs during compilation when you incorrectly write a command or
some other part of the program
2. Logic Error:
 Occurs when a program runs, but unexpected results are produced
 Often produced by an incorrect algorithm.
3. Runtime Error:
 Also known as execution-time error
 Occurs during execution, which results in an error message and an
abnormal end to program execution (program crash).
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

QUICK EXERCISE

Answer the following questions:


1. What type of error occurs when you misuse a C++ language, similar to
a grammatical error?
2. What type of error occurs when your code doesn’t perform the task it’s
intended to perform?
3. What type of error occurs when there is a severe logic error that
prevents your program from executing?
4. What type of error would be identified by the compiler?
© Najwa Abd Ghafar – UiTM Johor
© Rose Hafsah Ab. Rauf – UiTM Shah Alam

PROGRAM DEVELOPMENT LIFE CYCLE

5. Program Maintenance:
 Involves you modifying or upgrading the existing program or system
 It is important to document your program so that you and other
programmers can make changes or updates later
 There are 3 types of documentation:
1. Documentation in the Program:
Comments can be used to explain certain codes
2. Documentation outside the Program:
Diagrams, flowcharts or descriptions can be used to explain how
the programming problem was solved
3. Documentation for the User:
User documentation or user manual is used to explain the
functions of the program

You might also like