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

Program design

C pro

Uploaded by

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

Program design

C pro

Uploaded by

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

lOMoAR cPSD| 42087690

Program design
The program design is the process that an organization uses to develop a program. It is most
often an iterative process involving research, consultation, initial design, testing, and
redesign.
A program design is the plan of action that results from that process.

Program design approaches

● Top – Down
● Bottom-Up
● Data-Driven
Top-Down Design Model:
Top down Approach
(a) The large program is divided into many small module or subprogram or function or
procedure from top to bottom.

(b) At first supervisor program is identified to control other sub modules. Main modules are
divided into sub modules, sub-modules into sub- sub- modules. The decomposition of
modules is continuing whenever desired module level is not obtained.

(c) Top module is tested first, and then sub-modules are combined one by one and tested.

Example: The main program is divided into sub-program A, B, and C. The A is divided into
subprogram A1, A2 and A3.The B is into B1, and B2. Just like these subprograms, C is also
divided into three subprogram C1, C2 and C3. The solution of Main program is obtained from
sub program A, B and C.

Bottom-Up Design Model:


• In this approach designing is started from bottom and advanced stepwise to top. So,
this approach is called Bottom up approach.
• At first bottom layer modules are designed and tested, second layer modules are
designed and combined with bottom layer and combined modules are tested. In this way,
designing and testing progressed from bottom to top.

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

• In software designing, only pure top down or Bottom up approach is not used. The
hybrid type of approach is recommended by many designers in which top down and
bottom up, both approaches are utilized.

Data-driven approach
When doing data-driven programming, one clearly distinguishes code from the data structures
on which it acts and designs both so that one can make changes to the logic of the program by
editing not the code but the data structure.
Data-driven programming is sometimes confused with object-orientation, another style in
which data organization is supposed to be central. There are at least two differences. One is
that in data-driven programming, the data is not merely the state of some object, but defines
the control flow of the program. Where the primary concern in OO is encapsulation, the primary
concern in data-driven programming is writing as little fixed code as possible. Unix has a
stronger tradition of data-driven programming than OO.
Programming data-driven style is also sometimes confused with writing state machines. It is,
in fact, possible to express the logic of a state machine as a table or data structure, but hand
coded state machines are usually rigid blocks of code that are far harder to modify than a table.
An important rule when doing any kind of code generation or data-driven programming is this:
always push problems upstream. Don't hack the generated code or any intermediate
representations by hand — instead, think of a way to improve or replace your translation tool.
Otherwise, you're likely to find that hand-patching bits that should have been generated
correctly by the machine will have turned into an infinite time sink.

Program Design Tools


Computers are problem-solving devices and it is an electronic programmable machine that
requires a set of instructions to perform tasks. To facilitate a computer to solve problems
effectively, clear and concise instructions must be provided to it. A programmer must provide
clear instructions to perform a task and he must have a plan to solve a particular problem using
programming tools like algorithms, flowcharts, and pseudocode.

Flowchart
The pictorial presentation of program is called Flowchart. It is a tool and technique to find out
solution of programming problems through some special symbols. It is a way to represent
program using geometrical patterns. Prior to 1964, every manufactures use different types of
symbols, there was no uniformity and standards of flowcharting. The Standard symbols were
developed by American Standard National Institute (ANSI).

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

There are two types of Flow Chart:

(a) Program Flow Chart and

(b) System Flow Chart.

Program Flow Chart

(i) Start / Stop: This oval is used to represent START and STOP of program.

(ii) Input/Output: Parallelogram is used to denote input and output of data. We take data
through it and display result also using this symbol.

(iii) Process: Rectangle is used to denote process, formula, increment, and decrement and
assigned value also.

(iv) Pre-defined Process: The predefined process is denoted by this symbol. Example: Sorting
and Display is pre-defined process and represented as:

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Pre-defined Process

(iv) Decision box: It is a symbol of decision. All type of decisions is written in it.

(v) Connector: It is used to link to segment of flowchart to complete as one.

(vi) Data flow: It is used to show data flow from one component to other component, one
process to other and one symbol to other symbol.

The John Von Neumann used flowchart to solve problem in 1945 and explained its importance
in program designing.

Illustration: In our everyday life, there is a sequence of works. These sequences of works are
called routine. We all are tied with it. Suppose, we arise early in the morning at 5 0‘ clock, go to
toilet, after coming from toilet, clean hands with soap and water, brush our teeth then take bath.
Here, one sequence of work is formed.

In computer world, programming language is used to solve certain problems. The solution of
problem is a sequence of processes. In one problem, there may be many processes, the flowchart
help to arrange processes in definite order. Suppose, we have to convert Fahrenheit temperature
into Celsius, it has following five steps:

• Step-1: Start
• Step-2: Enter Fahrenheit temperature (F)
• Step-3: Application of formula: C=(F-32)(5/9)
• Step-4: Displaying the result (C)
• Step-5: Stop

These types of processes involved in solution of problem are called Algorithm. It is a stepwise
presentation of problem solution in simple English without using confusing words and phrases.

When we draw flowchart, it is only conversion of steps or algorithm in special symbols.

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Flow Chart

Flowchart is like as city map. Travelers or tourists search places of historical importance through
city map. Buildings are built on the basis of building-design (map) drawn by Architect
engineers.

Just like it, program is coded on the basis of flowchart. Flowchart is a language free concept, if it
is prepared, any language can be used for program coding. In software development cycle,
flowcharting is one essential phase.

System Flowchart:
System flowchart is a pictorial representation of procedure flows inside and outside of the
systems. It is also called Data Flow Chart or Procedure Chart.

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

System Flowchart Symbols

(i) Manual Input: It is used to enter data manually. For example, keyboard is a manual input
device.

(ii) Process: All type of processes is denoted by Rectangle.

(iii) Magnetic Disk: Mass storage device (Hard Disk).

(iv) Magnetic Tape: Magnetic tape is also storage device.

(v) Display: This is a symbol for online display, Example: Monitor (VDU).

(vi) Document: The print out document is denoted by this symbol.

Program Flowchart and System Flowchart:


Sn. Program Flow Chart System Flow Chart
1. The pictorial presentation of System flowchart is a pictrorial
program is called Flowchart. It us representation of procedure flows
a tool and technique to find out inside and outside of the systems.
solution of programming problems It is also called Data Flow Chart or
through some special sysmbols. It procedure Chart. The special type
is a way to represent program of symbols is used to represent
using geometrical patterns. system flowchart.
2. It is tool of programmers. The This is a flowchart to show data
flowchart designing to solve any flow inside or out to designed
problem is called program system. The system designers
flowchart. The candidate system is draw it to show data flow inside
designed using program flowchart. the current system.
Problem-1: The source program is stored in hard disk and after compilation; the object program
(Machine code) is also stored in hard disk. The rectangle represents compilation process. The
error messages are printed out and displayed on VDU also.

Compilation Process

Problem-2: Draw a system flow chart to update master-file.

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

System Flowchart to update master file

Problem-3: The headquarter of ABC Private Ltd. is linked with production, marketing and sale
department. The day-by-day information of each department is compiled at headquarter, stored
in master file and report is given to higher authority of company.

2. Algorithm
Algorithm is a stepwise presentation of procedures of program in simple and phraseless English.
It is also a programming tools used by programmer to develop software. It is a logical
representation of program procedures in order to obtain result. So, sometimes, it is called
Procedure also. An algorithm, named after the ninth Centaury scholar Abu Jafar Muhammad
Ibn Musa Al-Khowarizmi of Bagdad (Iraq).

A program is an expression of an idea in any programming language. A programmer starts with


a general idea of a task for the computer to perform. The problem is flesh out the outline into a

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

complete, unambiguous, step-by-step procedure for carrying out the task. Such a procedure is
called an ‖Algorithm―. An algorithm is not same as program. An algorithm is more like the
idea behind the program.

• Language independent
• Simple, complete, unambiguous, step-by-step program flow
• no standard format or syntax for the algorithm
• helpful to understand problems and plan out solution

Example: Following algorithm is written to find out roots of quadratic equations:

• Step-1: Start
• Step-2: Read a,b and c
• Step-3: d=b*b-4*a*c
• Step-4: if D<0, root is imaginary
• Step-5: x1 = (-b + sqrt (D))/(2*a)

X2=(-b-sqrt(D))/(2*a)

• Step-6: Display x1 and x2


• Step-7: Stop

Example: Write an algorithm to find out area of triangle when sides are given.

Algorithm:

Step-1: start

Step-2: read a,b and c

Step-3: S=(a+b+c)/2

Step-4: A=sqrt((s-a)(s-b)(s-c))

Step-5: Display A

Step-6: Stop

Example: Write an algorithm to find out slop and mid point of coordinate.

Algorithm:

Step-1: Start

Step-2: Read x1, x2, y1 and y2

Step-3: Slop=(y2-y1)/(x2-x1)

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Step-4: x-(x1+x2)/2

Step-5: y=(y1 + y2)/2

Step-6: Stop

There are no standard rule for algorithm designing, but we can use some common rules which
are not ambiguous to another computer literates:

(a) Value to variable: variable (Variable or Expression)

(b) Conditional statements: if -endif and if –else-end-if are used for conditions.

Example:

If age>=18 then print ―Case vote‖

Else print ―Wait until not 18‖

Endif

(c) looping statements:

i. do while (condition) Statement(s) endo ii. for

variable=value1 to final value step stepvalue

statement(s) endfor

Example: Write an algorithm to display factrolial of given number.

Fact = 1

Print ―Enter number‖

Read number

For count =1 to count number step 1

Fact = fact * count

Endfor

Print ―Factorial:‖, fact

End

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Problem-1: Draw a flow chart to input two numbers and display sum.

Flow Chart to display sum of two numbers

Problem-2: Draw a flowchart to enter principal,rate and time and display simple interest.

Flowchart to Calculate Simple Interest

Problem-3: Draw a flowchart to find the sum of the given series.

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Solution,

Flow Chart to find sum of series

3. Pseudo-code or Structured English

A logical construction, which has

(a) No strict rules like as programming language,

(b) Unambiguous statements,

(c) Phrase less statements, contains noun and simple verb of English , and

(d) No adjective and adverbs structure is called Pseudo-code or Structured English.

It is a Program Design Language (PDL) provides skeleton for program design and it can
replace flowchart used to describe system design.

General rules used in writing Pseudo-codes are as follow:

(i) Imperative Sentence: The imperative sentences are used to show actions.

Example: Add x to sum, Display result, Sort list etc.

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

(ii) Operators: Mostly arithmetic operators (+, -, *, / etc) and relational operators (=, =>, =>, <,
> etc.) are used.

(iii) Decision: IF, THEN, ELSE, ENDIF, CASE, ENDCASE are used for decision-making.

Example:

CASE (choice)

(Choice = 1):Display Employee, Department

(Choice = 2): Display Employee, BasicSal, Allowance, Gross

(Choice = 3): Terminate Program

ENDCASE.

(iv) Looping: The looping or repetition of statements is shown by FOR, FOR DO, ENDFOR,
DO, DO WHILE, DO UNTIL, ENDDO etc.

Example:

Display ―Selected for National scholarship Examination‖

FOR roll1 TO roll=10 DO

Display roll, Name, Address

ENDFOR.

Example:

IF age >=18

THEN CASTE vote

ELSE
WAIT until age is not 18

ENDIF

Example: Mailing a letter

BEGIN

WRITE a letter

IF bicycle is available

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

THEN GO to Post Office by Bicycle

ELSE

GO to Post Office on foot

ENDIF

BUY a stamp

STICK a stamp on the letter

PUT into letterbox

END.

Decision Tables

A Decision table represents conditions and the respective actions to be taken to address
them, in a structured tabular format. It provides a visual and systematic method for
documenting various combinations of inputs and their corresponding outcomes or
actions.

It is a powerful tool to debug and prevent errors. It helps group similar information into
a single table and then by combining tables it delivers easy and convenient
decisionmaking. Decision tables are often used in decision support systems, business
analysis, and rule-based systems to clarify and manage complex decision-making
processes.

A decision table typically consists of the following components:

Conditions: These represent the different factors, variables, or criteria that


influence a decision. Conditions are often presented as columns in the decision
table.

Rules: These are the possible combinations of conditions and describe the
actions or outcomes associated with those combinations. Rules are usually
presented as rows in the decision table.

Actions: Actions specify what should be done or the result that should be
achieved for each combination of conditions.

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Creating a Decision Table

To create the decision table, the developer must follow the basic four steps:

● Identify all possible conditions to be addressed.

● Determine actions for all identified conditions.

● Create the Maximum possible rules.

Here's a simple example of a decision table for a loan approval system:

Condition 1 Condition 2 Condition 3 Action

Good credit Sufficient income Loan term < 5 years Approve Loan

Loan term ≥ 5 years


Good credit Sufficient income Decline Loan

Poor credit Sufficient income Any loan term Decline Loan

Good credit Insufficient income Any loan term Decline Loan

Poor credit Insufficient income Any loan term Decline Loan

In this decision table:

● There are three conditions: "Condition 1" represents the credit score of the
applicant, "Condition 2" represents the applicant's income, and "Condition 3"
represents the requested loan term.

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

● There are five rules, each representing a combination of conditions, and each rule
has an associated action. For example, the first rule states that if the applicant has
good credit, sufficient income, and a loan term of less than 5 years, the action is to
"Approve Loan."

● The last four rules state that if certain conditions are met, the action is to "Decline
Loan."

This decision table helps in making loan approval decisions based on a set of conditions and
their combinations. It provides a clear and structured way to document the decision rules,
making it easier for decision-makers to understand and implement the rules within a system.

Decision tables can be more complex, involving a larger number of conditions and rules, and
they are particularly useful when dealing with complex business logic or decision-making
processes.

Decision Tree
The tree like presentation of condition and actions are called decision tree. Every node denotes
conditions. It is used for logical variations and problems involving few complex decisions with
complex branching routines.

Example: The person which age is greater or equal to 18 can caste vote in the favour of his
leader otherwise has to wait until age of 18. There is two conditions (a)age<18, and (b)age>=18,
both the conditions have actions.

Decision Tree

Example: The hotel ABC offers new discount scheme foe university students. It
provides 15% and 10% discount to monthly customers for vegetarian and non-vegetarian
meal respectively. The student attend hotel occasionally have discount rate 10% and 5%
for vegetarian and nonvegetarian meal.

Draw decision tree to show discount scheme:

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

Example of Decision tree

Entity-Relationship Diagram (ERD)

An Entity-Relationship Diagram (ERD) is a graphical representation used to model the data


and the relationships between entities in a database. ERDs are a fundamental tool in database
design and are commonly used during the initial phases of designing a relational database.

They help visualize the structure of the database, including the entities (tables), attributes
(columns), and the relationships between them.

ERDs use specific symbols and notations to represent different components of the database:

Entities (Tables): Entities are represented as rectangles. Each entity represents a


category of data, such as "Customers," "Products," or "Orders."

Attributes (Columns): Attributes are depicted within the entities and are used to
describe the properties or characteristics of each entity. For example, a "Customers"
entity may have attributes like "CustomerID," "Name," and "Email."

Relationships: Relationships between entities are shown as lines connecting the


entities. The type of relationship (e.g., one-to-many, many-to-many) is often indicated
on the line.

Cardinality: Cardinality notation indicates how many instances of one entity are
related to how many instances of another entity in a relationship. Common
cardinalities include "1" for one instance and "N" for many instances.

lOMoAR cPSD| 42087690

By Peter Cheruiyot ([email protected])


lOMoAR cPSD| 42087690

ERDs provide a visual representation of the database structure, helping to understand


the relationships between entities and the flow of data in a database system. They serve as a
foundation for designing and implementing efficient and well-organized databases.

Assessment

What is the difference between Top-Down and Bottom-Up program design approaches?

What is the difference between pseudocode and flowchart program design tools?

What are some of the disadvantages of a flowchart?

What are the rules for developing a flowchart?

Write a structured algorithm that would prompt the user to enter the Length and Width of a
rectangle, calculate the Area and Perimeter, then display the result.

By Peter Cheruiyot ([email protected])

You might also like