1. UNIT 1 Computing and Programming Fundamentals - BCA151203
1 ASWIN R
UNIT 1: Programming Process
Developing a program, program development cycle; Introduction to Algorithms, Characteristics,
writing an algorithm; Flowchart, Symbols, guidelines for preparing flowchart, benefits of
flowcharts, limitations of flowcharts; Pseudocode, Pseudocode guidelines, benefits of
pseudocode, limitations of pseudocode; program control structures.
Define Algorithm.
• An algorithmis a series of specific steps which solve a particular problem. It is a
sequence of unambiguous instructions for solving a problem in a finite amount of time.
What are the Qualities of a good algorithm ?
• Inputs and outputs should be defined precisely.
• Each steps in algorithm should be clear and unambiguous.
• Algorithm should be most effective among many different ways to solve a problem.
• An algorithm shouldn't have computer code. Instead, the algorithm should be written in
such a way that, it can be used in similar programming languages.
Explain briefly about the characteristics/properties of an Algorithm.
The following are the five important properties of an algorithm
Finiteness :The algorithm must always terminate after a finite number of steps. If we trace out
the instructions of an algorithm, then fo all cases, the algorithm terminates after a feasible
number of finite steps.
Definiteness : Each and every instruction should be precise and unambiguous i.e. each and
every instruction should be clear and should have only one meaning. Ex : If we assign values
5 and 6to a variable x, then x can have either 5 or 6 (x=5 or x=6).
Input: The algorithm should have zero or more inputs that are given to it initially before the
algorithm begins or dynamically as the algorithm runs.
Output : An algorithm should have one or more output that have a specified relation to the
inputs. An algorithm should produce atleast one or more outputs.
Efficiency : The algorithm efficiency is measured by calculating the amount of time it takes for
execution and the amount of memory needed for it to execute.
2. UNIT 1 Computing and Programming Fundamentals - BCA151203
2 ASWIN R
Describe the Levels of description of an algorithm
Algorithms can be classed into having three accepted levels of description:
1. High-level description
It describes an algorithm, ignoring the implementation details.
2. Implementation description
It is used to define the way the implementation is done
3. Formal description
It is the most detailed having the "highest level" of detail.
Writing down the steps that can be followed in writing an algorithm for a
programFollowing Get a clear understanding of the problem statement.
1. Proceed in a step by step fashion.
2. Divide the job into parts.
3. Include variables and their usage and define expressions.
4. Outline each loop
5. Include action statements.
6. Work outwards from the Action Statements, figuring out how each parameter will be
determined each time the loop goes around
7. Go back to step number if loop or condition fails.
8. Use jump statement to jump from one statement to another.
9. Try to avoid unwanted raw data in algorithm.
10. Use break and stop to terminate the process.
Example:
Algorithm to find area of a circle
1. Start
2. Input the value of radius R
3. Let PI=3.14
4. Calculate area=PI*R*R
5. Print area
6.End
3. UNIT 1 Computing and Programming Fundamentals - BCA151203
3 ASWIN R
Example: Algorithm to find greater of two numbers
1. Start
2. Input a,b
3. If(a>b) then
Print “Larger number is “ a
else
Print “Larger number is “ b
end if
4. Stop
FLOW CHART
Definition
• Flowcharts were introduced by Frank Gilberth in 1921, and they were called “Process
Flow Charts” at the beginning.
• A flowchart is a diagram that represents a process or algorithm. The steps are represented
by a series of boxes or other specialized symbols, then connected with arrows.
Other Definitions of Flow Chart
A diagram of the sequence of movements or actions of people or things involved in a
complex system or activity.
A graphical representation of a computer program in relation to its sequence of functions (as
distinct from the data it processes).
Symbols of Flowcharts
Flowcharts use special shapes to represent different types of actions or steps in a process
4. UNIT 1 Computing and Programming Fundamentals - BCA151203
4 ASWIN R
Example1 Example 2
Find area of a circle Example 2 Addition of two numbers
5. UNIT 1 Computing and Programming Fundamentals - BCA151203
5 ASWIN R
Description of Flowchart Symbols
• Start and end symbols, represented as lozenges, ovals or rounded rectangles, usually
containing the word "Start" or "End", or another phrase signaling the start or end of a
process, such as "submit enquiry" or "receive product".
• Arrows, showing what's called "flow of control" in computer science. An arrow coming
from one symbol and ending at another symbol signifies flow passes to the symbol the
arrow points to.
• Processing steps, represented as rectangles. Examples: "Add 1 to X"; "replace identified
part"; "save changes" or similar.
• Input/Output, represented as a parallelogram. Examples: Get X from the user; display X.
• Conditional (or decision), represented as a diamond (rhombus). These typically contain a
Yes/No question or True/False test.
• This symbol is unique in that it has two arrows coming out of it, usually from the bottom
point and right point, one corresponding to Yes or True, and one corresponding to No or
False.
• The arrows should always be labeled.
Guidelines for preparing flowchart
• The following are some guidelines in flow charting:
• In drawing a proper flow chart, all necessary requirements should be listed out in logical
order.
• The flowchart should be clear, neat and easy to follow. There should not be any room for
ambiguity in understanding the flow chart.
• The usual direction of the flow of a procedure or system is from left to right or top to
bottom.
• Only one flow line should come out from a process symbol.
• Only one flow line should enter a decision symbol, but two or three flow lines, one for
each possible answer, should leave the decision symbol.
• Only one flow line is used in conjunction with terminal symbol.
6. UNIT 1 Computing and Programming Fundamentals - BCA151203
6 ASWIN R
• If the flowchart becomes complex, it is better to use connector symbols to reduce the
number of flow lines. Avoid the intersection of flow lines if you want to make it more
effective and better way of communication.
• Ensure that the flowchart has a logical start and finish.
• It is useful to test the validity of the flowchart by passing through it with a simple test
data.
Other Flow Chart Symbols
Advantages of Flowchart
• It provides an easy way of communication because any other person besides the
programmer can understand the way they are represented.
• It represents the data flow.
• It provides a clear overview of the entire program and problem and solution.
• It checks the accuracy in logic flow.
• It documents the steps followed in an algorithm.
• It provides the facility for coding.
• It provides the way of modification of running program.
• They shows all major elements and their relationship.
7. UNIT 1 Computing and Programming Fundamentals - BCA151203
7 ASWIN R
Limitation of Flowchart
• Complex logic: Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy.
• Alterations and Modifications: If alterations are required the flowchart may require re-
drawing completely.
• Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem.
• The essentials of what is done can easily be lost in the technical details of how it is done.
Different Types of Flowchart
Sequential Structure
• In sequential structure flow structure, all statements are executed in a sequential order
that is the statements are executed in the order in which they appears. Control is passed
from one statement to the next unconditionally.
Selective Structure
• This structure, in general, has a conditional expression at the beginning and followed by
which one or more than one statements are present. Depending on the conditional
expression is True or False. If the condition expression is True, the first statement will be
executed and in case the value is False, the second statement will be executed.
Looping Structure
• These structure execute a set of statements repeatedly as long as the conditional
expressional at the beginning of the structure is True. The control will be sent out of the
structure, when the conditional expression is False.
PSEUDOCODE
Definition
• A notation resembling a simplified programming language, used in program design.
• An outline of a program, written in a form that can easily be converted into real
programming statements
• Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax
rules. It is simply one step - an important one - in producing the final code
8. UNIT 1 Computing and Programming Fundamentals - BCA151203
8 ASWIN R
• Pseudocode is a "text-based" detail (algorithmic) design tool.
• Include control structures such as WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and
CASE, which are present in many high level languages.
Difference Between Algorithm and Pseudocode
Algorithm Pseudocode
An algorithm is a well defined sequence of
steps that provides a solution for a given
problem
A pseudocode is one of the methods that can
be used to represent an algorithm
Algorithms can be written in natural
language,
Pseudocode is written in a format that is
closely related to high level programming
language structures
Benefits/Advantages of Pseudocode:
• Can be done easily on a word processor
• Easily modified
• Implements structured concepts well
• Clarify algorithms in many cases.
• Impose increased discipline on the process of documenting detailed design.
• Provide additional level at which inspection can be performed.
• Help to trap defects before they become code.
• Increases product reliability.
• May decreases overall costs.
• It can be easily modified as compared to flowchart.
• Its implementation is very useful in structured design elements.
• It can be written easily.
• It can be read and understood easily.
• Converting a pseudocode to programming language is very easy as compared with
converting a flowchart to programming language.
9. UNIT 1 Computing and Programming Fundamentals - BCA151203
9 ASWIN R
Limitations/Disadvantages of Pseudocode:
• It's not visual
• Create an additional level of documentation to maintain.
• Introduce error possibilities in translating to code.
• May require tool to extract pseudocode and facilitate drawing flowcharts.
• There is no accepted standard, so it varies widely from company to company
• We do not get a picture of the design.
• There is no standardized style or format, so one pseudocode may be different from
another.
• For a beginner, it is more difficult to follow the logic or write pseudocode as compared
to flowchart.
Pseudo Guidelines : Rules for Pseudocode
1. Write only one statement per line
2. Capitalize initial keyword
3. Indent to show hierarchy
4. End multiline structures
5. Keep statements language independent
1. Write only one statement per line:
Each statement in your pseudocode should express just one action for the computer.
If the task list is properly drawn, then in most cases each task will correspond to
one line of pseudocode.
EX: TASK LIST:
Read name, hourly rate, hours worked, deduction rate
Perform calculations
gross = hourlyRate * hoursWorked
deduction = grossPay * deductionRate
net pay = grossPay – deduction
Write name, gross, deduction, net pay
10. UNIT 1 Computing and Programming Fundamentals - BCA151203
10 ASWIN R
PSEUDOCODE:
READ name, hourlyRate, hoursWorked, deductionRate
grossPay = hourlyRate * hoursWorked
deduction = grossPay * deductionRate
netPay = grossPay – deduction
WRITE name, grossPay, deduction, netPay
2. Capitalize initial keyword
In the example above, READ and WRITE are in caps. There are just a few
keywords we will use:
READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE, REPEAT, UNTIL
3. Indent to show hierarchy
We will use a particular indentation pattern in each of the design structures:
SEQUENCE: keep statements that are “stacked” in sequence all starting in the
same column.
SELECTION: indent the statements that fall inside the selection structure, but not
the keywords that form the selection
LOOPING: indent the statements that fall inside the loop, but not the keywords
that form the loop
EX: In the example above, employees whose grossPay is less than 100 do not
have any deduction.
TASK LIST:
Read name, hourly rate, hours worked, deduction rate
Compute gross, deduction, net pay
Is gross >= 100?
YES: calculate deduction
11. UNIT 1 Computing and Programming Fundamentals - BCA151203
11 ASWIN R
NO: no deduction
Write name, gross, deduction, net pay
PSEUDOCODE:
READ name, hourlyRate, hoursWorked,deduction
grossPay = hourlyRate * hoursWorked
IF grossPay>= 100
deduction = grossPay * deductionRate
ELSE
deduction = 0
ENDIF
netPay = grossPay – deduction
WRITE name, grossPay, deduction, netPay
4. End multiline structures
See how the IF/ELSE/ENDIF is constructed above. The ENDIF (or END
whatever) always is in line with the IF (or whatever starts the structure).
5. Keep statements language independent
Resist the urge to write in whatever language you are most comfortable with. Inthe long run, you
will save time! There may be special features available in the language you plan to eventually
write the program in; if you are SURE it will be written in that language, then you can use the
features. If not, then avoid using the special features.
Ex:
12. UNIT 1 Computing and Programming Fundamentals - BCA151203
12 ASWIN R
The pseudocode for this would be:
IF amount < 1000
interestRate = .06 // the “yes” or “true” action
ELSE
interestRate = .10 // the “no” or “false” action
ENDIF
___________________________________________________________________________
Computer Program
• A computer program, or just a program, is a sequence of instructions, written to
perform a specified task on a computer
• The purpose of programming is to find a sequence of instructions that will automate
performing a specific task or solving a given problem.
• Source code is written in one or more programming languages.
• The process of programming thus often requires expertise in many different subjects,
including knowledge of the application domain, specialized algorithms and formal logic.
• Programming involves activities such as analysis, developing understanding, generating
algorithms, verification of requirements of algorithms including their correctness and
resources consumption, and implementation (commonly referred to as coding) of
algorithms in a target programming language.
DEVELOPING A PROGRAM
Program development is an ongoing systematic process that professionals follow as they
plan, implement and evaluate problem statement.
• The process is not confined to a planning cycle.
• It can be applied on a small scale to an individual
program; on a larger scale to an entire enterprise level
software.
• The scope may be different but the principles of
program development remain the same.
13. UNIT 1 Computing and Programming Fundamentals - BCA151203
13 ASWIN R
PDLC (PROGRAM DEVELOPMENT LIFE CYCLE)
• The program development life cycle (PDLC) is an outline of each of the steps used to
build software applications
• SIX STEPS OF PLDC
1. Analyze the problem
2. Design the program
3. Code the program
4. Test and debug the program
5. Formalize the solution
6. Operate and Maintain the program
Analyze the problem
Precisely define the problem to be
solved, and write program specifications
– descriptions of the program’s inputs, processing, outputs, and user interface.
Eg :
Problem : To find the sum of natural numbers
Inputs : 2 positive numbers
Processing : Adding first number and second number and storing/Print the result
User Interface : Any Programming Language (C compiler)
Design the program
Develop a detailed logic plan using a tool such as pseudo code,
flowcharts, object structure diagrams, or event diagrams to group the
program’s activities into modules; devise a method of solution or
algorithm for each module; and test the solution algorithms.
Eg:
14. UNIT 1 Computing and Programming Fundamentals - BCA151203
14 ASWIN R
Code the program
Translate the design into an application using a programming language or application
development tool by creating the user interface and writing code; include internal documentation
– comments and remarks within the code that explain the purpose of code statements.
Eg:
// C Program to add two positive integers
#include<stdio.h>
main()
{
int A, B, TOTAL; // Declare the input variables
printf(“ Enter the first number”);
scanf(%d”, &A); // Get the first input from the user
printf(“ Enter the Second number”);
scanf(%d”, &B); // Get the second input from the user
TOTAL=A+B; // Add the numbers and store it in a variable
printf(“ The Sum of Two numbers is %d”,TOTAL); // Print the output
getch();
}
Test and debug the program
Test the program, finding and correcting errors (debugging) until it is error free and contains
enough safeguards to ensure the desired results.
Formalize the solution
Review and, if necessary, revise internal documentation; formalize and complete end-user
(external) documentation.
Operate and Maintain the program :Provide education and support to end users; correct any
unanticipated errors that emerge and identify user-requested modifications (enhancements). Once
errors or enhancements are identified, the program development life cycle begins again at Step 1.