Vous êtes sur la page 1sur 39

Programming Logic and Techniques

NIIT

Programming Logic and Techniques 1

Why This Module


The Programming Logic and Techniques (PLT) module is positioned as the entry point into this curriculum. Since this curriculum is designed to cater to aspiring soft are professionals! a strong foundation in programming approaches and application of logic as found essential and as recommended "y the industry.

Linkage with OOPs


In the ##Ps module the students ill "e required to rite programs in$ol$ing the use of programming constructs. The PLT module! apart from teaching pro"lem sol$ing technique li%e flo charting! ill also prepare the students for the ##Ps module "y de$eloping the students a"ility to study pro"lems! understand pro"lems! and represent the logic required to sol$e these pro"lems.

The o"&ecti$e of this module is to familiari'e the students ith the "asic constructs and techniques used in sol$ing pro"lems. Since the entry profile does not e(pect the student to ha$e any e(posure to programming the module starts from the $ery "asics of flo charting and ta%es the student gradually through higher le$els of pro"lem sol$ing through flo charts.

) student ho registers for the PLT module should "e*

+amiliar ith the $arious parts of the computer and should %no the "asic difference "et een hard are and soft are. )"le to interact in ,nglish in a classroom en$ironment "ecause the classes ill "e conducted in ,nglish. The course are ill also "e in ,nglish. The sessions ill "e interacti$e in nature.

- Programming Logic and Techniques

NIIT

.omforta"le or%ing in the /indo s en$ironment. 0no ledge of 1S #ffice ould "e an added ad$antage.

)t the end of this module! the students ill "e a"le to*

.reate flo charts to sol$e pro"lems.

0no ledge acquired*

Sym"ols used in flo charting Sequencing the tas%s to "e carried out 2ecision ma%ing using flo charts Iteration using flo charts Identification of 3aria"les and constants 2ata types #rgani'ing and carrying out .onditional e(ecution Iteration Implementing procedures .oncept of a dry run

)s faculty you might find the contents of this module are light and may feel the need for greater depth of co$erage. Please remem"er that this is the first e(posure to programming for most students and e must concentrate on ensuring the follo ing*

They are $ery confident of analy'ing pro"lems and de$eloping solutions using the constructs learned They find it a $ery en&oya"le and enriching e(perience

NIIT

Programming Logic and Techniques 4


module

They ha$e had a taste of 5programming6! and loo% for ard to more of it in the ##Ps

7emem"er! once they start en&oying dra ing flo charts and learning the logic of programs they ill "e sufficiently moti$ated to put in more effort to learn more in the further modules. Therefore! if you get them hoo%ed right here! you ha$e on half your "attle. 1a%e sure that you do not go o$er"oard in gi$ing inputs. Let them apply logic from their e$eryday e(perience. Pre$ent yourself from lapsing "ac% into the topic8centered approach. +ocus on tas%s! and the %no ledge required for accomplishing those tas%s.

Lesson One
Experiences
2uring the )nalysis phase of course are de$elopment! e conducted se$eral inter$ie s ith pro&ect managers in the soft are industry. They told us that they found programming logic and s%ills lac%ing in many of the ne recruits. They suggested that this module needs to "e gi$en a lot of emphasis. People anted to %no hy are e teaching flo charts. 1any people are under the impression that flo charts are not used in the soft are industry. 9ut the fact re$ealed during our analysis confirmed that flo charts are used e(tensi$ely in soft are de$elopment.

Examples and Analogies


:uite often! people ho are riting algorithms for the first time! tend to s%ip small steps assuming that they ill happen automatically. #ne $ery common error is to s%ip the display statement! to display $alues that ha$e "een calculated. Some students rite the complete logic to accept a set of $alues and perform ela"orate calculations! "ut s%ip the display statement. ;ou can as% them ho they ould feel if the program to generate their pay chec%s calculated the monthly pay! the ta( and other deductions "ut missed out on the instruction to print the salary amount on the chec%. ;ou could use the follo ing analogy to illustrate the point. I had a ser$ant called 7o"ert. I once told him to go to the shop do n the road and "uy a pac% of "iscuits. <e left immediately. 1any hours later there as no sign of him. I set out in search of him. I al%ed to ards the shop and as a"out to as% the shop o ner a"out 7o"ert! hen I sa him standing close "y ith a pac% of "iscuits in his hand. /hen I as%ed hat as rong! he told me that as instructed he had "ought the pac% of "iscuits. )s he did not ha$e any further instructions! he &ust aited there. I had missed one important instruction = to return home and gi$e me the "iscuits. #"$iously this is a fictitious e(ample! "ut is $ery representati$e of hat could happen if an instruction is missed.

FA

> Programming Logic and Techniques

NIIT

: 1. )re flo charts actually used "y soft are de$elopers? ) 1. ;es! they are. ) flo chart is a graphic tool! it is easier to communicate the logic using a flo chart. : -. /hat is the con$ention used for the flo lines in a flo chart? ) -. @enerally! the lines flo from top to "ottom and left to right.

Additional !nputs
)s the programming logic is introduced for the first time! spend time on e(plaining the sym"ols used in a flo chart. /hen flo chart and its $arious sym"ols are introduced! discuss the $arious %ey ords associated ith the input! process! and output. +or e(ample! get! accept! and input can "e used for input of data.

"olutions# $ust a Minute%


1atch the follo ing $er"s ith appropriate sym"ols* @et! /rite! Stop! )dd! Start! 1ultiply! 7ead! Su"tract! 2i$ide! 2isplay! Input! #utput! If.
S. No. Symbol Activity

1.

-.

4.

>.

NIIT

Programming Logic and Techniques A

A.

"olution#
1. -. 4. >. A. If )dd! 1ultiply! Su"tract! 2i$ide @et! 7ead! Input Stop! Start /rite! 2isplay! #utput

&'P'&
Procedure of Admission in NIIT

&'P'(
The correct steps are*

B Programming Logic and Techniques

NIIT

1. -. 4. >. A. B.

Start @et the +irst Num"er @et the Second Num"er )dd the T o Num"ers 2isplay the 7esult Stop

Sequence of Steps to Add Two Numbers

NIIT

Programming Logic and Techniques C

&'P')
Display the Sum of Five Numbers

D Programming Logic and Techniques

NIIT

&'P'*
Display the Product of 2 and a Specified Number

NIIT

Programming Logic and Techniques E

Lesson Two
Experiences
/hile introducing relational operators! you need not introduce all the relational operators. #nly introduce those that are required for the e(ample gi$en. Since you already %no programming languages! you might ha$e a perception that the character datatype can store only one character. <o e$er as far as the PLT module is concerned! a $aria"le of character datatype can store one or more characters. The student may ha$e difficulty in using the naming con$ention. The con$ention that is used is the hungarian notation. ;ou may need to enforce it as it is one of the "est practices follo ed "y soft are de$elopers. ;ou may need to e(plain the difference "et een datatypes and hen to use hich datatype. Since the flo chart is a graphic tool! it is easier to communicate and document the logic! using flo charts.

Additional !nputs
The faculty should e(plain the purpose of connectors gi$en in the slides. These are not used in the student guide! as the flo chart comes in one page itself.

FA
: 1. /hat do dotted lines in a flo chart indicate? ) 1. 2otted lines indicate that the flo chart is not complete "ut is a flo chart segment that has only the rele$ant steps depicted.

"olutions# $ust a Minute%


Identify the $aria"le and constant data in the follo ing situation* ,ach day! the courier ser$ice deli$ers some letters. The num"er of letters is different each day. 7egardless of the num"er of letters deli$ered "y the courier ser$ice! they are paid a carrying charge of FA. 3aria"le* .onstant*

"olution#
3aria"le* Num"er of letters .onstant* .arrying charge FA

1G Programming Logic and Techniques

NIIT

$ust a Minute%
Identify the $aria"les and constants from the list gi$en "elo * a) )ge

") )ddress c) -1

d) H1G! 0ings ay .ampI e) f) H<enriI Name

g) H1DAI

"olution#
.onstants* -1! H1G! 0ings ay .ampI! H<enriI! H1DAI 3aria"les* )ge! )ddress! Name.

$ust a Minute%
2ra a flo chart to accept item name! price! and quantity. ;ou need to calculate $alue as the product of price and quantity! and display the calculated $alue and the item name using $aria"les.

NIIT

Programming Logic and Techniques 11

"olution#
Display the alue of an Item

('P'&
a) #0

") 7,J,.T c) @##2

('P'(
a) @##2 ill "e printed! since nKLn; and nKL1GG.

") Nothing ill "e printed (e$en though nK is greater than n;! it is still less than 1GG). c) Nothing ill "e printed (e$en though n; is greater than nK! it is still less than 1GG).

1- Programming Logic and Techniques

NIIT

('P')
Find !ut if a Number is Divisible by "

NIIT

Programming Logic and Techniques 14

('P'*
Display the #ar$est of the Three Numbers

1> Programming Logic and Techniques

NIIT

('P'+
%hec& if the A$e is Ne$ative

NIIT

Programming Logic and Techniques 1A

F A,-LT. O/"E01AT!O2"

1B Programming Logic and Techniques

NIIT

Lesson Three
Experiences
;ou may need to spend time on e(plaining iteration as some students may find it difficult to grasp. ;ou may need to spend time on e(plaining the concept of modules or procedures. ;ou ill also need to e(plain to the students the use of the sym"ol used for depicting procedures in flo charts! since this is the first time they ill "e using this sym"ol.

Examples and Analogies


Since 5procedures6 is a ne concept! you ill need to gi$e some simple e(amples to understand this concept. I often use this e(ample. I ha$e a dog at home. ,$ery morning the first thing I do is call out to the dog and as% it to fetch me the ne spaper. So fetching the morning ne spaper is a procedure that I can call e$eryday.

Additional !nputs
)fter the completion of an e(ample! you should ta%e the test case $alues and do a step "y step dry run! so that the students are familiar ith the dry run process and are clear on ho to chec% the flo of control.

NIIT

Programming Logic and Techniques 1C

"olutions#
)'P'&
Display the Product of Ten 'ven Numbers

1D Programming Logic and Techniques

NIIT

)'P'(
%ount the Number of !dd and 'ven Numbers

NIIT

Programming Logic and Techniques 1E

)'P')
Display the (i$hest of any Ten Numbers

-G Programming Logic and Techniques

NIIT

)'P'*

)odular Pro$rammin$

NIIT

Programming Logic and Techniques -1

)'P'+
The names ill "e displayed infinite num"er of times! as the $alue of n.ounter does not change. The $alue of n.ounter ill remain G and the condition ill ne$er "ecome false. So the loop ill ne$er terminate. This is an infinite loop.

-- Programming Logic and Techniques

NIIT

FA,-LT. O/"E01AT!O2"

NIIT

Programming Logic and Techniques -4

O/"E01AT!O2"

Lesson One
"olutions#
&'
Display Name and A$e

('
Display the Product of Two Numbers

-> Programming Logic and Techniques

NIIT

NIIT

Programming Logic and Techniques -A

Lesson Two
"olutions#
&'
%hec& if First Number is Divisible by the Second

-B Programming Logic and Techniques

NIIT

('
Display the Day of the *ee&

NIIT

Programming Logic and Techniques -C

)'
%alculate the Area

*'
%onvert the Temperature from Fahrenheit to %elsius

-D Programming Logic and Techniques

NIIT

+'
Display the #owest of the Three Numbers

NIIT

Programming Logic and Techniques -E

Lesson Three
"olutions#
&'
Display the Avera$e of First Ten !dd Numbers

4G Programming Logic and Techniques

NIIT

('
Display the Square of the First +,, Natural Numbers

NIIT

Programming Logic and Techniques 41

)'
Display Fibonacci Series

4- Programming Logic and Techniques

NIIT

*'
Display Total Number of %alls

NIIT

Programming Logic and Techniques 44

+'
%alculate the Net Price of a -oo&

4> Programming Logic and Techniques

NIIT

NIIT

Programming Logic and Techniques 4A

3'
Display the Status of the Stores Department

4B Programming Logic and Techniques

NIIT

4'
Display the Sale Price

NIIT

Programming Logic and Techniques 4C

5'
%alculate the Avera$e )ar&s of Students

4D Programming Logic and Techniques

NIIT

Cycle # Cycle1 OCR1

Activity/Problem No.

Duration (In Mins)

Lesson 1: Objectives Input, Process, and Output Programs Problem-Solving Techni ues 1"P"1 1"P"$ 1"P"! 1"P"% Summar& otal Cycle# OCR1 Lesson $: Objectives 'ariables and (onstants )ata T&pes *sing Operators +epresenting )ecisions in a ,lo-chart $"P"1 $"P"$ $"P"! $"P"% $"P"5 Summar& otal Cycle$ OCR1 Lesson !: Objectives )r& +un Iteration .odular /pproach to Programming !"P"1 !"P"$ !"P"! !"P"% !"P"5 Summar& otal

5 5 5 !5 1# 5 5 5 5 !"

5 15 5 15 !5 5 5 1# 1# 1# 5 1#"

5 $# $5 $# 1# 1# 1# 1# 5 5 1#"

NIIT

Programming Logic and Techniques 4E

Vous aimerez peut-être aussi