Sei sulla pagina 1di 23

Flow chart and algorithm Development of algorithms for

simple problems

References:
Programming in ANSI C E-balaguruswamy
ANSI C programming Language Dennis M Richie
Internet web sites are useful
vinayan Ap in IT

Learning outcomes
1.understand characteristics associated with flow
charts and pseudo code
2.understand role of step wise refinement in
developing algorithms
3.distinguish type of errors at the time of compilation
4.understand components of problem
solving,program design,algorithm development
5.understand type of errors produced by o/p
program

vinayan Ap in IT

Assesment plan
1.quiz
2.assignments(individual/group)
3.home works
4.match table
5.verify solution

vinayan Ap in IT

Introduction

-) program is specific set of structured operation to be performed by a


computer
procedural programming
-)perform ,present steps needed to solve a problem in sequential & logical
manner
Eg. to bake a cake [steps needed to be followed in the order]
-)easy way to point out potential problem areas
-)it is having nice aspect about problem solving,program design and algorithm
development

vinayan Ap in IT

Problem solving

-> need a strategy for solving a problem


video of planning
step1:define the problem
->error here is costly to both time & money
->determine what we are trying to accomplish
Eg.friend asked to plan a simple party for her birthday
[plan friends birthday party]
step2:requirement specification
->remove all ambiguities in problem definition
->determine output or result required
->determine what input needed & sources of input(key board/file)
input(I) ->process(P)->Output(O)
->refiniting & identifying requirements for the party
Eg:21st birth day,female friend,small group of attendees,food & beverages will be provided
->finalizing date & time of event ,clear goal & anticipated timeline& no of attendies& food
Eg:21st birthday,female friend,14 attendees,black forest cake,Lime juice,party will be friday at
7.pm,location my house
->ambiguities are removed from problem statement

vinayan Ap in IT

Step3: design

->develop algorithm for small piece of your problem(pseudo code to


represent algorithm)
->pseudocode is written list of steps need to solve problem
->once algorithm is completed use some sample data to validate
result manually
->1.accounted all required inputs
2.completed all processing steps
3.addressed all issues to generate output identified in requirement
specification
Eg:1)calculate ingredients,2)go to store,3)purchase,4)come
home,5)measure & arrange all ingredients
->suddenly you got issue and want to go to delhi,will not be a
problem .you can ask a friend to continue the algorithms , he need
not to be worried about amount of ingredient
that
vinayan
Ap inis
IT done in
requrement specification part

Step 4:implementation
->write source code based on algorithm developed in
site
-> integrate newly generated code into existing code
Eg1. Ur friend follows steps and bake the cake as
directed.
Accumulation of different components help to make
dessert
Step-5 testing and verification
->make shure program works & produce correct
output(any hacking)
->if error goes to step 3
vinayan Ap it
in ITfrom oven
->Eg.once the cake is done ,remove
,sampling the crumbs inside the pan

Step6:Repeat step3-5
once ur code tested sufficently determine next piece
of solution implemented & repeat step3-5
Eg1. For the next item in our menu now repeat
previous steps .focussing ur energies to make punch
step7:Maintenance
->program need to be revised & enhanced over time
->keeping design document providing readable
source code makes productive less time consuming
Eg1.altering or experimenting some of the ingrediants
used in desert
vinayan Ap in IT

Activity 1 (Quiz )relate table ?


Step1:Define the problem
Step2:Requirement specification
Step3:Design
Step4:Implementation
Step5:Testing & verification
Step6:Repeat step3-5
Step7:Maintenance
1.writing pseudo code
2.clarifying problem statement with your client
3.Writing C++ code
4.determining what information is neede from the user
5.determining what problem needed to be solved
6.identifying what outputs are generated by the program
7.Running program & determing works correctly
8.
vinayan Ap in IT

Flow chart
->problem: if test taker had a score above 90 excellent job if test taker
scores below 90 try little harder
->Termination -marks start & end of flow chart
->Process:activity associated with mapping of data
->Decision-illustriates flow solution based on true or a false condition
->input/output:show reading data or display result

Input/output

process

Decision

vinayan Ap in Termination
IT

Start

Display
enter score

Read
score

Display
excellent job

If score>90

Display
try little harder

vinayan Ap in IT

Exit

Pseudo code

->english representation of algorithm


Display prompt Enter score
Read from keyboard
if score >90
display excellent job
else
display try little harder
vinayan Ap in IT

Activity 2:(match left & right)

Form of algorithm in english

Decision symbol

Writing source code

Design phase

Revised over time

termination

Trial & error (hacking)

Requirement specification

Verifying logic of your solution

Flow chart

Symbol used in beginning

sequential

Mapping of data

Desk checking

Procedural programming

implementation

Determine output

testing

True/false

process

Form of algorithm uses symbols

Pseudo code

Develop algorithm

maintenance

vinayan Ap in IT

Problem solving applied

Problem statement:
your friend operates a business she asked you to create an algorithm
outline steps needed to calculate total kilometer expenses for her tax
return.this year IRS allows .585 rs for a kilometer for business related
travel.this will change every year,your solution should simply ask her for
that information .she would like to be able to enter amount of kilometers
she traveld for business & calculate total mileage expenses.
Develop pseudo solution?
Input type

data

source

Decimal

Km traveled

keyboard

Decimal

Km rate

keyboard

Requirement specification
Inputs

output

Output type

data

destination

Decimal

Km traveled

screen

Decimal

Km rate

screen

Decimal

Km expense vinayan
screen
Ap in IT
allowense

Design
Required formulas:
kmExpenseAllowance=km
traveled *km rate
Pseudocode:

--output phase-Display km traveled


Display km traveled
Display km rate
Display km rate
Display total IRS km allowance
Display total IRS km allowance

--input phase---

Testing verification

Display prompt enter km traveled


for business

Desk checking:

read km traveled

Are all inputs accounted for ?Yes


Are prompts self describing
has all required processing been computed?yes

Display prompt enter in the IRS


km rate

is all of the processing correct?use 496 kms @ .


585 rs a km

read km traveled

Kmexpenseallowance=496 * .585 =290.16

--process phase--

---Validation correct---

kmexpenseallowance=kmtraveled
*kmrate

---Validation--

is all output from output phase self describing ?yes


---Pseudocode correction--None needed
vinayan Ap in IT

Activity 3: verify solution


1.verify solution is correct.if it is not correct rewrite pseudo code
problem:read test score & determine what grade of a student?
90+ ->A 80+->B 70+ ->C 60 +->D
score less than 60 ->F
solution:
input:decimal no for test score
output:a letter of grade
pseudo code:
print prompt enter score
read score
if score >90
print A
if score >80 and score <90
print B
if score >70 and score <80
print C
if score >60 and score <70
print D
if score <60
Print F

vinayan Ap in IT

Assignment 1(individual)

1.Write pseudo code for adding 2 numbers?


2.Write pseudo code for find average of 3
numbers(10,100,1000)and print results
3.assume you take 3 exams ,write pseudo
code solution to calculate sum and average of
your exam scores

vinayan Ap in IT

Assignment 2(Group)

1.Your friend trying to write pseudocode solution to find sum of first 5


natural no's
a)is solution logically correct?if not ,what is wrong & how you correct it
b)how u able to prove her solution works?
c)suggestions to improve overall readabilty of pseudo code?
Problem:print out sum of first 5 +ve non-zero integers
SET x to 0
SET n to 0
WHILE n<5
ADD n to x
Print out x
write response to question a,b,c?

vinayan Ap in IT

Assignment 3(individual):

Write down probem statement,requirement specification & flow chart for


following problems
1. write down factorial of a no?
2. write down whether given no is odd/even
3. write down whether given no is prime or not
4. given radius of circle write a program to display area
5. write a program to pattern of asteriks as shown below? No of asteriks in
bottom is given
*
**
***
****
*****
******
vinayan Ap in IT

Running the program

Syntax error
->found during compilation process
->if severity is less compiler give warning
->caused by incorrect in mecanics of statements
Linker error
->encountered during build process
->linkers job to build executable from object code
->no tools allow you to jump to the line that caused error
->Link error must be corrected before execution of program
Run-Time-Error
->if a program terminates/crashes during execution then you have run time error
->error may be dividing zero/accessing outside memory
->debugger is set of tools help programmer to locate bugs
Logic error
->most difficult error
->stepwise refinement helps by confining logic error to localized area
->debugger is crucial tool helping locate logic error

vinayan Ap in IT

Assignment 4 (answer following)


1.What type of error can be resolved before executable can be created
2.what type of error debugger help find?
3.why is it important that first syntax error corrected and then program
recompiled?
4.what type of error would you get if you forget to include required
semicolon at the end of statement?
5.what you mean by desk checking

vinayan Ap in IT

Assignment 5(Group)

1.What are common programming errors?Explain each?


a)missing semicolon
b)missing braces
c)missing quotes
d)misusing quotes
e)improper comment characters
f)undeclared variables
g)forgetting precedence operators
h)ignoring order of evaluation of increment/decrement operators
i)forgetting to declare function parameters
j)mismatching function arguments
.................
etc
Ap in IT
Ref:page(441-448)programming in ANSI C Evinayan
Balaguruswamy

vinayan Ap in IT

Potrebbero piacerti anche