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

11th CS Program Analysis-2

The document outlines the program development life cycle, which includes problem definition, analysis, algorithm development, coding, testing, and debugging. It explains various methods for program analysis such as algorithms, flowcharts, and pseudocode, detailing their characteristics, advantages, and disadvantages. Additionally, it provides examples of algorithms and flowcharts for common tasks like finding the largest number and calculating the square of a number.

Uploaded by

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

11th CS Program Analysis-2

The document outlines the program development life cycle, which includes problem definition, analysis, algorithm development, coding, testing, and debugging. It explains various methods for program analysis such as algorithms, flowcharts, and pseudocode, detailing their characteristics, advantages, and disadvantages. Additionally, it provides examples of algorithms and flowcharts for common tasks like finding the largest number and calculating the square of a number.

Uploaded by

Hardik Dandekar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

2.

Program Analysis:
What is program:

◦ Program is a list of instruction given to a computer before writing a program user


has to define problem.
Program Analysis
1. Problem Definition
Here, we define the problem statement and decide the boundaries of the problem.
In this phase, we need to understand what is the problem statement, what is our requirement and
what is the output of the problem solution. All these are included in the first phase of program
development life cycle.
2. Problem Analysis
Here, we determine the requirements like variables, functions, etc. to solve the problem. It means
that we gather the required resources to solve the problem, which are defined in the problem
definition phase. Here, we also determine the bounds of the solution.
3.Algorithm Development/Design
Here, we develop a step-by-step procedure that is used to solve the problem by using the
specification given in the previous phase. It is very important phase for the program development.
We write the solution in step-by-step statements.
4.Coding & Documentation
It is the process of conversion of problem design into programming language,
Here, we use a programming language to write or implement the actual programming instructions
for the steps defined in the previous phase.
We construct the actual program in this phase. We write the program to solve the given problem by
using the programming languages like C, C++, Java, etc.
5.Testing & Debugging
In this phase, we check whether the written code in the previous step is solving the specified
problem or not. This means, we try to test the program whether it is solving the problem for various
input data values or not. We also test if it is providing the desired output or not.
FOR ANALYSIS VARIOUS METHODS ARE USED:
THESE METHODS ARE:
1.ALGORITHM
2. FLOWCHART
3.PSEUDOCODE
What is Algorithm?
❖The word Algorithm means “a process or set of rules to be followed in calculations or other
problem-solving operations”.
❖ Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be
executed upon in order to get the expected results.
❖Algorithm is a step-by-step set of instructions designed to perform a specific
task.
❖Algorithm is a logical sequence of steps prepared for solving problems.
❖It is tool to write a job in simple steps in simple English language.
❖It is not a programming language.
❖It is just used for guide to the users.
Steps:
Step 1: Start
Step 2: Declare variables/ intialize
Step 3. Read value
Step 3: Procees
Step 4: Display output
Step 5: STOP
Example:
An algorithm to add two numbers:
1.Take two number inputs
2.Add numbers using the + operator
3.Display the result

Step 1: Start
Step 2: Declare variables num1, num2 sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum = num1+num2
Step 5: Display sum
Step 6: Stop
Write an algorithm to find the square of a number.

Start
Step 1 : Start
Step 2 : Input a number As Num,
C Read
Number
Step 3 : Multiply the number A ‘Num’
twice by itself
Num*Num C=Num * Num
Step 3 : Store result In C
◦ C=Num* Num Display
Step 4 : Display C C

Step 5 : Stop Stop


Algorithm 2: Find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else If b > c
Display b is the largest number.
Else Display
c is the greatest number.
Step 5: Stop
Characteristics of Algorithm:
❖ It should be easy and Simple Language.
❖It should Not repeat the task again and again.
❖Every step must be accurate and complete.
❖ It can be easily modified if necessary.
❖It should be easily understandable to others and steps should be
clear.
Flowchart
❖A Flowchart is a graphical or symbolic representation of an algorithm/of a
process.
❖Definition:
❖The method used to represent an algorithm in pictorial form with standard
meaningful symbols is known as Flowchart.
❖ Each step in the process is represented by a different symbol and
contains a short description of the process step.
❖The flow chart symbols are linked together with arrows showing the
process flow direction.
Symbols used in flowchart:
1. Terminal:
The oval symbol indicates the start or stop/end of the process.
An oval flow chart shape indicating A pause is generally used in a program logic under some
error conditions.
Terminal is the first and last symbols in the flowchart.
•2.Input/Output: A parallelogram denotes any function of input/output type.
•Program instructions that take input from input devices and display output on output devices are indicated
with parallelogram in a flowchart.

3.Processing: A box represents arithmetic instructions.


All arithmetic processes such as adding, subtracting, multiplication and division are indicated by action or
process symbol.
A rectangular flow chart shape indicating a normal process flow step.
4.Decision :
Diamond symbol represents a decision point.
Decision based operations such as yes/no question or true/false are indicated by diamond in flowchart.

5.Connectors:
Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use
connectors to avoid any confusions. It is represented by a circle.
circular flow chart shape used to indicate a jump in the process flow
7. Flow lines: Flow lines indicate the exact sequence in which instructions are executed.
Arrows represent the direction of flow of control and relationship among different symbols of flowchart.

Advantages of Flowchart:
• Flowcharts are better way of communicating the logic of system.
• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts helps in debugging process.
• With the help of flowcharts programs can be easily analysed.
• It provides better documentation.
• Flowcharts serve as a good proper documentation.
Disadvantages of Flowchart:
• It is difficult to draw flowchart for large and complex programs.
• In this their is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.
Example : Draw a flowchart to input two numbers from user and display the largest of two numbers
Example : Draw a flowchart to input two numbers from user and display the largest of two
numbers

Example : Draw a flowchart to find square of a number.


◦ Draw flowchart to exchange swap values of two variables.

Example : Draw a flowchart for accept in 3subjects and find sum and average
Pseudocode
Definition:
◦ It is a programming analysis used for planning program logic.
◦ Pseudocode is tool used to solve problems of computer programs.

◦ Pseudocode is a detailed description of an algorithm which explains the function to be performed by the program.
◦ Pseudocode is one of the initial processes in the program development.
◦ Pseudocode is expressed in natural language, written in formal style which can be easily read and understood by
anyone.
◦ It can be said a template which is used for writing detailed instructions/ coding in a specific programming
language.

◦ Advantages:
◦ 1. Converting a pseudocode to programming language is much more easier as compared to flowchart.
◦ 2. It is used to write pseudocode as compared to drawing flowchart and actual program.
3.Pseudocode uses English like statements. Therefore, it can be written easily and quickly.
4.In pseudocode, each step is independent of other steps. Therefore, if any modification is done in any step, it does
not affect the codes of other module i.e. the code has not to be rewritten if any change occurs in any other step.
◦ Limitations:
1.Pseudocode is textual representation of an algorithm.
2. It does not provide graphical representation. Therefore, sometimes, it
becomes difficult to understand the complex logic written in
pseudocode.
3..When too many nested conditions are used in the pseudocode, the
level of difficulty to understand the code increases.
3.Graphic representations of program logic is not available in pseudo
codo.
Start

Declare A, B

Read A,B

If NO
A>B
YES
Display A Display B

Stop
Swapping of 2 numbers
Here in this algorithm we declare 3 variables to store integers ,then we input two numbers lets say 10 and 20. In the computer it gets
stored as a=10 and b=20 and we declare a variable T because if we put a=b then the value of b gets stores in a and then valuegets
removed ,so we put the value of a in t i.e. t=a, so t becomes 10 then we put a=b so a becomes 20. Now we put value of t that stored the
value of a in b ,b=a b becomes 10.

Step 1: Start
Step 2:Declare variables A, B and T as integer
Step 3: Read value of A and B
Step 4: T=A
Step 5: A=B
Step 6. B=T
Step 7. Print A
Step 8. Print B
Step 9. Stop A=10 B=20
OUTPUT: B=20 A=10
Step 1: Start
Step 2: Declare Variable n, fact, i
Step 3: Read number n

Step 4: Initialize Variable fact=1 and i=1


Step 5: Repeat While i<=number
fact=fact*i
i=i+1
Step 6: Display fact
Step 7: Stop
Step 1: Start
Step 2: Declare Variable sub1,sub2,sub3
Step 3: Read marks in subjects as sub1, sub2,sub3

Step 4: Initialize sum=0


Step 5: Add marks of 3 subjects
sum= sub1 + sub2 + sub3
Step 6: Average = sum/3
Step 7:Display sum and Average
Step 8: Stop
START

Declare marks in subjects as sub1,


sub2,sub3 Sum=0

Read marks in
subjects as sub1,
sub2,sub3

sum= sub1 + sub2 + sub3

Average = sum/3

Print sum and


Average

STOP
Start

Read N

If
N%2==0

YES

Print N is even Print N is


Odd

STOP
Start

Declare A, B

Read A,B

If NO
A>B
YES
Display A Display B

Stop

You might also like