flowcharting part

37
SAMPLE FLOWCHARTS

Upload: 04502

Post on 13-Jul-2016

9 views

Category:

Documents


1 download

DESCRIPTION

Flowcharting Part

TRANSCRIPT

Page 1: Flowcharting Part

SAMPLE FLOWCHARTS

Page 2: Flowcharting Part

Question 1Draw the program flowchart for finding the sum of first 100 odd numbers.

Page 3: Flowcharting Part

Since we have to find sum of odd numbers it should start from 1. So, our variable should be set as 1

Increment of the variable shall be by 2 The last no the series shall be 199. So we shall check

out counter at 199.

Page 4: Flowcharting Part

Step 4:Since we have to stop at the 100th

terms which is equal to 199,step 4 poses a question. “Has A

become 199 ?” If not, go back to step 3 by forming loop. Thus, A is

repeatedly incremented in step 5 and added to B in step 3. B holds the

cumulative sum upto the latest terms held in A. When A has become 199

that means the necessary computations have been carried out so that in step 6 the result is printed.

Step 5:we shall increment A by 2. So that

although at the moment A is 1, it will be made 3 in step 5 , and so on.

Step 6 :Result is Printed

Step 0 :Use START to start a flowchartStart

Clear all working Locations

Set A=1

B = B+A

?A = 199

Print B

Stop

A = A+2

Yes

No

Step 2:A is set at 1 so that subsequently by incrementing it successively by 2,

we get the wanted odd terms : 1,3,5,7 etc.Step 3:

A is poured into B i.e., added to B. B being 0 at the moment and A being

1, B becomes 0 + 1 = 1.

Step 1 :All working locations are set at zero.This is necessary because if theyare holding some data of theprevious program, that data is liableto corrupt the result of the flowchart.

Solution 1

Page 5: Flowcharting Part

Question 2 There are three quantities; Q1 Q2 and Q3. It is desired to obtain the highest of these in location H and lowest of these in location L.

Page 6: Flowcharting Part

Since we have to obtain highest and lowest of 3 categories, we will check 2 at a time and compare it with third quantity i.e. we shall compare the highest and lowest of the 2 with the 3rd

Highest and lowest values shall change only if 3rd is higher than highest or lower than lowest.

So effectively we shall have 3 decision boxes in the program. To compare 2 and than compare 3rd with highest and with lowest.

Page 7: Flowcharting Part

Start

Clear all working Locations

Read Q1, Q2 and Q3

? Q1 > Q2

H = Q1

L = Q2 L = Q1

H = Q2

Step 1 –The three quantities Q1,

Q2 and Q3 are read in via, say, these values are

enteredthrough keyboard of a

terminal.

Step 2 –Any two quantities, say Q1 and

Q2 are compared. If Q1 is greater than Q2.

Steps 3B and 4BAlternatively we can make H =

Q1 and L = Q2 in

Steps 3A and 4A, we make H = Q2 and L = Q1.

Yes No

Step 0 –All working locations are

assigned to Zero

Solution 2

Page 8: Flowcharting Part

? Q3 > H

L = Q3

? Q3 < L H = Q3

Stop

Step 5, we are holding the

higher of Q1 and Q2 in H and the lower of these in

L. We see if Q3 is greater than H.

Yes

No

Step 8If it’s a Yes, H is made

equal to Q3.

Step 6If Q3 is not greater than H, we compare Q3 with

LStep 7if Q3 < L, we make L = Q3, otherwise, the job

has already beendone prior to Step 5.

No

Yes

Page 9: Flowcharting Part

Question 3 Draw the flowchart for deriving the sum of the squares of first 20 odd numbers.

Page 10: Flowcharting Part

Since we want to calculate sum of 20 odd nos, our variable shall start from 1.

Increment in the variable shall be of 2 units When we accumulate value in another variable, care

should be taken that we add the sum of the number and not original no.

The last no shall be 39. So we have to check counter / variable upto 39. So we will have only 1 decision box.

Page 11: Flowcharting Part

Start

Clear all Working Locations

?K = 39

C =C + Square

PRINTC

END

Square = K * K

Set K = 1

K = K + 2

Step 0All working locations

are assigned the value zeroStep 1

The first odd number is 1 so we set K = 1Step 2

The square of first odd number is computed

by multiplying K with K and the result so

obtained is stored in location SQUARE.Step 3We accumulate the

first term i.e. square of the first odd number 1

in location C.

Step 4The 20th odd number is 39, therefore in this step

we see if K has become 39 or not (by step 5)Step 5

K is increment by 2 i.e. it becomes 1+2 = 3

Yes

No

Solution 3

Page 12: Flowcharting Part

Question 4 The weights of newly born babies in a hospital are input to computer. The hospital in charge is interested to find the maximum, minimum and mean weights of all the weights of the babies. Draw a suitable flow chart for his problem. A value of zero can be used at the end of the list of baby weights. This denotes the end of the list.

Page 13: Flowcharting Part

We have to calculate Minimum, maximum and mean weights. So we have to define 5 variables as follows › Minimum › Maximum› Total› Count› Mean (Total / Count)

Take care that Mean weight can be derived only after we have checked all the weights for minimum / maximum and added it to Total Weight and not at each step.

Page 14: Flowcharting Part

We shall define first weight as Minimum, Maximum and Total and keep comparing each variable to check if its less than minimum or more than maximum, and than we shall add it to total. Also count shall be increased by 1 for every number checked.

Since question says last weight is 0, we shall check if we have reached at weight = 0, once we reach there we shall calculate Mean and Stop. Till than the Loop shall keep running. So effectively we shall have 3 decision boxes same as last ques.

Page 15: Flowcharting Part

START

INPUT W

MINW = WMAXW = WTOTW = W

COUNT = 1

Solution 4

A

Page 16: Flowcharting Part

ISW = 0 ?

MEANW=TOTW/COUNT

ISW <

MINW?

MINW=W

END

ISW >

MAXW?

MAXW=W

TOTW=TOTW WCOUNT=COUNT + 1

PRINTMAXW, MINW,

MEANW

INPUT W A Solution 4 (2)

Yes

Yes

Yes

No

No

No

Page 17: Flowcharting Part

Class No. (K)

Class of Goods Customs duty (%), on Values of Goods (V)

1 Foods, beverages 102 Clothing, footwear 153 Heavy machinery 17.54 Luxury items 40

Question 5 (On computing Customs Duties) Assume that imported goods from foreign countries are classified into 4 categories for the purpose of levying customs duty. The rate for each category is as follows :

Draw the flowchart for computing the appropriate customs duty.

Page 18: Flowcharting Part

We shall use following variable › Value› Rate of Duty› Class

There are broadly 4 classes defined in the question. Since these classes are exhaustive, we need to check only for 3 classes, If it does not fit in 3 classes it has to be in the 4th class. So we shall have 3 decision boxes

Page 19: Flowcharting Part

START

Input Value, Class no, V, K

? K = 1

? K = 2

? K = 3

DUTY =V * 0.4

DUTY =V * 0.1

DUTY =V * 0.15

DUTY =V * 0.175Print

DUTY

LastItem? END

Yes

Yes

Yes

No

No

No

No

Yes

Solution 5

Page 20: Flowcharting Part

Question 6 A bicycle shop in Delhi hires bicycles by the day at different rates as shown in the following table :-

To attract his customers, the proprietor also gives a discount on the number of days a bicycle is hired for. If the hire period is more than 10 days, a reduction of 15% is made. For every bicycle hired, a deposit of Rs 20 must be paid. Develop a flowchart to print out the details for each customer such as name of customer, number of days a bicycle is hired for, hire-charges and total charges including the deposit. It is also assumed that there are 25 customers and complete details for each customer such as name of customer, season and number of days the bicycle is required for is inputted through console.

Season Charges per day (in Rs.)Spring (March - May) 8.00

Summer (June - August) 9.50Autumn (Sept - Nov.) 5.00Winter (Dec. - Feb.) 6.00

Page 21: Flowcharting Part

We shall define/ read following variables › Name› Counter› Season› No of Days › Rate› Net Rate (After Discount)› Hire Charges ( net Rate * No of Days)› Total Hire charges ( Hire Charges + Rs.20)

Page 22: Flowcharting Part

We shall check the season first because firstly there are 4 seasons that need to checked and also, to calculate discount (outcome for no of days condition) we need the rate of bicycle. Rate can be derived only from Season details and so we check season first.

Following points need to be checked for every bicycle.› Season (4 Conditions)› No of Days Hired for (1 Condition)› Last record (1 condition)Thus we shall have 6 condition Boxes

Do not forget to add Rs.20 in total Hire charges

Page 23: Flowcharting Part

START

Read NAME, SEAS, DAYS

Clear all working locations

N = N + 1

SEAS = Spring

SEAS = Summer

SEAS = Autumn

RATE = 8.00

RATE = 9.50

RATE = 5.00

SEAS = Winter RATE = 6.00

Solution 6

A

Yes

Yes

Yes

Yes

No

No

No

No

Page 24: Flowcharting Part

END

NRT = Rate

HCHG = Days * NRTPrint

NAME, DAYS, HCHG, TCHG

TCHG = HCHG +20.00

N >=25

Solution 6 (2)

Print “Invalid Seas”

DAY >10 NRT= RATE-RATE * 0.15

A

B

B

Yes

Yes

No

No

Page 25: Flowcharting Part

In the Next flowchart ,comparison step is initialized and modified for looping. The following is the comprehensive list of comparisons of this type that are valid:J(X) > K(Y)J(X) = K(Y)J(X) ≠ K(Y)J(X) < K(Y)

Page 26: Flowcharting Part

Question 7 Prices for ten commodities in the current year are designated by J(X), X varying from 1 to 10. Likewise, their last year’s prices are designated by K(Y), Y varying from 1 to 10. Draw the flowchart for finding the number, N of commodities of which prices have increased.

Page 27: Flowcharting Part

In array problems, always remember that we shall check the counter upto the no of slots in that array.

Always initiate the position of the cursor in the array i.e. we have set X and Y as 0.

Use only the functions that are permitted to be used in the array.

Page 28: Flowcharting Part

START

Clear all working locations

?J (X)> K(Y)

Print N

Set X = 0

Set Y = 0

Increment X by 1

Increment Y by 1

N = N + 1?X=10

END

Solution 7

Yes

No

No

Yes

Page 29: Flowcharting Part

Question 8 Add 45 (a constant) to the wages of 10 persons designated by J(X), X = 1,2...10

Page 30: Flowcharting Part

In array problems, always remember that we shall check the counter upto the no of slots in that array.

Always initiate the position of the cursor in the array i.e. we have set X as 0.

Use only the functions that are permitted to be used in the array.

Page 31: Flowcharting Part

START

Set X = 0

END

Clear all working locations

Increment X by 1

J (X) = J(X) + 45

?X=10

Solution 8

Yes

No

Page 32: Flowcharting Part

Question 9 Print 6 P’s in the pattern given below

012(print position)p

pp

pp

p007 (print position)

Page 33: Flowcharting Part

In Print problems we always have to define the position at which we want to print the material.

The material that needs to be print has to be put in either commas (‘) or is defined in a variable.

1 Line CS feed function is generally used in Print problems.

Page 34: Flowcharting Part

START

Set Y = 13

END

Clear all working locations

Decrement Y by 1

1 Line CS Feed

?Y=7

Print ‘P’ at Y

Solution 9

Yes

No

Page 35: Flowcharting Part

Question 10In locations J(X), X = 1, 2....200 are held 200 quantities. Draw flowchart for finding the ratio of the total number of quantities indivisible by 10 to that of divisible by 10.

Solution:The following symbols are used in it.NONTEN Total number of items not divisible by 10TENNER Total number of items divisible by 10RATIO Ratio NONTEN/TENNERJ(X), X = 1,2...200 are used to hold the last digit of a quantity.Partial transfer (as we have down in this flowchart) of one or more consecutive digits from one location into another location is valid.

Page 36: Flowcharting Part

When checking whether a no is divisible by other no or not, use standard divisibility tests. Like divisibility test for the no 5 is that last digit should be o or 5. Similarly for no 10 it is that last digit should be 0.

Always keep in mind the things that question asks u to calculate. Define variable for each of the item that is asked.

Counter shall go upto the number of slots in the array. 2 Decision boxes shall be prepared, one to check

divisibility and other for counter .

Page 37: Flowcharting Part

START

Set X = 0

END

Increment X by 1

Transfer last digit of J(X) in J

?J=0

Print RATIO

Increment TENNER by 1

Increment NONTEN by 1

?X=200

RATIO = NONTEN / TENNER

Solution 10

No

No Yes

Yes