Docsity

C Programming: Algorithms & Software Development with Waterfall Model, Lecture notes of Programming Methodologies

Partial preview of the text

Download C Programming: Algorithms & Software Development with Waterfall Model and more Lecture notes Programming Methodologies in PDF only on Docsity!

Chapter 1

Designing and Structuring

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

Designing and Structuring

Programs

-^

learn the software development method.

-^

learn and understand the concept of algorithms

-^

Objectiveslearn to design and represent algorithms usingpseudocode and flowcharts

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

Learning Outcomes

-^

able to develop a software based on a systematicprocedure.

-^

able to formulate algorithms in solving a given problem.

-^

able to implement algorithms using flowchart andpseudocode.

The Waterfall Model

-^

It is a systematic and effective method of developing aprogram

-^

Each phase is seen to occur sequentially

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

The Waterfall Model

-^

Requirements^ – All possible requirements of the system to be developed (i.e., the

expected functionalities and constraints) are clearly defined

  • The validity of these requirements and the feasibility of

implementing them in the system are also investigated

-^

Analysis

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

-^

Analysis^ – It involves identifying the inputs to the problem, the expected

outputs and any special conditions or constraints imposed

  • Then, a relationship between the input and output data is

established

  • For computing problems, appropriate formulae might be used to

relate the input and output data

The Waterfall Model

-^

Design^ – The specifications of the software are translated into the software

representation

  • It involves identifying suitable data structures and algorithms to be

used, identifying modules and interfaces between modules

-^

Design tools:

pseudocode,

flowchart

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

–^

Design tools:

pseudocode,

flowchart

  • Top-down design
    • Divides the problem into several simpler sub-problems, solves

each one of them separately, and then combines them

  • Many programs could be divided logically into three main parts,

i.e.,

  • Initialization: Initialize the variables used in the program– Processing: Input data, perform the calculation– Termination: Display the result

The Waterfall Model

-^

Coding^ – The implementation of the designed algorithm in a programming

language

  • If the detailed design is good, the transition from the design to real

code should be smooth

-^

Each line of

pseudocode

or each block of a flowchart should be

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

–^

Each line of

pseudocode

or each block of a flowchart should be

translated into one or few lines of real code

-^

Testing^ – To discover bugs or defects of the software, and do the necessary

corrections to eliminate these errors

  • Different sets of test data should be provided for testing

Algorithms

-^

An algorithm is a procedure to accomplish a specific task^ – A set of well-defined instructions is specified in the order in which

these instructions should be performed

-^

Example: Convert a temperature in degrees Fahrenheit todegrees Celsius

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

  • Initialization: No variables need to be initialized in this case– Processing:
    • Get the temperature in degrees Fahrenheit• Convert the temperature to degrees Celsius using the formula,

Temperature in Celsius

Temperature in Fahrenheit

  • Termination: Display the temperature in degrees Celsius

Algorithms

-^

Sequential execution^ – Instructions executed one after another in the sequence in which

they are written

-^

Transfer the control^ – When the next instruction executed is not the next one in sequence

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

Pseudocode

-^

It is one of the most commonly used design tools fordeveloping algorithms

-^

It is an imitation of the actual computer instructions

-^

It is not actually executed on computers

-^

It consists of actions statements

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

-^

It consists of actions statements^ – input or output operations, assignment statements, calculations

and data manipulations, function calls, etc

Flowcharts

-^

A flowchart is a graphical representation of an algorithm

-^

Each steps of an algorithm are illustrated as boxes ofvarious special-purpose symbols connected by arrows^ – The order in which actions are to be performed is indicated by the

arrows

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

Examples of Algorithm Designs

-^

Design an algorithm that inputs 2 numbers and displaysthe numbers in ascending order^ – Flowchart

  • Pseudocode

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

Prompt user for two numbersInput a and b from userIf a is smaller than b

Print a and b Otherwise

Print b and a

Examples of Algorithm Designs

-^

Design an algorithm that prints the first 3 integers^ – Flowchart

  • Pseudocode Set count to 1

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

While count is less than or equal to 3

Print count

Applying Software Development Method

(2/5)

-^

Design (Top-down design)^ – First refinement: Divide problem into smaller tasks and list them in

order

  • Initialization:

Initialize variables

  • Processing:

Input data from user, determine and sum all odd

integers

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

integers

  • Termination:

Display the result

  • Second refinement: Commit to specific variables
    • Refine the initialization phase from

Initialize variables

to

  • Initialize sum to 0

-^

Design (Top-down design) (cont.)^ – Second refinement: Commit to specific variables (cont.)

  • Refine the processing phase from

Input data from user,

determine and sum all odd integers

to

  • Input integer –^

While integer is not

1

Applying Software Development Method

(3/5)

Powerpoint slides to be used with “C Programming for Beginners” by HC Ling, SN Cheong, YK Teh,LC Kwek, Emerson, Vishnu Monn B and Badrolhisham (Pearson Education, 2010)

-^

While integer is not

1

» If the remainder of dividing integer by 2 is 1

sum = sum + integer

» Input integer

  • Refine the termination phase from

Display the result

to

  • Display sum