36
Prepared for: CHAPTER 1: PROGRAM DEVELOPMENT LIFE CYCLE CSC 128 Fundamentals of Computer Problem Solving

PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

Prepared for:

CHAPTER 1:PROGRAM DEVELOPMENT

LIFE CYCLE

CSC 128 – Fundamentals of Computer Problem

Solving

Page 2: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 3: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

COMPUTER SYSTEM

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

What is a Programming

Language?

Page 4: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

HOW A C++ PROGRAM IS PROCESSED

SOURCE

CODE

(.cpp)

OBJECT

CODE

(.obj)

EXCECUTABL

E FILE

(.exe)

Compiler Linker

Program is

written in

C++

MyProgram.c

ppProgram is

translated into

Machine Language

MyProgram.o

bj

Translates source

program into Machine

Language

Link the object program

with other programs from

the library

Program is combined

with programs from

library and is ready for

execution

MyProgram.e

xe

Page 5: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

PROBLEM SOLVING PROCESS

Programming:

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

What is Programming?

Page 6: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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 (C++) to prove that the

algorithm works

3. Maintain the Program

Modify the program wherever necessary

Page 7: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

PROGRAM DEVELOPEMENT LIFE CYCLE

Analysis

Design

Implementation

Testing

Maintenance

Program Development Life Cycle (PDLC):

Act as a guide for programmers when building a program

Page 8: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

PROCESSINPUT OUTPUT

Page 9: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

EXAMPLE

Analyze the following problem:

Find the summation of 2 numbers

Input Process Output

1st number

2nd number

sum = 1st number + 2nd

number

“The sum of 2 numbers

is”

sum

Use an IPO table for Problem

Analysis

132

Page 10: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Analyze the following problem:

The program should print out your name and the

phrase “C++ is my favourite subject!”

Page 11: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Analyze the following problem:

Find the total of days within the month of June,

July and December.

Page 12: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Analyze the following problem:

Find the perimeter of a rectangle

Page 13: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

PROGRAM DEVELOPMENT LIFE CYCLE

2. Algorithm Design:

Algorithm:

Is a set of sequential instructions that are followed to solve a

problem

What is an ALGORITHM?

Page 14: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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)

Page 15: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

2. Flowchart:

In a graphical form

These algorithm design is more

precise because:

Uses limited vocabulary

Make use of variables

Page 16: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 17: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

JohorEXAMPLE

Design a pseudocode for the following problem:

Find the summation of 2 numbers

1. Start

2. Display “Enter the 1st number”

3. Read num1

4. Display “Enter the 2nd number”

5. Read num2

6. sum = num1+ num2

7. Display “The sum of 2 numbers is” and sum

8. End

INPUT

PROCESS

OUTPU

T

Page 18: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 19: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Design a pseudocode for the following problem:

The program should print out your name and the

phrase “C++ is my favourite subject!”

Page 20: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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.

Page 21: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Design a pseudocode for the following problem:

The program should find the perimeter of a

rectangle

Page 22: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 23: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 24: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

Symbols Use of Symbols

Start / End

Input / Output

Process

Decision

Connector

Flow Line

PROGRAM DEVELOPMENT LIFE CYCLE

Flowchart Symbols:

Page 25: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

EXAMPLE

Design a flowchart for the following

problem:

Find the summation of 2 numbers

Start

Read num1,

num2

sum = num1 +

num2

Display “The sum of 2 numbers is”

, sum

A

A

End

Page 26: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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”.

Page 27: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Design a flowchart for the following problem:

Find the average of 5 numbers.

Page 28: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 29: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

QUICK EXERCISE

Design a flowchart for the following problem:

Find the largest of 3 numbers.

Page 30: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 31: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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: ";cin >> num2;

sum = num1 + num2;

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

return 0;}

INPUT

PROCE

SSOUTPU

T

Page 32: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 33: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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

Page 34: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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).

Page 35: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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 form executing?

4. What type of error would be identified by the compiler?

Page 36: PROGRAM DEVELOPMENT LIFE CYCLE - WordPress.com · Flowchart: Is an algorithm in graphical form which is made up of symbols The flow of algorithm should be written in sequence with:

© Najwa Abd Ghafar – UiTM

Johor

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