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

2.1 FundamentalProgrammingConcepts

The document discusses fundamental programming concepts including algorithms, flowcharts, and testing. Algorithms are presented as a detailed sequence of steps to solve problems. Flowcharts provide a visual representation of algorithms and logic. The document also covers unit testing as a method to test individual software components.

Uploaded by

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

2.1 FundamentalProgrammingConcepts

The document discusses fundamental programming concepts including algorithms, flowcharts, and testing. Algorithms are presented as a detailed sequence of steps to solve problems. Flowcharts provide a visual representation of algorithms and logic. The document also covers unit testing as a method to test individual software components.

Uploaded by

ArunRamachandran
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Fundamental Programming Concepts

Programming Techniques

Accenture
Accenture2007
2007All
AllRights
RightsReserved
Reserved

USTGlobal Course Code #IDCGRF001-A1

Course Approach
Learn by Doing
Hands-on programming
Activity-based Learning
Activities are designed to be difficult but doable
Activities have time limits to encourage wise use of
your time
Activities will force you to research on the required
knowledge
Resource-rich Environment
Use available resources (i.e., online/offline materials,
human resources, etc)
Encourage research and learning on your own
Accenture 2007 All Rights Reserved

USTGlobal

Course Approach Contd


Teaching Method
This is not a lecture course!
Lessons serve only as guideposts and reminders, and are
not expected to be complete classes on these topics
Instructors serve mainly as facilitators and knowledge
coaches
Performance Evaluation
Each participant will be evaluated
Participate
Dont just listen to discussions, interact!
If in doubt, ask questions to clarify.
Spot problems and suggest alternatives or workarounds.
Accenture 2007 All Rights Reserved

USTGlobal

Course Approach Contd..


Teamwork
Cooperate, coordinate, collaborate!
Work together to complete the deliverables for the
course.
Be resourceful
Dont ask for answers or solutions, find them!
The course environment provides all the necessary
tools and materials to learn, utilize them well.

Accenture 2007 All Rights Reserved

USTGlobal

Contents
Algorithm
Benefits

of Algorithm
Approaches to Algorithm
Efficiency of Algorithm
Structure of Algorithm
Flowchart
Benefits of Flowchart
Concept of Testing
Unit Testing
Accenture 2007 All Rights Reserved

USTGlobal

Objective
At the end of this section, you should be able to:
Describe and understand the need of
algorithms
Measure the efficiency of Algorithms
Understand the advantages & disadvantages
of Flowcharts
Work with Flowcharts
Describe the concepts of testing
Implement Unit Testing
Accenture 2007 All Rights Reserved

USTGlobal

What is an Algorithm
is detailed sequence of actions to
perform or accomplish some task
An Algorithm is a solution to a problem that is
independent of any programming language.
Algorithm

An algorithm is:

A finite sequence of steps

Each step shall be explicit and unambiguous

For each input, it shall terminate in finite time with output

A program is an algorithm expressed in a programming


USTGlobal
language.

Accenture 2007 All Rights Reserved

Benefits of Algorithm
An

algorithm is a definite procedure for


performing certain task
It is written using simple English sentences
Facilitates

easy development of programs


Iterative refinement
Easy to convert it to a program
It helps resolving complex problems
Review is easier

Accenture 2007 All Rights Reserved

USTGlobal

Analyzing An
Algorithm
There

are different approaches of


algorithm in analyzing a problem.
Empirical (a posteriori) approach
It is a method consisting of programming the
competing techniques and trying them on
different instances

Theoretical (a priori) approach


It determines mathematically the quantity of
resources needed by each algorithm as a
function of the size of the instances

Hybrid approach
Combination of Empirical and theoretical
USTGlobal
approach

Accenture 2007 All Rights Reserved

Algorithm
Complexities
Complexities

are the parameters to capture


the challenges or complications

Few

of the algorithm complexities are


captured based on :
Time Complexities
Is the amount of computer time it needs to run to
completion

Space Complexities
Is the amount of memory it needs to run to completion
Accenture 2007 All Rights Reserved

USTGlobal

10

Structure of an
Algorithm
Algorithm

is Defined in a standard structure


Most of the time it has the following contents

Begin
Step
Control
Comments
Variables
Input / Output
Exit

Algorithm Always Begins with Begin or Start


Algorithm Ends with End or Exit or Stop
Rest of the structure contents are used depending on the
need
Accenture 2007 All Rights Reserved

USTGlobal

11

Structure of an Algorithm - Example 1


Example of an algorithm to find the sum of two numbers
Algorithm Starting
point

num1, num2 are the


variables declared
1.
2.
3.
4.
5.

Begin
Input num1,num2
Sum=num1+num2
Print Sum is= ,Sum
End

End of Algorithm
Accenture 2007 All Rights Reserved

Input is used to
perform read values to
num1 & num2
print is used to
print the output
(result)
USTGlobal

12

Algorithm concepts
There

are three types of algorithm concepts

Sequential
Modules are executed in some sequence/ in a linear
fashion

Selection (Single & Multiple)


Single Alternative
Having a single condition criteria to qualify any test
If( condition is true) then statement is executed

Multi Alternative
Having a multiple conditions to qualify any test

Iterational
Looping statements
Repeat step m thru n ,N times

Accenture 2007 All Rights Reserved

USTGlobal

13

Sequential Algorithm Example 2


Example of an algorithm to read marks of three subjects and to find the
average scored by the student

1.
2.
3.
4.
5.
6.

Begin
Print Enter Marks of 3 subjects
Input Marks1, Marks2, Marks3
AVG = (Marks1+Marks2+Marks3) / 3
Output Average Marks =, AVG
End

Implementation of
Sequential
Algorithm Method
Accenture 2007 All Rights Reserved

Output:

Enter Marks of 3 subjects


60
70
80
Average Marks = 70
USTGlobal

14

Single Alternative Algorithm


Example 3
Example of an algorithm to read marks of three subjects. Find the average
scored by the student, and print pass if the score is more than 50
1.
2.
3.
4.
5.
6.

Begin
Print Enter Marks of 3 subjects
Input Marks1, Marks2, Marks3
Avg = (marks1+marks2+marks3)/3
If (Avg >= 50) Then Print Passed
End

Implementation of
single Alternative
algorithm
Accenture 2007 All Rights Reserved

Output:

Enter Marks of 3 subjects


60
70
80
Passed
USTGlobal

15

Multiple Alternative algorithm


Example 4
Example of an algorithm to read marks of three subjects. Find the average
scored by the student, and print Pass if the score is more than 50
otherwise print Fail

Example:

1.
2.
3.
4.

5.

Begin
Print Enter Marks of 3 subjects
Input marks1, marks2,marks3
Avg=marks1+marks2+marks3)/3
If (Avg >= 50) Then
Print Passed
Else
Print Failed
End

Implementation of
Multiple
Alternative
algorithm
Accenture
2007 All Rights Reserved

Output:

Enter Marks of 3 subjects


40
30
30
Failed
USTGlobal

16

Algorithm Iteration Example 5


Example of an algorithm to read marks of three subjects. Find the average scored
by the student, and print Pass if the score is more than 50 otherwise print Fail for
N number of Students
Begin
1. Print Enter number of students
2. Input N
3. Repeat step 4 thru step 7, N TIMES
4. Print Enter Marks of 3 subjects
5. Input marks1, marks2, marks3
6. Avg = (marks1+marks2+marks3)/3
7. If (Avg >= 50) Then
Print Passed
Else
Print Failed
End-if
8. End
Accenture 2007 All Rights Reserved

Implementation
of Iteration
Algorithm

Enter number of Students 2


Enter Marks of 3 subjects
30 40 50
Failed
Enter Marks of 3 subjects
60 60 70
Passed
USTGlobal

17

Flowcharts
is a graphic representation of the logic
or steps in a program or system
The flowchart can be defined as a diagram of the
problem solving steps in a process
A flowchart is a schematic representation of a
Flowchart

process.

Accenture 2007 All Rights Reserved

USTGlobal

18

Flowchart depictions
Each symbol depicts a
Start End points
process
The start point, end points, Processing Logic
inputs, outputs, etc are
represented by a graphical Input/Output
image
Any flow chart should
Decisions
have
Start in the beginning
Connectors
End to the end of the
flow chart
Flow Line
Depending on the
Loops
requirement, rest of the
Accenture 2007symbols
All Rights Reserved
are used
USTGlobal

19

Flowchart Example 1
Example of Flow chart to read marks of three subjects. Find the average scored
by the student, and print Pass if the score is more than 50 otherwise print Fail
for N number of Students
Start
Enter m1,m2,m3
Avg=m1+m2+m3/3

Avg>50
Fail

pass

end
Accenture 2007 All Rights Reserved

USTGlobal

20

Advantages and Disadvantages


Advantage

Disadvantage

Communication

Complex logic

Effective analysis

Alterations and Modifications


will be difficult

Proper documentation

The essentials of what is done


can easily be lost in the
technical details of how it is
done

Efficient Coding
Proper Debugging
Accenture 2007 All Rights Reserved

USTGlobal

21

Testing
is a process used to help identify the
correctness, completeness and quality of
developed computer software.
Testing is the process of running a system with
the intention of finding errors
It enhances the integrity of a system by detecting
deviations in design and errors in the system.
It aims at detecting error-prone areas, which helps
in the prevention of errors in a system.
Testing also adds value to the product by
conforming to the user requirements.
It is Oriented to 'detection'
Testing

Accenture 2007 All Rights Reserved

USTGlobal

22

Unit Testing
A

unit test is a method of testing the


correctness of a particular module of source code
testing is also known as Component/
Module/ Program Testing

Unit
It

is the most 'micro' scale of testing

The

goal of unit testing is to isolate each part of


the program and show that the individual parts
are correct

Most

thorough look at detail

Accenture 2007 All Rights Reserved

USTGlobal

23

Unit Testing
Entry criteria:
After completion of each class/method, unit
testing should be done.
Exit criteria:
Functionality is achieved
All requirements tested & verified
Result:
No Incorrect data, or data recorded in the wrong
field, account or database
No side-effects or bugs remain vis--vis
functionality
No errors in calculations, formulas or rounding
No
data
corruption errors
Accenture 2007
All Rights
Reserved
USTGlobal
24

Test Cases
case is a set of test inputs, execution
conditions, and expected results developed for a
particular objective, such as to exercise a particular
program path or to verify compliance with a specific
requirement

Test

Test

cases are written for each unit in the main


program

program will execute all the test cases and record


the results .it can be called as a test file.

Test

cases will have Description,


inputs, expected25
USTGlobal

Accenture 2007 All Rights Reserved

Test Case - Example


1.
2.
3.
4.
5.
6.
7.
8.

9.

Begin
Print Enter number of students
Input N
Repeat step 4 thru step 8, N TIMES
Print Enter Marks of 3 subjects
Input marks1, marks2, marks3
Avg = (marks1+marks2+marks3)/3
If (Avg >= 50) Then
Enter number of Students 2
Print Passed
Enter Marks of 3 subjects
Else
30 40 50
Print Failed
Failed
End-if
Enter Marks of 3 subjects
End

Accenture 2007 All Rights Reserved

60 60 70
Passed

USTGlobal

26

Example-test cases
Step
Number

Action /
Description

Input Data

Expected Result

1.001

Enter character

Character : X

Invalid input

1.002

Enter negative
number

Number : X

Negative input

1.003

Enter a special
character

Special character : Invalid input


X

1.004

Enter number

Number : X

Accenture 2007 All Rights Reserved

Correct Input,
should continue the
next stage
USTGlobal

27

Key Points
is detailed sequence of actions to
perform to accomplish some task
Algorithms facilitates easy development of
programs
Algorithm

Flowchart is a graphic representation of the logic or steps in


a program or system

Testing

is the process of running a system with


the intention of finding errors.

Unit testing is used to isolate each part of the program and


show that the individual parts are correct.

Accenture 2007 All Rights Reserved

USTGlobal

28

Programming Life cycle


Programming Techniques

Accenture 2007 All Rights Reserved

USTGlobal

29

Contents
Programming
Programming

Life Cycle
Types of Programming Design

Top-Down Approach
Bottom-Up Approach
Linear Programming
Structured Programming

Accenture 2007 All Rights Reserved

USTGlobal

30

Objectives
At the end of this section, you should be able
to:
Understand what is programming
Work with program life cycle
Understand Different Types of Programming
Design

Top-Down Approach
Bottom-Up Approach
Linear Programming
Structured Programming

Accenture 2007 All Rights Reserved

USTGlobal

31

Programming
A

program is an algorithm expressed in a


programming language

The

act of creating software or some other set


of instructions for a computer

Computer

programming is the craft of


implementing one or more interrelated
algorithms using a particular programming
language to produce a concrete computer
program

Accenture 2007 All Rights Reserved

USTGlobal

32

Program Development Life cycle.


WHAT
Requirement
s
Gathering,
Problem
definition

HOW
Analysis
& Design

DO IT
Build

TEST
Testing

Accenture 2007 All Rights Reserved

Deploy
&
Maintai
n
USTGlobal

USE

33

Program Design Approaches


Different

Types of Programming
Design Approach are

Top- down programming


Bottom-up programming
Linear programming
Structured programming

Accenture 2007 All Rights Reserved

USTGlobal

34

Top down Design

Based on the fact that large problem become more manageable if


they are divided into a number of smaller and simpler tasks which
can be tackled separately.
Top down design approach is performed in a special way.
The main program is written first. It is tested before sub-programs
are written.
To do this, actual sub programs are replaced with stubs.
The stubs tests to see if the data is passed correctly. After the
main program is written and checked, each module is written and
tested in turn.
If the modules run properly, then it is tested with the main
program. If the module and the main run properly then the next
module is written and checked and so

Accenture 2007 All Rights Reserved

USTGlobal

35

Bottom Up Design

Write the most basic subroutines in the hierarchy first and


then use them to make more sophisticated subroutines

The pure bottom-up approach is generally not recommended


because it is difficult to anticipate which low subroutines will
be needed for any particular program

In this approach it is usually assumed that the basic routines


created will be general enough to be used more than once

This approach is designed to generate reusable code

This is more like a basic instruction in the programming


language than a large scale program component.

Accenture 2007 All Rights Reserved

USTGlobal

36

Linear Programming

Straightforward programming in sequential manner


is Linear Programming
This does not involve any decision making.
General model of the linear program is :
Read a data value.
Compute an intermediate result.
Use the intermediate result to compute the
desired answer.
Print the answer.
Stop

Accenture 2007 All Rights Reserved

USTGlobal

37

Structured Programming
The

technique for writing a program using


decisions, branching points, loops, etc. is
called structured programming.

It

in turn result in more complex programs.

There

are procedures that can be used for


writing those complex programs that makes
them much less error prone and much easier
in debug.

Accenture 2007 All Rights Reserved

USTGlobal

38

Program Life Cycle


Req.
Req.
Gathering
Gathering
Algorithm
Algorithm
Test
Test Plan
Plan
Coding
Coding

Pseudo code

Source Code +
Test Script

Compilation
Compilation

Object code
Linking
Linking

Libraries

Accenture 2007 All Rights Reserved

Debugging
Debugging //
Testing
Testing

Executable
File

USTGlobal

39

Program Life cycle


Requirement

Gathering

Gathering all the required information to understand


the problem in hand
Algorithm

An simple English, language independent pseudo


code is generated.
Test

Plan

Gives a plan to test the solution. It involves test


cases, test scripts and test data

Accenture 2007 All Rights Reserved

USTGlobal

40

Program Life cycle


Coding

Enter the source code using some standard editor,


care must be taken for proper formatting, indenting
and using comment entries.
Compilation

The compiler program scans the source code for


SYNTAX errors, and if it does not find any errors, it
converts the source code to OBJECT code.
Link

The object files are combined with other library files


to create the EXECUTABLE file.

Accenture 2007 All Rights Reserved

USTGlobal

41

Program Life Cycle


Library

It is a catalogue of previously developed objects.


They contain procedures for input, output, math, etc.
A user can create their own libraries
Testing

Synthesize test data such that it will evaluate the


different criteria. The testing should be NEGATIVE
testing.
Debugger

It is a very useful tool to test the program as the


intermediate results, new values of the variables, etc
are visible

Accenture 2007 All Rights Reserved

USTGlobal

42

Key Points
A

program is an algorithm expressed in a


programming language
Programming is the craft of implementing one
or more interrelated algorithms using a
particular programming language
Large problem become more manageable if
they are divided into a number of smaller and
simpler tasks which can be tackled separately.
Straightforward programming in sequential
manner is Linear Programming

Accenture 2007 All Rights Reserved

USTGlobal

43

Questions and
Comments

?
?
?

Accenture 2007 All Rights Reserved

USTGlobal

44

You might also like