You are on page 1of 42

DCP5026 Program Design

Topic 1 : Software Development and Programming


Environment
Learning outcomes
◼ After completing this module, students should be able to
◼ explain the six steps involved in the software development process.
◼ apply design tools such as flowchart and pseudocode in developing an
algorithm.
◼ explain the six phases in developing a C program.

2
Introduction
◼ Computer science
◼ A field of study that deals fundamentally with problem solving using
computers
◼ The programming language that you will study is C
◼ C is a is powerful, rich, versatile and exciting programming language

3
Computer software
◼ Sets of instructions that tell the computer what to do.
◼ 2 categories:
◼ System software - enables application software to interact with the
computer.
◼ Application software - helps end-users perform general purpose tasks.

4
System software
◼ Software that controls everything that happens in a computer.
◼ Examples of system software
◼ Operating system
◼ Software written into memory upon start-up of a computer.
◼ Example: Windows, MS-DOS, Unix, etc.
◼ Utility programs
◼ Software that perform the basic operation necessary for the fundamental
performance of the computer system.
◼ Example: Text editor, Anti-virus, etc.

5
Application software
◼ Examples of application software
◼ Office suite
◼ Word processing, Desktop publishing, Presentation program, Database
management system, Scheduling and time management, Spreadsheet,
Accounting software.
◼ Internet Access:
◼ Browser, Email client, Web server, Mail transfer agent, Instant messaging.
◼ Design and manufacturing:
◼ Computer-aided design, Computer-aided manufacturing, Plant management,
Robotic manufacturing, Supply chain management.
◼ Graphics:
◼ Raster graphics editor, Vector graphics editor, 3D modeler, Animation editor,
3D computer graphics, Video editing, Image processing.

6
Application software (cont.)
◼ Examples of application software (cont.)
◼ Audio:
◼ Digital audio editor, Audio playback, Mixing, Audio synthesis, Computer
music
◼ Software engineering:
◼ Compiler, Assembler, Interpreter, Debugger, Text editor, Integrated
development environment, Software performance analysis.
◼ Games:
◼ Strategy, Arcade, Puzzle, Simulation, First-person shooter, Platform,
Massively multiplayer, Interactive fiction
◼ Programs written by you

7
Programming languages
◼ A programming language is an artificial and formal language
that has a limited vocabulary consisting of a set of keywords for
making up instructions and a set of precise grammar rules.
◼ 3 types of programming languages:
◼ Machine language
◼ Assembly language
◼ High-Level language

8
Programming languages (cont.)
◼ Machine language
◼ “Natural language” of computer.
◼ The only language computer can directly understand, other languages
are finally converted to this language.
◼ It consists of strings of 0s and 1s to form specific machine codes or
instructions, i.e., 00000110 00001000.
◼ Disadvantages
◼ Tedious for humans
◼ Difficult for programming, debugging, and modifications
◼ Machine-dependent (not portable)

9
Programming languages (cont.)
◼ Assembly language
◼ Using mnemonic codes (English-like abbreviations), eg.,
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
◼ Must be translated to machine codes by assemblers.
◼ Examples of assembly language: ARM, MIPS and x86.
◼ Advantages
◼ Less tedious to humans
◼ Easier for programming, debugging, and modifications
◼ Disadvantages
◼ Requires many statements/instructions to accomplish substantial tasks
◼ Machine-dependent (not portable)

10
Programming languages (cont.)
◼ High level language
◼ Similar to everyday English, use common mathematical notations, eg.,
grossPay = basePay + overTimePay
◼ To be translated to machine codes by compilers or interpreters.
◼ Examples of high level programming language: FORTRAN, BASIC, COBOL,
PASCAL, C, C++, JAVA, MATLAB, etc.
◼ Advantages
◼ Single statement to accomplish substantial tasks
◼ Machine-independent (portable)

11
C programming language
◼ Brief history of C
◼ Evolved from two programming languages: BCPL & B.
◼ Invented by Dennis Ritchie at the Bell Laboratories in 1972.
◼ Added data typing, other features
◼ Development language of UNIX.
◼ C programs are portable, i.e., hardware independent.
◼ The American National Standards Institute (ANSI) formed a
committee to establish a standard definition of C, which
became known as ANSI Standard C.
◼ Every modern C compiler has the ability to adhere to this standard.

12
Software engineering
◼ It is the application of engineering to development of software
in a systematic method.
◼ One of the most commonly used model of software
engineering process is called the classical Waterfall model.

13
The Waterfall model

◼ A sequential software development model in which


development is seen as flowing steadily downwards.
Requirement

Analysis

Design

Coding

Testing

Maintenance

14
The Waterfall model (cont.)

1. 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.
2. 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.

15
The Waterfall model (cont.)

2. Analysis (cont.)
◼ Example: Convert a temperature in degrees Fahrenheit to degrees
Celsius
◼ Input to the problem:
Temperature in degrees Fahrenheit
◼ Expected output:
Temperature in degrees Celsius
◼ Formula for the conversion:
Temperature in degrees Celsius
= 5/9 * (Temperature in degrees Fahrenheit – 32)

16
The Waterfall model (cont.)

3. 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.
◼ 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.,
i. Initialization: Initialize the variables used in the program
ii. Processing: Input data, perform the calculation
iii. Termination: Display the result

17
The Waterfall model (cont.)

3. Design (cont.)
◼ Top-down design (cont.)
◼ Example: Convert a temperature in degrees Fahrenheit to degrees
Celsius
i. Initialization: No variables need to be initialized in this case
ii. Processing:
◼ Get the temperature in degrees Fahrenheit

◼ Convert the temperature to degrees Celsius using the formula,

Temperature in Celsius = 5/9 * (Temperature in Fahrenheit – 32)


iii. Termination: Display the temperature in degrees Celsius

18
The Waterfall model (cont.)

4. Coding
◼ The implementation of the designed algorithm in a programming
language.
◼ Each line of pseudocode or each block of a flowchart should be
translated into one or few lines of real code.
5. 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.

19
The Waterfall model (cont.)

6. Maintenance
◼ It is a continuous and systematic process of updating the software that is
already in use, in order to prevent system failures and to enhance the
efficiency of the software.
◼ The software is updated to
◼ rectify errors and oversights undetected in the testing phase,
◼ accommodate the changing needs of the end-user.
◼ Proper documentations should be kept during each phase of software
development process.
◼ Requirements documents, software design documents, internal
documentation, etc.

20
Writing A Program
◼ Program
◼ List of instructions that the computer must follow in order to process
data information [from Using Information Technology, pp. 489]
◼ Algorithms + Data Structures [from The Art and Science of C, pp. 376]

◼ Before writing a program,


◼ Have a thorough understanding of the problem
◼ Plan carefully an approach for solving it

◼ While writing a program,


◼ Know what “building blocks” are available
◼ Use “good programming principles”

21
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.
◼ 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.

22
Structured programming
◼ All program can be written in terms of three control structures:
◼ Sequence structure
◼ Instructions are executed sequentially by default.
◼ Selection structure
◼ A condition is tested; the next instruction to be executed is selected from
two or more options based on the truth value of the condition.
◼ Repetition structure
◼ A condition is tested; a block of instructions is repeated as long as the
condition remains true.

23
Pseudocode
◼ It is one of the most commonly used design tools for developing
algorithms.
◼ It is an imitation of the actual computer instructions.
◼ It is not actually executed on computers.
◼ It consists of actions statements including
◼ input or output operations, assignment statements, calculations and
data manipulations, function calls, etc.

24
Flowcharts
◼ It is a graphical representation of an algorithm.
◼ Each steps of an algorithm are illustrated as boxes of various
special-purpose symbols connected by arrows
◼ The order in which actions are to be performed is indicated by the
arrows.

25
Flowcharts (cont.)
◼ Commonly used symbols:
Symbol Description
Oval (or start and end symbol)
It indicates the beginning or end of a
program, or a section of code
Rectangle (or action symbol)
It indicates any type of action

Diamond (or decision symbol)


It indicates a decision is to be made

Arrow (or flowline)


It shows the flow of the program

Connector (or entry and exit symbol)


It connects one flowchart to another
26
Algorithm design: Example 1
◼ Convert a temperature in degrees Fahrenheit to degrees
Celsius.
◼ Flowchart ◼ Pseudocode
Start
Prompt user for tempF
Prompt user for tempF Input tempF
tempC = 5/9*(tempF-32)
Input tempF
Print tempC
tempC = 5/9*(tempF-32)

Print tempC

End

27
Algorithm design: Example 2
◼ Design an algorithm that inputs two numbers, and displays the
numbers in ascending order.
◼ Flowchart ◼ Pseudocode
Start
Prompt user for two numbers
Prompt user for 2 numbers Input a and b from user
If a is smaller than b
Input a, b
Selection
Print a and b
True
a<b Print a, b Otherwise
False Print b and a
Print b, a

End
28
Algorithm design: Example 3
◼ Design an algorithm that prints the first 3 integers.
◼ Flowchart ◼ Pseudocode

Set count to 1
count = 1 Repetition
While count is less than or equal to 3
True Print count
count <= 3 Print count
Increment count by 1
False
count++

29
Applying software development method
◼ Problem statement
◼ Design an algorithm that inputs an arbitrary number of non-zero positive
integers and determine the sum of all odd integers read
◼ Analysis
◼ The problem states that an unknown number of non-zero positive
integers are expected to be received from the user. Upon receiving these
numbers, the algorithm should be able to identify all integers having an
odd value and determine the sum of all odd integers read
◼ Input to the problem:
integer /* a number with no fractional part */
◼ Expected output:
sum /* sum of all odd integers read */

30
Applying software development method (cont.)
◼ Design (Top-down design)
◼ First refinement: Divide problem into smaller tasks and list them in order
i. Initialization: Initialize variables
ii. Processing: Input data from user, determine and sum all odd
integers
iii. Termination: Display the result

31
Applying software development method (cont.)
◼ Design (Top-down design) (cont.)
◼ Second refinement: Commit to specific variables
◼ Refine the initialization phase from Initialize variables to
◼ Initialize sum to 0

◼ Refine the processing phase from Input data from user, determine and
sum all odd integers to
◼ Input integer

◼ While integer is non-zero positive

◼ If integer cannot be divided evenly by 2

Add integer into sum


◼ Input integer

◼ Refine the termination phase from Display the result to


◼ Display sum

32
Applying software development method (cont.)
◼ The complete pseudocode:

Initialize sum to 0

Input integer
While integer is non-zero positive
If integer cannot be divided evenly by 2
Add integer into sum
Input integer

Display sum

33
Applying software development method (cont.)
◼ Flowchart:
Start

Initialization: sum = 0

Input integer Repetition structure

True True
Processing: integer > 0 integer % 2 sum += integer

False
False
Input integer Selection structure
Termination: Print sum

End
34
Integrated development environment
◼ Integrated Development Environment (IDE) is a software
package used to develop a program which includes:
◼ Text editor
◼ Preprocessor
◼ Compiler
◼ Linker
◼ Debugger
◼ Examples of IDE for C:
◼ GNU gcc, Borland C++, Microsoft Visual C++, Dev-C++
◼ Rhide - IDE for gcc in DOS

35
C program development
Program a.c is created in the
◼ Phases of C program Editor Disk editor and stored on disk

development: Preprocessor program


Preprocessor Disk processes the code
◼ Edit
◼ Preprocess Compiler
Compiler creates object code
Disk and stores it on disk
◼ Compile
Linker links the object
◼ Link Linker Disk code with the libraries,
creates a.exe and stores
◼ Load Primary memory it on disk
Loader
◼ Execute Loader puts program in
memory

...
Disk
Primary memory
CPU takes each
CPU instruction and executes
it, possibly storing new
...
data values as the
program executes

36
C program development (cont.)
◼ Text editor
◼ Program used to edit simple text.
◼ Editor for MS DOS, Notepad for Windows, Emacs and Gedit for Linux.
◼ C program file name should end with an extension of .c
◼ Preprocessor
◼ Executes automatically before the compiler’s translation phase begins.
◼ Obeys special commands called preprocessor directives.
◼ Usually consists of including other files in the file to be compiled and
performing various text replacements.
◼ Compiler
◼ Translates a source code written in a high level language into a machine
language code (object code).

37
C program development (cont.)

◼ Linker
◼ C programs typically contain references to functions defined elsewhere,
such as in the standard libraries or in the private libraries of groups of
programmers working on a particular project.
◼ A linker links the object code with the libraries to produce an executable
file, eg., c_prog.exe
◼ Loader
◼ Takes the executable image from disk and transfers it to memory
◼ To load and execute a program on a DOS system, type the program
name and press Enter, eg.,
c:\ecp1036>c_prog

38
Programming errors
◼ Syntax (compilation) error
◼ Violations of syntax rules, which define how the elements of a
programming language must be written.
◼ Caught by the compiler during the compilation process.

◼ Logic (execution-time) error


◼ Not caught by the compiler; have their effect at execution time.
◼ Two types of logic errors; i.e., non-fatal and fatal
◼ Non-fatal: Program runs, but often producing incorrect result
◼ Fatal: Program exits prematurely, i.e. division by zero on most systems

39
Dev-C++
◼ Bloodshed Dev-C++ is a full-featured IDE for the C/C++
programming language.
◼ It uses Mingw port of GCC (GNU Compiler Collection) as its
compiler.
◼ Downloaded for free at http://www.bloodshed.net/dev/devcpp.html

40
Dev-C++ (cont.)
◼ Sample of executing a C program using Dev-C++:

41
Summary
◼ The six steps in software development using the Waterfall
model are requirements, analysis, design, coding, testing and
maintenance.
◼ An algorithm is a sequence of instructions for carrying out a
procedure or solving a problem
◼ An algorithm can be represented in the form of pseudocode
and flowchart
◼ The six phases in developing a C program are edit, preprocess,
compile, link, load and execute.

42

You might also like