5.1.6. Program design tools - Computer Notes | Computer Notes for 11 and 12 | PLK Computer Sir

Breaking

Home Top Ad

Post Top Ad

Responsive Ads Here

5.1.6. Program design tools

A program is developed to solve our real-world problem. The program development process has mainly three phases: analysis, design and development. During the analysis phase, the detailed study of the problem must be done. After the analysis phase, the problem is designed by using different programming tools such as algorithms, pseudo codes, flowchart, etc. During this period, input, process and output of the problem are determined. The good program design makes efficient and faster development of program. After designing, it is ready for development i.e. programming the problem.

i.                   Algorithm

Algorithm is one of the most basic tools used for solving problem. It is defined as the finite sequence of instructions for solving a problem. It consists of stepwise list of English statements making sequential procedure. The number of instructions should be minimized to increase the speed of the algorithm.

Algorithm is a finite sequence of instructions for solving a problem.

There are not any specific rules for designing algorithms however, designing an algorithm requires a clear understanding of a problem. Before writing an algorithm, a designer should have knowledge about the input, output and process of a problem. The instructions are written in simple informal English statements. Some of the major guidelines while writing an algorithm are as follows:

·                     The number of instructions should be finite.

·                     Each instruction should be in simple language and no ambiguous instructions should be included. 

·                     It should have an input, process and desire output after executing the algorithm.

·                     It should not depend on any language or computer.

Algorithm for calculating simple interest

Step 1: Start
Step 2: Input Principal, Rate and Time
Step 3: Multiply Principal , Rate and Time and Divide by 100
Step 4: Store the result in Simple Interest
Step 5: Output Simple Interest
Step 6: Stop

Advantages of algorithm:

·                     It is simple and easy to understand.

·                     It has no hard and fast rules for writing an algorithm. 

·                     It does not require prior knowledge of programming during writing algorithms. 

Disadvantages of algorithm:

·                     It is more difficult to translate algorithms into program codes. 

·                     It is not considered as a standard tool for program designing.


ii.                 Flowchart

When an algorithm is expressed in pictorial form, then it is called flowchart. It is defined as a pictorial representation of an algorithm that describes the procedure to solve a problem. lt shows the order of instructions and relationship between them. The purpose of constructing flowchart is to help for the programmer for understanding the logic of a problem.

Flowchart is a pictorial form of an algorithm. It uses meaningful symbols to represent different types of instructions.

It uses different meaningful symbols to solve a problem. It is useful tools when an algorithm is short and fits conveniently on one page. Moreover, it also helps for the solutions of mathematical and logical problems. It defines the sequence and the flow of operations of a problem. It clearly explains the input, process and output of a problem. It shows the internal relationship between the instructions. Some of the major features are as follows.

·                     It is only suitable for small logical or mathematical problems.

·                     It cannot solve complex and lengthy problems.

·                     It can only solve procedural types of problems.

·                     Designers should have knowledge about the symbols of flowchart.

Symbols used in Flowchart



Flowchart for calculating Simple Interest

Flowchart to calculate simple interest


Advantages of Flowchart

·                     It is very efficient tool for solving logical and mathematical problems.

·                     It shows the types of instruction whether; an instruction is input/output, process or logical.

·                     It is easy for converting flowchart into program codes.

·                     It is easy for testing and maintenance.

Disadvantages of Flowchart

·                     It is difficult for solving large and complex problem.

·                     It is time consuming for designing a flowchart.

·                     It is difficult for modifying and updating the flowchart.

·                     Designer should be familiar with different symbols and their respective meanings.


iii.              Pseudo Code

Pseudo code is a kind of  algorithm for solving a problem. The instructions of pseudo code are written by using English phrase and mathematical expressions. It is also known as structured English. It has no specific rules for writing instructions, but the instructions are very closer to high level language instructions. Designer should have basic knowledge about high level language instructions before writing pseudo code. It is independent of any programming languages.

Pseudo code is a kind of algorithm in which the instructions are expresses in more English like structure and mathematical expression. The instructions of pseudo code are similar to the program instructions.



Pseudo Codes for calculating simple interest

Start
Input P,T and R
Calculate SI=(P*T*R)/100
Output SI
Stop

Advantages of Pseudo Code:

·                     Complex and lengthy problems can be easily solved by using pseudo code.

·                     It is easy for converting pseudo code into program codes.

·                     It is easy for testing because it can be tested by using computer aided tools.

·                     It is independent of any programming languages.

Disadvantages of Pseudo Code:

·                     Designer should have prior knowledge of programming while writing pseudo code.

·                     It is more complex than algorithm.


CONTROL STRUCTURE

A control structure is the most powerful tool in any high level language which is used to control the flow of instructions in a program. Moreover, it is used to develop program logic for the solution of a problem. It is also known as control statement. The main components of control structure are sequence, selection and repetition / iteration / looping.

A control structure is major component of a high level language that helps to control the flow of instructions in a program.



i.                   Sequence

A sequential control structure is a linear structure. It executes statements one after another in a sequence. There is no mechanism for choosing alternate paths in statements flow. It executes one statement then automatically moves to next statement and so on.

Algorithm Syntax of Sequence:

Start
Statement 1
Statement 2
..................
..................
Statement N
End


Flowchart of Sequence:


Example of Sequential Control Structure
Write an algorithm and a flowchart to calculate area of rectangle.
Algorithm to calculate area of rectangle
Step 1: Start
Step 2: Input L,B
Step 3: Calculate A=L*B
Step 4: Output A
Step 5: Stop

Flowchart to calculate area of rectangle



Ch 5 Assignment 3

1.                 What are the three states of program development?

2.                 List any three program design tools.

3.                 Write an algorithm to calculate area of square.

4.                 Write an algorithm to calculate area of a circle.

5.                 Write an algorithm and a flowchart to calculate to calculate simple interest.


ii.                 Selection

A selection structure is known as branching statement. It has the decision-making capabilities based on given conditions. It allows alternative paths for the instructions of a program based on given conditions. If the condition is true, one set of instructions will be executed otherwise, another set of instructions will be executed. Mainly, there four categories of selection structures such as if else, if else if, nested if else and switch case structure. Let us discuss simple if else structure here and we will be discussed the other categories of selection structures later in C programming.

Simple if else structure is the basic type of selection structure. If a given problem has one condition with respective two actions: true/false, then we can use simple if else structure. We should consider either true or false part. If the given condition is true, then the statement 1 will be executed, otherwise the control moves to else part i.e. statement 2 will be executed. In this case, the else part is optional so, if we remove else part then it will become simple if statement.

Algorithm syntax of if else

if(condition)
statement 1;
else
statement 2;

Simple if statement
if(condition)
statement

Flowchart of if else statement



Example of Selection Control Structure

Write an algorithm and a flowchart to find the greater number among two numbers.

Algorithm to find the greater number among two numbers

Step 1: Start
Step 2: Input A,B
Step 3: if(A>B)
Output A is greater.
else
Output B is greater.
Step 4: Stop

Flowchart to find the greatest number among two numbers

Ch 5 Assignment 4

1.                 What are the three major components of selection structure?

2.                 List four types of selection structures.

3.                 Write an algorithm and a flowchart to check the number is positive or negative.

4.                 Write an algorithm and a flowchart to check the number is odd or even.

5.                 Write an algorithm and a flowchart to check the number is divisible by 5.


iii.              Iteration / Looping

Iteration is commonly known as looping or repetition. In iteration process, an instruction or group of instructions is repetedly executed until some condition has been satisfied. Every loop has three fundamental components: intilialization, condition and counter. An intialization statement defines the starting point of the loop. The condition defines the stopping point of the loop and finally the counter counts the number of iterations. The increment and decrement operations are used as counter. If the condition of a loop is always true, then the loop will be executed infinite times and such loop is called infinite loop. There are three types of loops: while, do while and for loop.

Let us consider simple while loop. In this loop, computer first checks the condition, if the condition is true, then it executes the statements inside loop. The process is repeated and the value of increment or decrement operator is also changing. When the condition is false the loop stops. If the given condition is intially false, then the loop will not execute further.

Algorithmic Syntax of while loop

intialization;
while(condition)
{
statements
..........
..........
increment/decrement;
}

Flowchart of while loop

Flowchart of while loop



Example of Looping | Iteration Control Structure

Write an algorithm and a flowchart to print 1 to 10.

Algorithm to print 1 to 10

Step 1: Start
Step 2: i=1
Step 3: while(i<=10)
{
Output i
i++
}
Step 4: Stop

Flowchart to print 1 to 10

 

Flowchart to print 1 to 10




ABSOLUTE BINARY, ASCII, BCD

A computer understands only binary numbers in the form of two electronic states: high voltage(1) and low voltage (0). Such binary notations are further derived into different standard codes. Such codes are used to represent the data for convenience to the users. Different data representation codes are used in computer system. Some of the popular codes are as Absolute Binary, BCD, ASCII, EBCDIC, Unicode etc.

Absolute Binary

We use plus sign + and minus - sign to represent positive and negative numbers respectively. In computer system, such mechanism is not employed. In absolute binary method, 0 is placed before the binary number to represent positive number and 1 is placed before the binary number to represent negative number. The binary number is expresses in 8-bits,16-bits,32-bits or 64-bits format on the basis of word length of processor. The most significant bit denotes the sign bit and the rest of the bits represent the actual number. For examples: To represent +12, in 8 bit absolute binary number is 00001100, similarly for -12, the absolute 8 bits binary number is 10001100.

BCD

The binary coded decimal code is used to represent numeric data in computer. It uses 4 bits to represent a single digit decimal number. For examples: BCD code for 7 is (0111) and BCD code for 15 is (0001 0101).

ASCII

The American Standard Code for Information Interchange is the standard code to represent data in computer. It assigns numeric value for each character, number and symbol. It is extensively used in most of the computers, peripherals and soft wares. It is 8-bits code which represents 256 characters or symbols. For examples: ASCII code for A-65,B-66,C-67,a-97,b-98 etc.

EBCDIC

It stands for Extended Binary Coded Decimal Interchange Code. It is an eight bits code, which defined 256 different characters or symbols. It is mostly used in IBM mainframe and other minicomputers. It is not used in personal computer.

Unicode

Unicode Worldwide Character Standard is a character set which provides 16 bits codes to represent 65536 different character, numbers, symbols etc. It includes characters of all the languages of the world. It also includes all characters from ASCII character set. A newer version of Unicode has 32 bits character set which represents more than 4 billion different character or symbols from the world.

Ch5 Assignment 5

1.                 What are the three components of a loop?

2.                 What happens when the condition is always true in the loop?

3.                 Write an algorithm and a flowchart to print 100,99,98,...1.

4.                 Write an algorithm and a flowchart to print 1   3   5   .....N

5.                 Write an algorithm and a flowchart to display multiplication table of 5.

6.                 Write the full form of BCD, ASCII, EBCDIC and Unicode.

 

No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages