Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
600 views
266 pages
Simple Logic Programming Formulation
Study Flow Chart
Uploaded by
JohnLeonardTernida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Simple Logic Programming Formulation For Later
Download
Save
Save Simple Logic Programming Formulation For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
600 views
266 pages
Simple Logic Programming Formulation
Study Flow Chart
Uploaded by
JohnLeonardTernida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Simple Logic Programming Formulation For Later
Carousel Previous
Carousel Next
Download
Save
Save Simple Logic Programming Formulation For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 266
Search
Fullscreen
ES ee PHIL. COPYRIGHT 2008 Sy: Andes Mountain Printers Printed May, 2004 SIMPLE PROGRAM & LOGIC FORMULATION ISBN 971-8523-24-3 eS ij “Sy ALL RIGHTS RESERVED NO PORTION OF THIS BOOK MAY BE COPIED, REPRODUCED IN BOOKS, OR PAMPHLETS WHETHER PRINTED, MIMEOGRAPHED, TYPE- WRITTEN, XEROXED OR IN ANY OTHER FORM OF DISTRIBUTION OR SALE, WITHOUT THE WRITTEN PERMISSION OF THE AUTHOR. Edited by: Juvy Basbas De La Rosa Published & Distributed by: Andes Mountain Printers #25 I. Francisco St., Malinta, Valenzuela City Tel. # (02) 291-0313 Fax # (02) 291-0303 Cell # 0915-3759455 3= To my wife Juvy Basbas De La Rosa and our angels Jecelie Claire and Julian Pauline oeACKNOWLEDGMENT My sincerest gratitade to all the people who served as slaty in the fulfillment of this writing Sheryl Basbas, Jam Cadainggan, Jon Gaddy, Antonio Dungea, Rommel Espinosa, Erwin Mendoza, Alan Pacion, Alvin © Limpin, Harvey H. Sadiaca, Elmer G. Cruz, Reggie Exposa, Benjamin Santillan, Piel Javier, Dennis: Reyes, Jim Pangan, Glenn Gutay, Armold Alcodis, Mike Gerard Galon, Rundy Aguas, Alan Aguas, Eric Ambrocio, Dino ‘Quintans, Anne Mane Tongson, Cholet Ballesteros, Abel Reyes, Terence CGuanio, Susan Guania, Ryan Brozo, AB Arias, C) Aguirre, Vher Agbay, Ofed Ousilla, Cecile Lopez. 10 Nadora, Members of The Fisherman's Antiphon, Prends from Silliman University, Marexans, and Tony Andes Sr. for all the inputs, support, and encouragement. Bolet P. Calleja for his 64-bit worth of wisdom, comtineoas guidance, and untelfich sharing of knowledge. My Master in Information Management students, o realization of Tacit to Explici Knowledge transformation. My family, Jun, Arceli, Mama Cita, Jacel, Jeffrey, Susan, Rene, Venus, Vener, Marci, Joy, Agnes and Romnie for all the inspirutions. Above all, to our GOD ALMIGHTY for all the blessings To God be the glory!!!JERALD HERRERA DE LA ROSA Hic iso certified! 80 90012000 — Quality Management S94 n Auditor, ISO S200 — Quality M. 0 Systems for Software Organization Awditor, and the } Lope Excellence Awanl (HEA) Assessor using the Haropean Foundation & Quality Management (EPOM) Model He received his Bachelor of Science in Computer eno degree and Master in Business Management from Saint Francis of ‘College System, Master of Arts in Extension Administration from th Silliman University 2s CHED-PAPE scholar, and Masier in leformoedio Management from Asia Pacific College He was the former Asiistant Director of the | Vice-President for N.C.R. of the Philippine Instinte of (Comp Engineers (PhICEs) for several years, ] At present, he bolls ihe followi Hie! Management Director at Global Idealopy “Corson es ant at the European Chamber of Commerce of th Cae Che eas, Meupement Prof seagreciee College Graduate School o Crmaation hf PC Computer Science and Se eeeCHAPTER 1 CHAPTER 2 CHAPTER 3 (CHAPTER 4 CHAPTER 5 (CHAPTER 6 CHAPTER? CHAPTER 8 CHAPTERS TABLE OF CONTENTS Introduction, Basic Symbols and Variables Working with Process Symbol jeoeewen and Process Decision Application Loops and ltaration Switch Functions Arrays Working with Arrays & & & 48 111 141 199CHAPTER 1 Introduction, | Basic Symbols and VariablesIn this. lnowledge em, on: cannot live wiihout technology. 1 fealty Tot technology is now-a way of life, It is a ificant component of our daily existence. It has revohstionized vay Of doing things — household chores, bosiness,. leisure, pmunecation, travel, amd all ith wherin push-button Me electromc cowipment is present. Have we about the things that made these techaologies'’ Howe we er asked what were itv fonm, jook, and fonmat before if was allied -choology? This curiosaty weld jead os to the world of “behinal the scene” ‘This “behind the scene” is daven by 2 COMPUTER RAM to implement action and procosses that are happening i technology response takes place. Just like wetching 2 We know that when we switch the igniter on, a Mlame bumer, but have we ever thought of understanding the » that takes place in lighting the gas stove? What abot the. behavior anc format of the source where the flame came ? Let's look at the “behind the scene” proces: of the gas-stove mple. When the igniter of the gzs-stove is switched on, the gas gece ool of the unk: the gas flows through the rubber pips and goes directly to the barnes; it passes through an electronic igniter and produces the flame. f This: “behind the sccm: Simdents understanding of the technologies are providing. Ir procures on bow theses techs the students in the different cy of Coomputer Programming from the resources used for processing, how it ic processed, when if is to be processed, the owlput of ihe propes:, and the figel thor drives the process focus of this book, the and’ processes thea me the stop-by-siop reality. Ut will assist This book will alse poide studenia to appreciaic the Analysis side of programming. This will also facilriate to the Muibers the simplest way ol appreciating and learning the “behind the scene” of technology To grasp knowledge of "behiew! the seene”, this hook will eo ton called: “fhewchartiti!) White ‘bisal” Wall help beginmicrs*7 ef coving. hig jake-cf b . = 7 h a) and cay a nit t : a aeationn ot the woy and eins with “STARTS 9 journey, se ag cing Us Oo the, Compater Sysem ‘or Wihen wo are the first. instinct thal comets ed as to ee aE c When we have the calculator, there are (hings. thal we think and do insamtancously. “The fire resgetice 1 automatic. We 1 i j analyze the objective by identifyung the mathemalical operating needed (edition, = subtraction, muiliplicaleon, civiseia, exponentiation, tc.) thes, we imput the data to be computed by pressing the barton that repeesents the. mumbers i mathemarcal operations, we then press the equal sign baton precess the inputted. manibere The result is then shown one display panel of the cabealator: ibis result whether comec © emronedus is What we call onipul given an obpective 0 compuille large munibers, te oar The relationship of the input, process, and @ components producing the result doesn't stop there, The outpull we on our cabculsior can be two things, first is the inconreet and second is the correct result We pet incorrect newalt, wire: y y input wrong data by pressing either the wrong vedor by pressing wrong mathematical operas beading to either negauve value or error result. ¥ Lz7 ef coving. hig jake-cf b . = 7 h a) and cay a nit t : a aeationn ot the woy and eins with “STARTS 9 journey, se ag cing Us Oo the, Compater Sysem ‘or Wihen wo are the first. instinct thal comets ed as to ee aE c When we have the calculator, there are (hings. thal we think and do insamtancously. “The fire resgetice 1 automatic. We 1 i j analyze the objective by identifyung the mathemalical operating needed (edition, = subtraction, muiliplicaleon, civiseia, exponentiation, tc.) thes, we imput the data to be computed by pressing the barton that repeesents the. mumbers i mathemarcal operations, we then press the equal sign baton precess the inputted. manibere The result is then shown one display panel of the cabealator: ibis result whether comec © emronedus is What we call onipul given an obpective 0 compuille large munibers, te oar The relationship of the input, process, and @ components producing the result doesn't stop there, The outpull we on our cabculsior can be two things, first is the inconreet and second is the correct result We pet incorrect newalt, wire: y y input wrong data by pressing either the wrong vedor by pressing wrong mathematical operas beading to either negauve value or error result. ¥ LzWe get comect reeeli from oar caloubation TASfinct Somes into our mind: we either use the reall again InPuE cae SOMmPputabon. or in the memory for fiature ¢ i These outpat whether ‘OOrrect incarect, and whether used as input for . feedback component of the Fig. 1, Components of a Computer System The Blue Print The relationship of the componcats is the bloe print of o computer system. Blue print is the bogic and ides transformed into aomap of bow compulcr should do things It is implemented software (instructions that tells the computer what to do) and executed through the interaction of different hardware devices (physical computer itself). Blue print also serves as the bass of how a computer functions, and how data are processed insde the COMPLE, Let os step backward, recall a eee i mouse to for = key in using a keyboard or ingut pone characters. ‘The entered data is then processed by the Central Processing Unit (C.P.U,). ‘The C.P.U. inside the compater box is just a tiny square piece of Integrated Circuit attached oa the mother rEa ai jon board that normally has ® dimension in size, its functions 10 the com e computer- functions as the brain of th ents Central Processing Unit Compom The & iain (C.P-o) has different components that OE Ts These components are: xecute instruc (ors. work cooperatively to € The command center of processor. It has three primary functions: read and interp instructions. direct flow of operations | and hardw devices, and control the traffic flow of instructions 2 data g Register a Control Unit (C.U.) A temporary storage microchip that holds d during processing. {t 18 located inside the CPU and has tt game function that of a memory, specifically the type (R.A.M.) because of its vola Random Access Memory Us. I character. This type of memory has a capability t temporarily holds data during processing, but the data stored are also lost once electric current is turned off; a a Arithmetic and Logic Unit (A.L.U.) - The most signifi component inside the C.P.U. for our iearning of the “t the scene”. It is the chief of operations of the comp A.L.U. performs two major operations in processing dé i mathematical computations (addition, —_ subtrac multiplication, and division) and logical opera (comparisons of data such as; greater than, less than, greater than or equal to, and less than or equal to). processing are the main concentration of how a ce pee data, and is the foundation of the “aml ne PTT ANC] Litas pee 14Behind the seese in acthon As we have read, the tue print of bebind the scene, i Should be clear by now why a compedter is defined at an porerinia devier that can accept, process, and sore vast amouniof data to prxtuce useful information, (Let further better grasp of behind the scene, oe eo Computer programmers writt computer instreations in COmpuler programming langwage. Just as poopie speak their native diaect, PrOQramMers write programe in different langeages: some examples am C#, C++, Visual Basic, Java, PHP ond COBOL No mater which programming lasguage o eOnipuler Programmer uses, the language has rules goveming its terminology and punctuations ‘These rules are called syeroe. Syrtnx is set of rules that povern a programming language, Take note that every programming language is unique and have their specific set of symlas, When ideas are converted imo a computer program, it is sent to the CPU for proocssiag. However, the CPU cannot untersiand the code (computer program) and will not do amything because of language incompatibility. For the CPU to understand the code, @ Language translator is neoded, The language translator ovftware is called compiler or interpreter, The role of compiler is jo transform the code info a muichine language (series of 1's and O's to represent ON and OFF states of the computer devices. It is also the representation of the digital electronic changes inside the computer), Qnce the code is compiled, 11 changes its form. from computer program with strict symiax to a readable machine language that can be interpreted by the CPU. (CPU then executes the instructions and performs the tasks. Lifeblood of a Computer System cuted b the CPU vary from simple scoeptance of data gree raorathe cof different files, Whatever task the 43cri «ine ihe nee weripuect empowers perio cafe We hal What carpus & 5 Wh nese!’ & Wh , needed to produce the Supa? Where shoulel the output go? We can mow agree thal the compuler ode is the: fi powers the computer. IL is now the role of behind the tranuiaie these ideas into a form that is easier to illastn understand. Behind the scene can be illustrated, by the te flowcharts. Flowehart ix a modeling toal used to iihust instnictions, process, and scquence using a set of sm symbols. In the world of computers we cam simply Sa flowchart is a step-by-step graphical representation of a oka The basic symbols used in programming are presemed in TableTable 1. Baste Flowchart Symeheals it Sa MBC NAME T Defines the | TERMINAL, | Sting asd ending | point of a 5 fhoewchart. | The preparation ox | ‘ S| INITIALIZATION. |, [Biialization of memory apace for | | data procesting | The inputting of | ee | | data for / / INFUTAOUTPUT | processing, und the | printing cat of | processed dala. 1 | | Manipulation af — Bk | data (asignments PROCESS and mathcroaical | computabions} | | { + | Defines the logical | 7 | of the JW LINES program. It pours = tothe neat syonib to be performed.NAME. a evamor | one f Aowchart 16 aj . iE | On - PAG i qc TOR oonmecthana » | cONNE sain pee Comnects flowchart i OFF - PAGE different CONNECTE 1 avoid 8 conection, Process: Pe : using nels =i SEs DECISION operators. Use J 1 for trapping am Variables The next most important thing io know is how represented in the program Recall that data are entered i program ising o keyboard or mouse, and the data en procesting age saved on a certain location, This location & variable Variable is a Primary storage location that can different numeric or alphanumeric values. [i is alsa a Tien Spice allocated by a computer user for processing and storin Vanables like humans need i / i Tames & Microsoft suggests a variable baming pronbieslt ae Notation. Hungarian Matation Specifies a vari5 the Data type is the type of the data berm proccsecd in | am However, data type +s language specific and may hawe ifferent representations. Table 2 shows the basic date typos with their desorption: fale 2 Basic Dain Types DATE TYPE | DESCRIPTION EXAMPLE _ "Integer | Whole number 10 3551590 _| 54765 134000 =? Final of t Integer with decimal Aldté (1.12 10 Poable murabers. 1212 9.99 O04 “(harscter Alphabets and special | J Ww A | characters | Sie ee String | Combination of am age imt_l ______| tharecters |__| a total grand ital Boobean ] Reply of the compiicr in | Values are cither | the program thai es for YES or Ofor No performed behiredl the sere wed moaly by all programming languapes Choe+,Java, Visual Basic and other programming lunguages specific | Note that the data types above are not the only data types used in gramming. Oiber programming liiguage may have their own set af ‘types with specific descriptions that are nod presented above. able 3. Sample variahe names using Hungarian Notation VARIABLE NAME | DATATYPEant in programming. However, data aa ning language In the study | will not be integrated in 4 and logic development an S por’ progt amu data types alysis Data type 1s bn is unique to every programmung, logic, discussion to allow pure ane students Variables name characteristics on for variables used with « convent ; ge are presented below: The standard namin langua any biases to any prograimoune o Must be descnphve and significant io the data, problem @ tg solution, It should be descriptive enough to identify 4 process or data 1 is referring (0. 4 Combinations of alphanumen¢ characters (alphabet, numbe and special characters) can be used as a variable na provided that it starts with an alphabet a Although the length of variable name can have 256 charact the lesser the number of characters the more efficient program is Examples class_size tuition int] Income sum char3 f name answer net_income |_name total grand_total Computer Operators: Processing Data The languages of computers 4 language that the CPU can eee For i oe instruct computers to process mathematical computatio logical operations, they would have to use symbols that Co can understand. The symbols presented are the generic § used by computers for processing. Note: As wy rogres different programming languages the mathemati tea - symbols may vary. ae 7regret Havwever, dla hy Ia the i - MAB REP Sl eae noe be iMegrated iny and loge: development an 1 Vorianhes namer chat < characters (alphabet, emmy ¢ be sed os a Variable ) alphabet q vecan hawe 23% characigd the more cificion® Examples: chass_ sine stair nel_ihcomne ‘Computer Operators: Processing Data The languages of computers peed to be converted language thai the CPU can sland For the prog TEI CoMpubers: to process: mathematical computal fogical operations, they would have to use symipols. thal oo can understand. The symbols presemed are the generic used by computers for processing. Note: As you prog differcat programming languages the malhematical and & syinbols may vary.ARTUIMETIC OFERA TORS PEA THON SYMACH EXAMIMLE | RALANA TION H Multeply ihe waltic off ire A tes the Value of veriahie i Xi¥ Thvide the valee uf vanablc XX by. the value of varalibe ¥. + ist Ue hin Ackil the walos of wanble iat) te the value of workable in A Subtract thee vadie olf variable fron the value of variable. A. den Minitiply the value of wanable * twice. MATHEMATICAL EXAPRESSIOS OOMPUTER EXPRESSIONARTUIMETIC OFERA TORS PEA THON SYMACH EXAMIMLE | RALANA TION H Multeply ihe waltic off ire A tes the Value of veriahie i Xi¥ Thvide the valee uf vanablc XX by. the value of varalibe ¥. + ist Ue hin Ackil the walos of wanble iat) te the value of workable in A Subtract thee vadie olf variable fron the value of variable. A. den Minitiply the value of wanable * twice. MATHEMATICAL EXAPRESSIOS OOMPUTER EXPRESSIONarn /y" ¥, *y¥) oF ? Ca] a*s oi?) y eee * hp) (tc * a) oF ‘ ( yeayice*a) \ important 10 pote that ti aa « jn commpulers a oe ineluded in the hierarchy PEMDAS (Parentheais, Addition and cy ara Division, LOGICAL OPERA TORS RATION | SYMBOL | EXAMPLE variable A is greater than the val aniable Be variable X is bess than the value of The value of variable tat is int] == int? | equal to the valueThe vabae of ther age? | variable aged is leas than oF equal to the | valee of variabbe aged Leet than of age! < Types of Variable The sole of variables in programming is very crucial. In the sage of a program, the variables are the repository of Tation. Depending om the obpoctive of the problem, be stored io the memory, ased for mher computation, The challes tin this stage is identifying can be clarified by describing ypes of variables. Destractive vanable — variables that destroy or change its valoe rOCeaR mE This type of variable is normally the IFy storage of data during processing. c variable — varlables that mainteins its value after 8 lustrate ee thal we have variables A and B, and the values of A and 1 10 respectively. What will happen if we have an oA =? What is now the value of A after processing the ? What is the value of B? And who gets what data the confusing part. To further illustrate: 5 | = io | these “ = Original valuex of 4Praring, proceso iis is Alter jr of ibe yanerrire At iL fas Variable B, 10, and destroyed. Th vie variables. Varneble J ‘equivalent computer ex aria io aniher bs aie from right to- left, a self from your algebra. Let it sink in to-you: ythe var of variable A, oS Mm anthmetic ex pressions: pressions to 4 bbe: ne value ad ee. | processimg. the same value tie} 1. Vol Cylinder « h: where pi is @ variable to ee eran oe F = Gms d ep) Grade = 10S Assignment + 20% Seat_Work + 30%= Quivces + 405 Bxom bh) X= fat ye — [hve] (VW ey) i ASS aes oF fh -% Ka psu [gh] Solve the problem statements by simulating the given values. of the variables below: X=S: Yell; Zols; A=2: Bed; C=6 As 2% 2 = B. What is the-valoe of BY. I X=; X= What isthe value of X? WH=C;A=X; ¥=% Whatis the valocal A? WA=B: B=C,C o X. What is the value of A? Fee ¥.¥=shi¥=2. Wats eee ux oe oF ate Br e Be a 5 & R =] non wb Ae io ee z 5 = ~~] a 9 # ¥. Vie nie oe ot erate :B=Z. Whatis the value of Jif] =A—B? ocak What is the valueof Jif J =A+B4C7 SP ee sn en aS “> i bi ft No Shes Ope WA a6CHAPTER 2 Working with Process SymbolA flowehwt abways starts ith the insiaction = START oF BEGIN... the only guadeline to remenvber imahe ternal symbol ia the comivtency of temmifologies. The ongamazedt way of writing the instraction is to use the pais START - STOP or BEGIN — END. Initighzation symbol is where you prepare the wariables to be available for use. ‘When you initialize, you are also allocating, memory spect for your data storage, As o cub, we always drew this syrebol to static the Gee of our memory. Since we use START in the opening of our flowchart, for comisiency we should use STOP to benminaic.cxcrcines bebow wg 5, ihe fenmins parca in beghe an ax ae POET To be famill puithe uss in wmnserstun pi Lah Ber eeamdly uc dace: cel Laren Bacreisant coal wwe eee + my that wil af Coto both A. aon Bb feat flerarcihet he tee € L Create hact Goat wal Ac 15, B ae | Gree a Mhowebart that 12 ‘valores of the variables are: 4 Create wi fleweckuat that will art onder where Via ighes vale. Whe value Create a fhcews bert thew Laveriad onder wherr the lowes valuc. The v Dat aunon Mo. | coe renie a flowchart thet will sire the valuof A toi, whens A. = 5. nel ysis. re If we are to. solve the problem, it is clearly stated that pjective is to store the value of variable A to variable B, We xu really interested if variable B has a value because all we o ido is store the value of variable A io variable BL We know uiabbe 6 is the destructive variable and it will destroy its. ori due and get the value of variable A. perc heart:% The use of initialization in this flowchart Aa 5 x. are three things: Beso / 1) Allocate two memory locations for é variables A and B; i | 3 2) Assign number 5 to variable A; and 3) Assure that variable B has no value. 3 ~ The expression B=A is an assignment | B= A | operation. The value of variable A, 5 is i assigned to variable B, destroying the original value, 0 of variable B. After the | assignment process, the mew value of | Variable B is 5. STOP) ath Gar © czh Solution No. 2 Problem: Create a flowchart that will assign stored value of C to both A and B where A= 15, B= 10 and C = 20. Analysis: The objective in this problem is to store the value of variable C to variables both variables A and B, we This would mean that will be destroyed. A and B. Regardless of the data stored on have to assign the value of variable Cc. the original data of variables A, 15 and B, 10The processing of data in the) START process symbol is suggested to beg detailed and precest js possible. the solution shown, we can see thagl the assignment of the data fro 4 variable C to variables A and B 7 aoe Red done separately. This is to engine sy B= 10 thal the processes are clear and dome! ‘op. 80 in a step-by-step manner If the ‘ programmer placed all th é. SRS TES 1 Oe Pireccss 3 Evol the process would Look like this: poe we can see the confusia we conn identify who Re ne and who en the aie po i .ohare Big. Problern create 2 (owehart that will move the valee of A to B and-B to C The valuce of the variables anc: A = 25, B = 30,C = 35 real Wes he greatest challenge im this os learning exercise ix not moving the 1A to-B and Bte-C, but on how to the ‘iB i will be stored toc soit ee aS uneduabely, we destroy ibe data of B, and the data on & can no er be stored tC because it was already Iau, The best way is othe swap technique. Let's illaetrate: nm vanuabbes and their values: Gl Gi & apy Moving the data of A to B destroys the value of 58 &rong o naw ee a “mecmn Moving the devtroye" wool? = i : i : ; é Sigg a f — 1 a 1 - = = _ i 4 a ew vawriable, 7 r e will need au He i Sep Tect so nae cmp. Variable during the p riabie Implementir us infrodece 2 et wlll temporarily fhobel thee dais @ i] i: ow that We have to sve e aba served. Since we know f ee date is preee t re eae ee the data of B before li accep data of B to Temp ‘Temp Wecan nin des first objective of movi fe ch as met Ving the dala of A ow a now save the data fram Temp io c I aot ‘= Ho Temp A lowchart: START ) Since we need a new variable to * save the data of B, we have as = introduced a new variable Temp. asp ) Temp is assigned a value zero (0) : to specify that there is no value in T E / _ : the variable, and a memory was allocated. The swapping technique is shown from getting the value to be = preserved, Temp = B, to placing | B= A the saved value to the desired SS variable, C = Temp. The middle process symbol is a requirement of the problem that B gets value from 35(Create a fheweh ascemhing omer Avruadl pri ; 5 7 The problem in this ue iy rast — Arta the data in ascer ing ores i direction on where to ave the arranged values. We also to understand that th te rane i jogically variable C will no dude fe process. To sienplify Ube solution, ¥ will ose the fechaique as lastrated: ext ad then We Giver, varuable : x : c Ourput Requirement” : = pe ji BB c The presence of variable 1: Temp is for th i on will be used to save the omallest ‘aus ca the <4 ; : is =ce the Mevest da in of Varkalbe rd nat kaved, we cam iow destroy the edd sities: and move the middle value to its required is —_ aS ie a Sal) we Temp A 5B c « know that the lowest value was saved in variable Temp and middle value was also moved to its location, ariuble &. To complete the swapping of data, let us move the west data to varkable A to solve the problem. It is clear that the illustration, we were able to arrange the date in lowest to ighest order in its required location os specified in the blem statement. 10 =. | Temp a B c “The (inal data of variables after conipleting the swapping process: ASPsFlowchart START ing technique is ¥% The swapPlle r = ni mh clear in this flowchart. You canj the pattern of the swapping of d a a ) from variable to variable. a 0 data was saved, we can ff destroy the data in B. In the second process, B gets | value of A, destroying the data | B. We don’t have to worry if In the first process, the data on — — a was first saved to Temp. Sines =| this process the data of B wi was already saved to Temp. In the last step, the preserved d in Temp is now saved to destroying the | ee 38Solution No. § Problem Cr aan flowchart that will arrange the values of A, B, C and D in Best to Lowest order where variable A gets the highest value and vartable D gets the lowest value. The values of the variables are: A= 3, B=9.C = 19 and hes Analysis The problem in this learning exercise is to arrange the data in Highest to Lowest order. It has a clear instruction on where to save the arranged values; variable A should get the highest value, |2 and variable D should get the lowest value, 3. We know from the given values that the highest value stored in variable C should be placed in variable A, and logically we cannot immediately move the data from C to A because we might destroy the data in A. Swapping the contents would need additional variable to temporary hold the data that we want to swap. Wariable temp will be initialized to function as temporary holder of the data to allow swapping of data from one variable to another. The solution using the swapping technique is illustrated as follows: Given variables and their values: 39ihe PO ee te Temp We ina variable A, : ; cave (ve "The presen’ that will be i eee ' variable“ Z now saved, WE con OW des 4 1h Since the data of variable A the data of and move the Highs! number. The highest value, 12, is now stored in variable A. both C an A hes the same values. We can mow de value of variable C. Since variable B has the second value, variable B will not be part of the swapping pro eno move the data from variable D to variable C 6 7|esoe —__— A E : :To complete the solution, the data kept in the temporary variable should be transferred to variable 1) 3 ae : A B (e D temp The final data of the variables after the final swapping process “HP e B Cc D a 41STAR T A = Gm 12 f Temp ¥ Temp = A Ps hd Az«C - x. Ce BD * in the first process, Ube alata A was fire saved to emg Since the dato was saved, flowchart can mow desinoy iia of A In the second and third proce A gets the value of deawoying the data Oo followed by the instrecthon moving the data of 1 te In the last process, Preserved data on Tenap th waived to 1) destroying ihe on D. Bringing back the ¢ D from ‘Temp completes ‘Upping process andTo complete the solution, the data kept in the temporary variable should be transferred to variable 1) 3 ae : A B (e D temp The final data of the variables after the final swapping process “HP e B Cc D a 41STAR T A = Gm 12 f Temp ¥ Temp = A Ps hd Az«C - x. Ce BD * in the first process, Ube alata A was fire saved to emg Since the dato was saved, flowchart can mow desinoy iia of A In the second and third proce A gets the value of deawoying the data Oo followed by the instrecthon moving the data of 1 te In the last process, Preserved data on Tenap th waived to 1) destroying ihe on D. Bringing back the ¢ D from ‘Temp completes ‘Upping process andExercises; fate a flowchart that will Solve the given problems Store the data of Variable B to wariabhe A-whete A= Sand Be It Move the duty of variable A. to vagi M ul atiables 8. Deand E, wisere 20, B = 25,0230, Dm 35 and Rad "4 a Mowe the data of variable A to B, and (to D, where a © 33, B= 22, Call, and Deda: Store the dita of variable C ap E, B to F, aed Oto A, where A = 20, Bat Cait b=, 6 240 and F = 45. Store: the data of variable D to variables A, Bad ©, and the daca af variable H to variables E, FE and G where A = 20, B= 25, C=, Dos, Bed, Fads and) Ge 3), Given the variables and dita A = 20, B = 24.0 = 30 and D = 38. Make all the values of the variables equal to the value of variable B. Swap the contents of variables A and D, and B amd C, where A= 15, B=5,Cet). b=25 md b= 30 Swap the data of variables A and B, C and DB, and E and F; where A = 20, Bo 35, Ce 30, De 35, Fedde F= 45, Arrange the values of the given variables i Lowest to Highest onder le mbintainiog their order. . Teton Fee bhe a ACR BURCED DE Ip EL a Output Requirement: As2,B=4:Cot: De §:8= 10, . Arange the values of the given variables in Highest to Lowest order intaining their order, i Se rahee chee jiikdel ik Vs 2, W=8 X= 1 Y sh: 2e4, Quiput Requirement: Veli Was Xe 6 Yeh tet aiCHAPTER 3 Input-Output | And Process ApplicationINPUT OUTPET Inpiit / Chuepeun is dhe Part of the program that the user sees, Input is the only way for the user to send data to the computer for precesting. Input data can be numeric value, character, or string. Whee the computer executes input instruction, it expects dala to be entered through a keyboard. If none is typed in, the Pompaicrs Simply waits for an input data. If'no data was entered the compaiter becomes idle gives no response. ‘To prevent this Scmino. programmers must develop the program in a way that it BAN COMMHMNICALE to the user, For the program to communicate, it must have a descriptive statement to ask the user what to do and what type of data to input. In the same manner, the ‘output should also include a descriptive statement to communicate to the user to add meaning to it making it “useful information”, Qutput instruction defines when and Where to rehease the data in the program. To clarify input and output instructions in flowcharting, let's illustrate its application. instruction: Input an integer value 5 to variable A and print the yaloc. INPUT Instruction using flowchart symbal: « [mn7 Eh It is assumed that Integer A was Shieh space. Executing the instruction, Integer 5 is stored to he A destroying the initialized value 0. Take note that the a7. aes user vane was defined in thie problem ond in meet C8? the defines mput values OUTPUT Instruction asing fowehart symbol ——_ ae / Print (A) of | 2 | f i f Ml In the given instruction. Integer § is sett out frocn variable: A. Since we are sending oul a number, we simply say Print (Variable Name). If incase we are to send multiple data we says SO In this iMustratien, we cam clearly see that the programmer defines the organization of the variables j : jetty Whe cer of vibibtee Ia Ibs cial ding out data by asnine Exercise cate a flowchart (hat ‘wall eee i 1 cpl two integers a zm cepted valums P ae See Varubles A and 8 wore axsigpeedd to O fo uncte that: the i i before ia is if the solution meets the req ? called) aes programmer use a technique rien a ee— Simao the poet of Se chan step sue the variables wed, a sop-hy ‘execution of all instructions; and the gi at each ae | see how sumulation is implemented in the given encin Flowehart Simulation Supposc thet the impos wallas for Bis # The vatec cf vasiabiles A. duloel a heceeeaeeevapping process discussed in Chapter 2. Let us S€© how lowehart will execute mathematical operations Instruction: Perform C = A +B; where A= 4, and B=6 rhe mathematical formula given tells us to add the value of the cables A and B and store the sum to variable C PROCESS Instruction using flowchart symbol: se ~~ \ ss sees Nees 5 The illustration shows that the value of the variables were added and stored to variable C. If we wish to print the sum after processing, we simply use the Output symbol as shown below: Oe |. Create a flowchart that will accept two integers and print the Learning Exercises: sum. 2 Create a flowchart that will accept a value for radius and compute and print for the area of the circle, where the formula for area 1s: 4111416 Ama=! sinnuilation, Salation & F 4 2 = START ‘ ee rcaaet jritidieallor gum = 0 seep 5 ¥ Inpat value dor A ie “ liput (A) fo 16 f ere abo for at 0 Input (B} pal ‘m0 * Add valeea of A to Bi and stone gums A+B to warkabbe sam, sim yg sing 5 r , So Print the value of sama, // Prietisuen) a $0 os —s— Note that the ougput ‘lected: {n the given solution the a ofthe problem a fen °K S sepa to compl Step 1 The variables were iniias Space amd ined 5 Ma pecing ere ae * 00 prior cm b>] iStep 2 Siep 3 hiep 4 Step § User input an imeger value § to variable A. Ueor input an (ntoger value 10. to variable B. The arithmetic operation addition was executed in the process eymbol. ‘The value inputted by the user was added. and the computed value, 18 was stored in variable seen The value of variable sum which is 15 was displayed in the Guiput screen.ing No 2. P a flowchart that will accept a value for earn com d print for the area of the circle, where the formula for area is: aa =Tir . The value of TI (P!) is 3.1416 In this problem, a constant valu > Ww initialized to variable Pi. After the initialization, Pi has now a vail 3.1416 and is ready for computer As a guide, all constants that used for computation shou initialized in the initialization sy mbo Area=0, A=3.1416 User inputs a value for radius. ‘Assume that the user input value is 5- 3 The value of Pi, which is 3.1416, ee i anaietee hy ee ae value of vari _f* "2 hich is 3 ' Area=Fi*r'2 | Cher tetera Ba [ The value of variable Area, 78.54 is (rag 75 E Pi Ars _ Output Screen 0 31416 0 la caagiaee —_ : ; Input value § for _- radius. 4 31416 0 (ae computes for Area Area = Tr’ Before the Nowehant can compute for Area let ms transform the mathematical formula to its equivalent COmputer cxpressian. ‘The problem states thar Fi will be used to represent I, therefore: the formula that the computer can understand is: Area = Pi * r*2 Performing the computation we have: Area = 3.1416 * 5°2 w 3.1416 * 25 Area = 73.54 3.1416 74.54 c ‘anes [Fass ia moved to Area, 3.1416 78.54 THS4 oie “Applications Dy. ‘Creme:a flowchart that will accept the tengthof the base , tdangk amd print te ared. oe ee ae neat the tina’ is, Area 2 4b * he where b +e the base and his the height : 3. Create a flowchart that will accept a temperature tn Fahrenheit and print its equivalent temperature im Celsius. The formula for converting Fahrenheit 10 Celsius is C = 4 (FP -F2h where F js the temperature in Fahrenheit. ; J | 9. Create a flowchart that will accept a temperature In Celsius and ; print its equivalent temperature in Fahrenheit. The Formula for converting Celsius be Fahrenheit ig F = 9/5 (C ) + 32; whene is the temperature in Celuius. 4 4. Create a flowchart that will accept the length of the side of a square and print the Perimeter and the Area. The formula for compuling the perimeter of a square js Perimeter = 4 aes Area is Area = $2; where S is.the length of the side of the “art |. (Create a flowchan that will accept a length value in meters and” uA print its oquivalent length in yards. The conversion | 1 meter = 100.em, 1 in, = 254m, a Pit=12 in lyd= 3 ft Solution No. | Problem: Create a flowchart that wi fitgoaipiiee ee heigeComputing the area of a Triangle Flowchart | START ) =a a The variables sed in. the flowchart ss initialized ate Base for the base, Hit for the a height and Area for ibe area. , Base=0 In the Input Symbol, tbe Ht=0 ) ti es eld ! and L were werithen USINE . Area = 0 yf a single WM) symbol 1 a simplify the solution. If in cases where the peoblem ay would require « soparate 1M $$ ——_—F symbol, separate the enpulteng Input (Base, Hl) / of dita. ae ans Using the conversion of | mathematical cxpressiogs 00 \ compulet expression, the Area = ( Base“ Ht) /2 — stone the product to variable Area si, = Print (Area) i (as se! Area. | 2 would mean mulipty the }Solution No, Z iré in Fahrer Hele. emperalt 1 Problerti jowehart that will accep! x Paislls The formula it, Pi wie’ ; ; a | Savertiig Fahrenheit to oe Celsins and F is the tenpasallll i perature ; the equivalent tempe Fahrenhel Analysis ‘out a temperatite Cc or will just ry direct, the use : m should compute USINg the input ¥; yputed value 18 then displayed, The problem is ve Fahrenheit and the progra and the given formula. The com Fahrenheit to Celsius Conversion Flowchart In the flowchart, the ve START used are Far for Fahrent and Cel for Celsius. # Fate f \ The formula ip Cal = 0 expression in the symbols says that the val + inputted for Far is subtracts a SCté«Y «32. The differc one en _i multiplied by 5. “ne ! ‘ i then is divided by 9. Th it result ig the Eom : a & - 7 temperature In ll ar - 92) 5)/9} Stored to vadshe ao aod = US have 100.4 as Ue, as an example Ce] = Cel 5 §{100.4 s 32) * 5) 9 ofSolution No. 3 Problem: ‘Create a flowchart that will accept a temperature in Celsius and /print its equivalent temperature in Fahrenheit. The formula for converting Celsius to Fahrenheit is F = 9/5 (C ) + 32; where C is the temperature in Celsius, Analysis: The problem is the same as no. 2 the difference in this problem are input temperature in Celsius and the formula to be used in converting the temperature from Celsius to Fahrenheit. Celsius to Fahrenheit Conversion Flowchart: oy START. To add clarity to the solution, a 7 = descriptive statement is added in the Input and Output instructions. + Far=0 S Instead of just Input (Cel), add a Cel =0 descriptive statement: Input (“Input a temperature reading ¥ 7 in Celsius: “ , Cell) Input (Cel); | , The statement describing the input is ae inside a double quote (" **) to denote a ; that the text will be printed as Is, it is | Far = ((Cel *9)/5)+3 then followed by the variable Cel to accept the input value of the user. ‘a Suppose that the user input is 38. / Print Far), = It will display the following: Input a temperature reading in Celsius: 38 (stop) 59pul ean faire wl iu 1 Pal Oe lenlayed Tas ny Pcie O the ATA te jue 38. ‘The fornia { : lies: Po (3k ited ilue Tt Far Le | a | solution Ne Problem Create a flowchart that will accept the length of the sid quare and print the Perimeter and the Area. The formula omputing the perimeter of a square is Perimeter = 4 * § and (rea = S*: where S is the length of the side of the square Anal ysis: The problem is also very direct, It requires the user to inpu the length of the side of » square. ‘The inputted value will b: ovyseti to compute the the formula given, Perimeter and the area of the square using wr solution to five use rs a better understanding. nputing the Perimeter and Area of a Square Flowchart: START a The descriptive statement re in the input and output rea =| provides a clearer understanding of what the ' flowchart is asking from rut Cau the lerctha the the user, and what the abd thesuae ~ Side! flowchart will provide This practice is standard . n programming, but for Per =4" Side the behind the scene inalysis, the descriptive statements in the Input nd Qutput in the ding examples will a how at there 7 cnpuove n both Paint (° The Peirete of th rth ¢ epee * Per acreae y und yt pul d the squares ” AreaSotation No.5 ; ; yale in Jength wales fos. that will et "The E aversion writs ay ene fees jengeh 1 yards print ite equ following 22m gaat Anil! conversion from Meter to ¥ In our Math and Physics, the poguire ihe following sept x Aft x 12 in It using the formola above we . . 4 To convert 5 meters 10 yaris have Smetes X 5.45 yards or simply ra Sees X 100 vdimeee 445 yards Let ue apply the formula in Computer expressions. Meier x Mea lee, tie ae | her 23 om Din Vards = (1 "TOD 12548 peg ) OF ean also be written 289 Yards (1) eh) | added 25 print statement Mi the “ONVErsion but the Let us see how these se formulas ary j Pemented in floyyseti to compute the the formula given, Perimeter and the area of the square using wr solution to five use rs a better understanding. nputing the Perimeter and Area of a Square Flowchart: START a The descriptive statement re in the input and output rea =| provides a clearer understanding of what the ' flowchart is asking from rut Cau the lerctha the the user, and what the abd thesuae ~ Side! flowchart will provide This practice is standard . n programming, but for Per =4" Side the behind the scene inalysis, the descriptive statements in the Input nd Qutput in the ding examples will a how at there 7 cnpuove n both Paint (° The Peirete of th rth ¢ epee * Per acreae y und yt pul d the squares ” AreaSotation No.5 ; ; yale in Jength wales fos. that will et "The E aversion writs ay ene fees jengeh 1 yards print ite equ following 22m gaat Anil! conversion from Meter to ¥ In our Math and Physics, the poguire ihe following sept x Aft x 12 in It using the formola above we . . 4 To convert 5 meters 10 yaris have Smetes X 5.45 yards or simply ra Sees X 100 vdimeee 445 yards Let ue apply the formula in Computer expressions. Meier x Mea lee, tie ae | her 23 om Din Vards = (1 "TOD 12548 peg ) OF ean also be written 289 Yards (1) eh) | added 25 print statement Mi the “ONVErsion but the Let us see how these se formulas ary j Pemented in floyyards, (START + yards 0 yard = (mater ™ 100) / (2.54 " 12° 3) * Prant (yard) sToP Teises: numbers, Moter=g showing both implementations of the converting meter | START | + i é Ena bee = fh ° yan =O r Input moter) yard = ( moter" 1.09 } = Print tare i (| Stop] te & flowchart that will solve the following problems: - Accept three qumbers and print the sum: and the inputted Accept three numbers and print the product of the aumbers. Create a flowchart that will accept three numbers and print the Ssurn, product and average of the numbers.geet tea i constant 15-6673 * is Fo Seas ee P. 15. Comite (or the grade of student gi a Oe Exam. 10% Ast + 20% Seat_Work + 30%" 75% as the pai graies vrrmed are in percentage Navin and 100%: as the perfect score. : engih, of. the adjacent Accept integer values for the | me epastio aos of a right triangle and compute and print value of the hypotenuse. The formula for computing | hypotenuse isc? =a +b 17. Accept dollar value and print the equivalent peso value. fu Nowehart will convert dollar to peso having an exchange ral of 1 isto 45.15 1B-In the mike of a yearly subscription, the rate of subscription was reduced by 5% per momih, If a sub paid an annua! Internet subscription. How much is the amount to be refunded to the subscriber. Note: use a intemet subscription at Inpart. 19. Referring to problem no. 8, how much is the monthly refund-o the subseriber, 7 20. Referting to problem no & suppose that the , subscriber did ma take his nefund and add the refundable amount for = another annua! subscription, what amount will the si heed to add for anew subscription? ;CHAPTER 4 | | Decision | | Application——————E—E——E——— DECISION APPLICATION People are given the privilege to decide. Cur daily routine entails decision-making This is a reality that we cannot escape We have to make a choice to move on, Tho moment we wake up in the morning, we are faced wiih different situations and for us: mace a derision, We always ask ourselves questions that require Secision -- Am I going to school or not? Will L eat breakfast before folng to school or eat laser during break time? Am I going to drink Jeice or soft drinks during beeak time? Will I ride a jeep or take a in-mobibe to pet home? ‘This is what decision application is all shout; it ix a way for Pegrammers to integrate decision making capability ine a ‘Program £0 filter situations that will bead to a solution, Decision epplication im fkewcharting js implemeneed using a decision Symbol. [tis the sole symbol im flowcharsting that has the abihity to Perform relational operaiions chat can filter conditions te arrive ata decision, It bas a single input and iwo-oulput choines Characteristic, The teo-oulput characteristic of the symbol it the filtering aage of a program that deiermines if the set condition in the decision symbol is either TRUE or FALSE. Remember that in Making a decision, there is no MAYBE choice, it is only a choice between YES and MO, Let us book at the simple Decision Symbol application below: pare the value of vanubles A and & the valwe of variable A is greater than the value of Variable B, P, Otherwise, add the value of variable A to the valee of isble Band store ibe sur io Variable C, tion: Comparing the value of A and f SSIS gieater thanECTS DON APPLICATION People ang gj lois decision magaas: he Privilege to decide. Our daily routine rave tO make 9 This is a reality that we canned escape, Hitt ECO, wre Choice to move On. The moment we. wake op ace a decision Gee Faced ‘with different situations and for ws sion — Am I pot f always ask ourselves questions that require ng be schook Boing to school or aut? Will I eat breakfast before é OF cat lager during break time? Am 1 poing to drink oc Saft drinks durin aera ts F mobile te get heme? break time? Will [ride a jeep or take: a Uhis ts what decision application is all about; itis a way for Ogres Ao integrate decision making capability into a woprum to filter situations that will bead to a solution. Decision application in floweharting is implememed wiing a decision mitel. [tis the sole symbol in flowcharting that has the abélity to orm relational operations that can filer conditions to anive al & Cision. ft has a single impor and two-output chooes characteristic, The two-oulput characteristic of the ric fs the filtering stage of a program that determines if the set an im the aeulen symbol is either TRUE of FALSE. Remember Usat in making a decision, there is mo MAYBE choice, it is only a choice between VES and NO, Let us look at the simple Decision Symbol application below: Given: STOF. Variable C variable B and store HEN of A and B using greater than symbol. “7ECISION APPLICATION People are 9; © zi sl tals decision-making 7 Privilege lo decide. Qur daily routine have to ma : 18 18 8 reality th “ad . We Rte we wake ui ace a decision. ei with different situations and for ie ision -- Am I going to Wes Ourselves questions that require oing to school or eat ieee ol a Will I eat breakfast before ring time? Am I goin ‘ : 2 to drink ice or soft drinks duri i Win i-mobile to get home? RE OES aE ogremnners, gee Le cai tahoe sy tr ae : integrate decision making capability into a program to filter situations that will lead to a solution. Decision application _in flowcharting is implemented using a decision symbol. It is the sole symbol in flowcharting that has the ability to peri orm relational operations that can filter conditions to arrive at a decision. It has a single input and two-output choices characteristic, The two-output characteristic of the symbol is the filtering stage of a program that determines if the set condition in the decision symbol is either TRUE or FALSE. Remember that in making a decision, there is no MAYBE choice, it is only a choice between YES and NO. Let us look at the simple Decision Symbol application below; Given: A=2:B=4,C=0. Conditions: j id B. Compare the yalue of variables Aan the value of Variable B, i is speater than 8 as ft eee ris Gane of variable A to the value of STOP. Othervrore the sum co Variable C a ee -ao the value of A and B using greater symbol. AlECTS DON APPLICATION People ang gj lois decision magaas: he Privilege to decide. Our daily routine rave tO make 9 This is a reality that we canned escape, Hitt ECO, wre Choice to move On. The moment we. wake op ace a decision Gee Faced ‘with different situations and for ws sion — Am I pot f always ask ourselves questions that require ng be schook Boing to school or aut? Will I eat breakfast before é OF cat lager during break time? Am 1 poing to drink oc Saft drinks durin aera ts F mobile te get heme? break time? Will [ride a jeep or take: a Uhis ts what decision application is all about; itis a way for Ogres Ao integrate decision making capability into a woprum to filter situations that will bead to a solution. Decision application in floweharting is implememed wiing a decision mitel. [tis the sole symbol in flowcharting that has the abélity to orm relational operations that can filer conditions to anive al & Cision. ft has a single impor and two-output chooes characteristic, The two-oulput characteristic of the ric fs the filtering stage of a program that determines if the set an im the aeulen symbol is either TRUE of FALSE. Remember Usat in making a decision, there is mo MAYBE choice, it is only a choice between VES and NO, Let us look at the simple Decision Symbol application below: Given: STOF. Variable C variable B and store HEN of A and B using greater than symbol. “7ai i Are l i ve r if ‘ + ceAek lion, Aw shown in the figure abs a a whoa i f TRUE condition, it is the ¢ th Te rise ten ihe value of B. Fence, if the valoe of ii greater than A, the given condition is FALSE forcing te awehat fo pass to the left path of the symbol. It is therefore a fact Cha the decisioa symbol has only a single output at any given point jad flowchart. Leaming Exercises: - y 6, Create a flowchart that will accept two unique integers ii print the higher integer. | 3, Create a flowchart that will accep! two unique integers fi variables int] ard int? respectively and print the imegert i lowest to highest onder. 7 P Create a flowchart that will accept two integers. If the intege are equal, print the sum of the integers, otherwise print th a 9. Create a flowchart that will input unique | Cisdprkt tehishon nein” poems inet ae 10, Create a flowchart that will accept a real estate value i compute for the realestate tax that will meet the follow a If the value of the real estate j : » fama tra ea j value of teal estate is betwee 500 7 n 250,001.00 500,000.0, tx is compuisd at 10% af the real coe. & If the value of the real estate ‘ commuted at 1S % of the real esate ya oOo a *Solution No. | Problem Create & fowehan that ; ihe higher inkeper! Will accept two unique integers and print Analysis. To solve the given . problem wcing the Pilbeal secodb sesey be ned = the Crp: [. ts chear in the problem thai the user should input two unique integers, By the given input condition, the user is not allowed to input any real numbers mor input the same integer valae. Since ihe input variables are nea given in the problem, the programmer should initialize the variables to be used. In this problem, variable A will bo used to accept lhe first unique integer and variable B for the second unique integer. Process: To solve the problem, the first thing to do is to identify which among the input value is higher? After knowing which among the value is higher, the higher value is printed and the program is terminated. Keowing the requirements and the way to selve the problem, the programmer now tras the option te use any of the relational operators to compare the integers. ‘The suggested relational operator to be used is (Greater Than (>) Take note that the dectdion symbol wall force the program to pass the path where the condition is TRUE. Output: Fr Once: the values of the integers are compared. the higherhad Bat varie A it welteg
Having equal values leads to a TRUE condition and forces the flowchart to pass to the right side of the decision symbol. The next instruction is to add the values of A and B and store is to variable sum. Take note that the initial value of sum is 0; eS performing the instruction: i OUTPUT eae ee Koa eee an =~ ese a “Incase the Fatyes putted for both A and B are not equal, then” . if lect the left side of the decision symbol and | Ca a he values of A.and B and soe ito variable rod. i ' "The product then is printed before the flowchart terminates - eee ree and single Output symibol for Flowchart using a common variabl odin Simulation. TT If the user input values for A + and B are 3 and 4 respectively the variable will be: co) Ce = : : the integer values ae comparing oa “i Cae = = -B inout (A) Having unequal values leads to ‘ / . FALSE condition and forces — the flowchart to pass to the left ie side of the decision symbol. ie The next instruction is to me ie multiply the values of A and B and store is to variable QUTPUT. Illustrating the process will show: - A=B ——_ ~ outppt = A * B ‘ake note that when the values inputted are equal, the condition in the decision symbol is TRUE forcing the flowchart to pass to the right side of the decision symbol. The values are then added and the sum is stored to variable OUTPUT. To illustrate: Input values for A and B is 10. output = A Rateatiog the last inkgoietion Moa. 4 Towet Loweban hat will der at pul Unique: ineepers for A, He andd € et highest imeger abe zi . ied aoe left colume of the thle below. The right A specifies the wartable where the highest value 15 Input combinations c OUTPUT Vanahle A A c B H c mn mm ba eee be ke ek ee he Mae that the validation of identifying if the input mnbegers are the same is mot yet considered in this solution Process: In the table shown: above, it is clear thal whatever inpat combination the user will provide, the program shenald. be able to identify the highest integer: This will be filtered through series of logical comparison using greater han or less than symbols. In this problem the symbol that will be used is greater than (>). Before transforming the solution into flowchart form, the analysis of the problem is presented jn a tree Siructure. ‘The right path specifies TRUE condition and the left path is for FALSE condition. The illustration of the analysis of the solution is shown below: TTaa | Integer A is grep ater than A than the value j H is greater than A pecause och | is not greater than B. Since B is greater | thet Avead Cis fe | greater than B; il pee follows that C is greater than A; ay Therefore, Cc is the Cc highest 2 Since B is greater than A; and B is greater than C: ee Ais greater than B; and@ is greater than A; it follows thar Cis greater than B; Therefops, C is the highest Therefore, B is the highest Flowchart:Solwion 6 Probens ue anel COMpaip eer LOT Create varchar that ¥ for ti 250,001.00, tax, A 250, C01 MD aud of the neal estabe Analysis: it amd Chatput in tis problem, the requirement of the problem 15 for the user to input a real estate value. Once the real eaiate value is inputted, the program should identify which neal estate percentage tax should be appheable, apply the percentage tax and print the real estate tax payable. Process: In the process, the program should multiply the inputted real estate value by a certain percentage to produce the real estate tax payable, The challenge in this problem is to identify which percentage that should be applied in computing the real estate tax. Whatever real estate value inputted, the program should be able to identify the appropriate perceatage multiplier that should be applied to compate the real estate tax due to ihe user. The tricky part in the filtering is the identification of the boundaries of the sc a used for filtering (>, <, >=) or <=The conditions todefine the applicable percentage are If the value of the real extate ix lens than 290,001.00. multiply che real catate value by 05 to get the 3% of the real estate ansoant duc. Tf the value of the real estate is greater than 250,000.00 and is fess than 500,001.00, multiply the real estate value by 10 to get the real estace amanank due, aml I the value of the real estate is greater than $00,000, nsultiply the estate value by .15 bo get the teal estatc ameuint dec. ‘The filtering condition in table form is presented below: Real Estate Vabue Multiplier Percentage (in decimal) (in percent) Php 250,000 and below = 0G 5% Php 250,001 - 500,000 10 10% Php $00,001 and above 15 15% ‘The Mowehart for this problem is presented on the next page #1Computing Real Estate Value flowchart START ¥ REV = 0 RET =9 ; ¥ Input (REV) AS shown, the | of Jess than or equal to (<= to simplify the fil instead tering proces s, Note i I (RET) z 82faercies: Create # flowchart that will solve the problem of the following: ‘cet EWO IniGRers and determine if the valucs are equal, if values are equal do now print anything, olherwise print the higher aumber: inpet three anigque nuambers and print ihe lowest number. Input Unaguec Valliees for Noi, Nie 2, and No 3 and arrange the umbers in Lowest to Highest onder inp three unique numbers and print the difference of the highest ond lowes! nombers. Accept three numbers and determine the highest number, if the highest mumber has an equal do not print anything, otherwise promt the highest number. Accept three integers and identify it there arc equal numbers, if there ant expial gumbers print the eqoal numbers otherwise do not print anything. |. Input three integers and determine if there-are equal numbers. If there are equal numbers, print the product of the equal numbers, otherwise print the average of the numbers. Create a flowchart that will compute for the grade of spudenis and print its equivalent grade point. The formula for computing the grade is; GRADE = 10% Assign + 20% Seat_Work + 30% Quiz + 40% Exam, Note that there are 2 assignments, 2 seal works and 2 quirzes given. Exqulvaleot Grade Poet 1.0 94 — 100 225 = f4 — 86 12 - 96 — 98 250: a — 83 1.30 - 93-95 215 ~ 80 1.75 - 90-92 300 - s T 20° = 87 - 89 50 - behiw 78oye, nub y rate plus bh yer over 40 haat " woold be computed by Uting 14, Create a program that will accept vehicle type ps lect traveled and determine the toll charge given Me owing formula Toill Charge = Vehicle type * Km. (based on ticket type) Toll Charge Matrix: k Car P SO | = Yellow 15 ken, Light Track =P 75 2 = Blue 25 hem Hus PI a= Red 50 im. Heavy Tock =P 125 4 = Orange 75 km 415, Create o flowchart that will accept a person's age and print fly equivalent education level. The age of a child is considered | year old if it reaches 6 moaths. Given the condition of converting 6 months to | year, the flowchart should be able ta identify the child's education level. If a child was able to finish college, it is considered thar he is no longer a child and is alreacly a young adult and a professional, If the educational 's professional. the flowchart should not print anything: The education level in relation to age is as follows: Age O- 2 ~ Parental ren 1-1 - Ag 3-4 - Ni Age Age 3-6 ~ Preschool Age 13-16 - High School Age |7~ 2] Colts Ra reCHAPTER 5 Loops and Iterations— es | LOOPS and ITERATIONS H ine (ATR etd the: capability of Automated Teller anal tae when making transaction requests like deposit, - nil ace ta el Payment, transfer of funds, etc.7. You = — that ATMs have the same procedures 10 process ND fi tarts by waking fer Personal Identification Number (PIN) for security access, end then followed by offering services that Ih Sar Process (0g. depoalt, withdrawal, transfer of funds, payments, etc.), After sclecting a service, the user is asked for the —r be prose, At the end of the transaction, a receipt is ee Hext user will aga the samme . The only difference in the Near abhi transaction is that the added, whtracted, or transferred, is a Pee ‘This ts function called loops, Loops is a aet of inetruction!s that executes repeatedly until a condition is satisfied. In the above example, the processes that cnn be performed by ATMs are the set of instructions that are running repeatedly upon the request of the user, No matter what it takes or how many times it has to be performed, the machine should satisfy the request of the user. To understand the concept of loops, a simple example is ahown below,Take nore also of the instruction inside the inpaviowlput symbol. The numbers to be printed ane inside double quotations CO". This would mean that the dat ¥ _ eg, numbers, characters, wards of % 1 | phrase} inside the double quotations / Print('S) —/ Sesprnted as thoy ace. tho dol — T quotations were written inside the ¥ lepulfoutpeat synibol, if will mean [San ee tit iva variable, and tho dati Print ("4") / be printed isthe content of the variable and NOT: ihe variable. _¥ a Bs, Print (“A"Yand ‘jet (Bs Print ("5") / ‘Wheto A = 5 and B= 10. The i OF insiruction = will peodoce: Pea« Tteration — The repetition ofthe loop. When A hie Problem requires printing the aumbers # to means 4 Pepetition of instruction to PRINT 10 times is The number of Tepetitions: the loop has taken to the problem is the number of iterations 10, it needed. jporfann fo sateefy « Accumulator — A femporary horage location im a central processing unit that holds mathematical data during processing. Using the problem given in the Beration cuanple. instead of printing the numbers | to 10) the problems looks at printing the sum of the numbers, Ubustrating the problem we have 445, 6.7, 8 910 2a 3+ deS e647 +494 10 Numbers given ame l, Sum of the numbers: | The sum is: 55. This means that we will ADD the numbers 10 ; 4 the same time, there will bel iterations that will bappes send ' i sqaure fre to 10, get an umbers as it incremete wo = ease a andl store Uber tm a temporary eee ete a ‘ani the 10 iterations ar evenpleted a the curr mi . yalue forthe earn 18 the 5 be iecteaniag YET that temporarily holds # accumulator. 7 ly. for scummulatoe Es ased not onl) ro a ee Sie and other mruachenatical addition but for applications a well multiplications of cxmmis he I th ae ma fe eg 4 i @ wnt hus. executed. ALO ee qiant bo adres mg ibe mala is Ue coma jorationé 4 program alue 1 also used in ries oF camerLULU af aecumulaloe The illustration of this ‘Une: ion concept is shown below. Create a flowchart hat will print the first 1O00 counting numbers. thing to mate in this ae ge ihe use of pan arjable. Since, we are to prin nubers 1 to 1000, ‘The variable ued in this solution is ctf and is set wo O, (just to eet 8 variable that is significant to the function of counter, but remember you are free The formula set in the symbal, ctr = cir 4 1 is the counter uaction. During the first eration, the value of ctr becomes 1, because ‘ctr value is © plus 1 is equal to 1 i is then stoned ko ctr, giving the new value of ctr, 1. The decision symbol asks if the valee of ctr is less than 1001? Definisely it ix true, so the at through flowsSarmnalatd iy , a aT — ie es oe ere to the ale ¥ \ i path of the doctdon atoe \ ; fytbsl, prints ihe i ' * value of ctr, and \ gest back mm cir \ and performs 1 tir = ctr 4+ |; | ae” By this time, efr value becomes 1001. se i “through the decision symbol, the condition set is now FALSE, ~ the value of ctr, 1001 and is mot less than 1001, they are “in fact equal. See ee A 1000 to include number Tees ieee cee value used is 1000, then the flowchart will print numbers | to 9% Biving erroncous solution.level programs. To further the undert to bear. Programing, if is important "The types of loops arc what a program? © ae Ponrirber thet defines how boops should °° ©, constrect is a set of rule tha constracted. These set of ri languages Tt ti due 4 ‘Types of Loops thar runs without an ered. « Infinite loop - A loop wroag logical operation oF expression used, or wrong Yariab sed to control the termination of the loop. Others call thay jogical eros, Often this type af error is the hardest type of error lo debug. Learning Example: Problem: Print the first [counting numbers Analysis: The problem is very simple. It only requires printing the numbers 1 to 10. Sine eee kan ek wrong veces and of Wr00g logic expression then we might end up in having infinite loop. The illustration iz shown on the next page.Fiewst * 4 ‘ 7 : xe rt * + Wein (io STOP « Index loop - A loop that executes when the number of ieration is explicit in the problem. ‘The printing of numbers 1 to IM) bs an example of this type of loop, Learning Example: Problem: Print the first five ewen numbers Analysis We know that and 10. The problem req the first five ever numbers are the numbers 2, 4,6, 8 mites printing these even numbers. If we bers, we will notice that there look closer to the first five even nam > from each number. To implement ihe S the counter function should use 2 as en cumibers. The illustration is isan increment of increment in the program. incrementing step to produce the ev shown on the nex! page. a3Flerachart START £ ar = 0. H r | mache? i | checks. if the cure. oo | m li sae. The. flowchart 1 cht = 10> hig | terminates if the carrent value | of cir is prewter than 10 7 . } or Pret (ot | fete thal the incrementing siep | is aoa | for gounber fuschos 1 ) bimitedl io 0, ‘The counter ep may differ based oom tbe requirement of the pacblem = Conditional Joop - A. loop that cxecules only in a given catisfied condition. The number of iterations in this type of oop as net explicit in the problem and the iteration ts dependent on the cosdditions given. | Learning Example: i ' Problem: Input a number and print the integers of the inputted : number i Asal ysis. | ‘The user is given Ihe opportunity to input any integer. Uf the wser inputs 6, the integers of this number are |, 2,3, 4, 5, und 6, Our : problem is to ereabe a flowchart thar will accep! any whole number and print the integers of the number, ——— coMote: (ee problem can } a an he solved eondlthen OF poal-cemadi . cy : spplication tr programming, — precondition Approach AL Pre-comdis lion fist itch ese isa conditional boop t “iecks the cand ani bai ete inexecuted, A classic looping ae , Of approach is the While Loop. This joop first checks Rat rien Se ee if the given condition in the decision symbol proc. [f it is true, the ; Ls, chamb. for this apaesuek tapes sens ingiection. ‘The rule of “While the condition Is truc, Do “statements” AStatemie is Meky be a singe instruction (¢.g...¢ = ¢ + 1) or series of instructions (e.g. J =] + 1, followed by x = x* j, and printix)). Pre-Condition Approach Flowchart: The problem explicitly states pl tha ihe insinaction is to prim (str) the integers of the number, As thown, the Gutpul syrmbel eats Os is placed after the decision symbol. ‘This chearty shows that the Alowehart will [first check the condition given in the decision symbol. Lf the_— Programnnity uuridker Cui & wal ohhot = hile the coreiieion es tr we" gigas, the Hlowehinen “Always execu les jis lonp at le “Tho statement ane iterate 4 Post-Condition Approach Flowchart: i Ins thse il START will acoope a value | meer, [then inet £ ‘current value of cirthen prnis ae ean value of ctr xa0 a : Morice that the flowcban a executes the instruction fiat { inet (of Printtetr) } before i goes 10 the : ——- decasioc syrmibed to chisk the ¢ - = 1 condition. recat i " f (At this point of the Plorwehart, : Pit ie y the condition in the decision symbol is checked; if the r t condition is trac ( the value of : ene X is greater than the vabue of WO gy SES | ctr) at oes back to the loop a and performs the imstructbans. | If tbe condition is false ( the i + value of X is teas chan or equal a to the value of ctr), it terminates the program.be proeraTUNE CONVERtICN Bf goes 1 ASt. PEORT Imig lary Integrating Exampbe — Pre-Condition Approach t flewehart that will . (Create 2 " at will sec; 4 ae cam of the imagers, OFM 4 whale pimber and \ Analyels 4 key things bo know to solve the problem ' |. "The user will input a whole number. (so decimal number allowed) 2.Generabe the imegers of the momber (can be solved using the | counber ) 3, Use Accumulator to add the integers of the nambet | 4. Print the accumvulatog after satisfying the condition. (all fenerated integers were added) The fhowchart ihustration bt shown in the next page. a7(aia in the initiadizadion symibe7, \, bai ff variable mam la Introduced to be used ad eccummullatoy The formiild eu = sR 4 chr, takes care of adding the inaegers Remember that variable cor, i 6 counter function that can bp uted to penerasy the integers of the rarreienr, ‘The major difference in (his solnos is the Simulation is provided ou the maxi page to pre-condition appeosch wed inthis imngrating exaerle, bsaiex: te i aia( START ‘ | _{ Simulation: | \ * Jnitiatization Hu tr x sum no. ofi é cir = 0: X=0; X 0 0 0 no a ‘. sum =) ? SS Input value of user is 5. sa cir x sum no. of iterations ae Pia " ee ie Se » Counter function np | ee | tt=ctr+1 ctr= 041 sum no. of iterations 0 ir x x é 0 1 4 4. Filtering Is the value of X greater than or equal to ctr? gee Sens Is5 >= 1? YES, perform |) Print (sum) / | sim 7 Be 1 TAS cosh es 7 " sum= 0 + 1 —— oa STOP o ov 9 a Tn ts The simulation from this part of the 4 Counter functi flowchart continues to process ctr=ctr+1; ctr= 1+1 instructions as long as the decision symbo] doesn’t terminate the solution. ctr x Variables ctr, x and sum continues to or A change its value every iteration. 4 Iteration is also included im the es: cobaee show the mumbo OF ine is increased to 1 loops the program has taken. te number of iterations show 1S not Value of counter in a program. Numbers in bold are the changes tis Occur in every 3 perfor in the flowchart. sum no. of iterations 3Simubation continuation 1: Sinvulation: 5, Filtering, Is the value of X greater than or equal (0 ctr? Is § >= 27 YES, perform sum = sum + clr then boop sam = 1+ 2 STaar Ee ctr * sum occa sa oo os o 6 fine Rak _— > ra i 1 “| S 2 eat 6 Counter function [van / creer+]; coe 2+! sum «fo, of iterations ff ¥ ve od gygjnmulation “OOKLA oe, 2 5 chan 8 onter fhemetion cred; Gira 34] f x sum 10. of bterations = go ¢ 8 f START Ye oe . x z t = Z 6 3 Kady \ : %. Filtering 2 Is the value of X greater than or equal to ctr? ik $>=47 YES, perform + SUM @ SU + chrs then loop cre t ame 6 + 4 Ei tr x sum no of iterations aver oe @ f : it 5s oF F eee - z pete a o 3 t a 4 10 ret = 3 = “Counter fxaction ! chsci+ 1; cra 44] ae X 800 oo. of iterations 6 o¢ g SE F a Zz & 7 10 4‘Sipmabat bow | setiveatians * pq aber 1, Peering : % greater ; al te cle? 57 VES they are equal, ricer earn = ae + Cy het J ; an= If + 3, hoop: : Be : i bE uae Qsr-~2SE AM a rol mabe, ‘the jen in dictated. by the hwo appreac: (the problem salutier to perform: whether before checking or fillte fs the better aye’ ite : the condition first before executing ¢ ny ceNgueies che ft ier tr ebeck then Pre-Conelitioe opppeciicdl is mare i ) , real life example is how ATM fonctions. Ef you - ATM example in the’ previous chapter, it explains how cs user to input a. comect PIN before they are given if we relate this analogy to looping. cc ti access to transact is the ee ues correct is the cathy program erates, displays again ct eee Siac pes astrepee etl fi the eprating process of asking the user for fepeatiog instruction in the ATM pe user tor aSE AM a rol mabe, ‘the jen in dictated. by the hwo appreac: (the problem salutier to perform: whether before checking or fillte fs the better aye’ ite : the condition first before executing ¢ ny ceNgueies che ft ier tr ebeck then Pre-Conelitioe opppeciicdl is mare i ) , real life example is how ATM fonctions. Ef you - ATM example in the’ previous chapter, it explains how cs user to input a. comect PIN before they are given if we relate this analogy to looping. cc ti access to transact is the ee ues correct is the cathy program erates, displays again ct eee Siac pes astrepee etl fi the eprating process of asking the user for fepeatiog instruction in the ATM pe user tor apot TiO Approach Flowchart Stsaliation: Sinvulation: 1. Initiatization ctr x sum mo. of iterations oo oO 0 START | Input value of user is 5. clr = sum ng of erations og o 0 & 2. Counter fanetion crecr+l; are 041 Filtering Is the value of ote bess than X? Is L< $1? YES, loop = §, Counter function cect |; cre 1+1Past: Conditins wehart Stomalalsom Contention I: pulatoe ie Litt fry aM 7 ' dr v sum no. of Hterntions 1 eos fi gs 2 ! 1 * -_ shart 7. Filtering | E L Is the value of otr less than 3p t Ix 2< 5? YES, loop are 0%. Counter fonction i crooaré i; ara 24]ton Approach Flawet: 20 Simulation Continnation Simulation: 14, Filtering cof ctr text than &? 3 <5? VES, loop 11. Counter function im Ors ctr+ ic cu 1+] | cle x sum eo, of Herations | ow gg o ' cede I eu) i F £ a 6 a r 1 4 e 12% Accumulator x ST no, of iterations #6 2 . ar nO 5 F £ = I 6 a 4 10 ' : ee f ns cir bess than X7 Is4 <5? VES, loop— —_— =f Ple no. 9 jot: ¥ sa ! acne Will accept a whole number and print the pro oe rhe 5 Elven below illustrate the different approaches ©!
) Taper ld iniegers ar at the highest uMeger a ‘ihe factorial of the mumvber, 7 8. Tnpet a cumber anc a> 120 ‘Ourput me> 6 Sample inpat ==> 5 Sample input=2> 3 Output 2 A fibonacci series, is a series that adidls the present series value to iis predecessor value and writes the sum to succeeding series. The sum valucs fesctions as Sie poem value in the series and add to its predecessor. sbianl tuowtoor sie eee See me eame i ret oe Easel seen Sample input ==> 21 Cee: a ih 123581321 ee SMhassarsa aCHAPTER 6 Switchgate Hels CERT are have if TO review already learned heat we have achieve MEME et os ames of forming mathematical * essing, SADTessions into computer if flowchart as a pro. vCTiNg With tigers get ing pene ool sac Merongh Ontput ay Symbol and providing Lath, InPortanc A ipalation. f variables in data clulness of Variables j terms of counter imulator, * % oat oocss mathematical and logical operations lier conditions and validate responses of users, s | came logical solutions using decision symbols, ) Provide solutions to repetitive process ta meet user quirements. oderstanding of how problems are analyzed and solwed in ¢ workd of programming. fo complete the essentials bal bce == wether important concept that needs to lead. Recall fevigUs chapters, varieties Bae three functions -- nique problem requirements. h variables. Wartable is ‘The baited used to set a condition in the "The functions of variables are Functions of variables |. Initialization Counters Accumulators E 4. Switch ach ig discussed in the. flowchart The concept of S¥" FPlication below: 113Leaming Rx Probie m1 ; , pa number and prist the Nghe flowchart thar will acee To solve the problesr, t following of ie |, Use a counter to count the number of inputs. : 3 [nitialiee variables for the imput numbers, highes number and switch. : i. Use a switeh to move the input number to the varishle holding the highest number. ‘ 4. Use a condition to terminate when the user has inputted 5 numbers. The major challenge in this learning example is how te identify the highest cumber. If we have initialized all the variables to zero (0), we are sure that the first input number is the highest We can therefore use this number as the highest number to compare the other numbers coming in to the program to identify the highest number. The switch function in this example is switching of decision symbol to a path (YES and NO path) will instruct the program to store the highest number, Tf the next number inputted is not higher than the first number then the Gecision symbol switches the program to continue accepting inputs. ‘The switch in this analysis is the variable in the decision symbol that is used to determine the highest number. The flowchart solution is shown on the next page. “ fig F 4ott he HIGH Nae Fiometaes value from to-5 and ctr, from 0 to 1.Identifying the Highest Numbe Simulation: START 4. So cr ar 5 | 5 _# mre # Input value of usep | s, High = 2 | | 7, So ctr High | J ge @ oF rae SF 5 Inga (Me) 3 4 : -_yartsbie No changes em =o + from 5 WT ya Ls the value of Mo gre Pde: i. Pees ihe switehes te NO pash. 16oS and etx, fron 2 to 3. uwIshonsil firicthon 3s High fe (malo of eer 10 High a 4 E Ce ee F * Variable No changes vileg a from 3 eo 2 and ctr, from Si x | 16. ts the value af Nol pea WO is He = | than High (10> 3)? YES thea the flow of the Por [arenes oes ee ht | £3. Variable High pete ie value of Ma, Hightnor is 1 A Ys 1Bgt 3 a 35 B - o& jace tawe fy BBE ae u Jews 2 Ect heen eo dase Pek heen 53 2 2 3 Zebra E Zebrnge 4s ath Zhe Bo 3 < 75'S aaSE di Gage ot High 10 sd > cy, 7] START * j j 9The flowchart illustration in the previous exaniple Clearly lation illustrated the function of switch. It wa: dekailed Ee ne simu thal switch can force the flow of a program (0 Ce ay instruction, In the example, switch forces the flow o Program to YES path if the user input is the highest number | We might say that the example given is easy to solve, what if we twist the problem by identifying the lowest number instead of the highest number? | am sure that you oer ane approaching the problem the same way we have solv © first example. Then you are wrong, let me illustrate why. Let us simulate to see what i. ‘ happens to the flowchay mane using the same approach. ee Simulation: s ee neo No ctr Low a 0 oO 0 =e Input value of user; ]_ / Input (No) or any number agen! No ctr Low |_or= cnr + f 0 aa 1 1 Se When we reach the switch condition, is No < Low? (05 1 ), the condition is always FALSE, and it can never move the value of No to Low. Because the value of No is compared to zero (0), The instructions here are the filtering condition of counter, and there is no number lov 4 printing the lowest number and than zero (0), of co ane loop to input another number &xcept for decimal numbers.4m cunmpar imc; paer i ip START naa , Te te La Rowehast, wc 2=0.cre Ubea thee ty a al tale inne, rk allowed er ore than five tienes i M Migilates the problem put No) TOWWUEMeR. “The flowchart . H Wee weer io ing aia ' Times weve othe = fret Per; hugober inputted was mat included in the counter Take ote that the function of counter is to Mont the number of bnpur the uner has made, and it lemmittates the program. when the value of counter is 5 Another eve sore im the sobstion ix the use of to Inpul symbols for the same wariable Te other words, thas approach will siall mot moet the problem requirement 50 what is the solution? Is there a solution te thas problenn? The best way to solve the erm is WO ust eo switches. Printing the Lowest Number Analy : cal to say that the first 4 ayurnber, it is FORT ber that all the ite a ee or highest, Reims 3 el ial4m cunmpar imc; paer i ip START naa , Te te La Rowehast, wc 2=0.cre Ubea thee ty a al tale inne, rk allowed er ore than five tienes i M Migilates the problem put No) TOWWUEMeR. “The flowchart . H Wee weer io ing aia ' Times weve othe = fret Per; hugober inputted was mat included in the counter Take ote that the function of counter is to Mont the number of bnpur the uner has made, and it lemmittates the program. when the value of counter is 5 Another eve sore im the sobstion ix the use of to Inpul symbols for the same wariable Te other words, thas approach will siall mot moet the problem requirement 50 what is the solution? Is there a solution te thas problenn? The best way to solve the erm is WO ust eo switches. Printing the Lowest Number Analy : cal to say that the first 4 ayurnber, it is FORT ber that all the ite a ee or highest, Reims 3 el ialr nitialized to vere CO) amd the first input | ase lowest rambor Docaeee there 00 mame | tow, of we can aah a switch to force the fn, variable Low, then We are assured thay + amber twin vara OMe ee the Essig of a | first inpat wo variable. low 1 8 path = by sitet, then it can te, switch back to the other path. to deny passing through He as, n for the snccending loop The switels application in gs, cy rangle iniwoton and IHicy ) proce: arwcrionns dev thee Rowe. wit edd be pocrice fe fo process the rest of the os ar back Mow what we have understood how to solve. the we are now faced with o new challenge How do we set the thal will switch once and switch hack for the rest of the loop? 5; there a way to implement this? The solution is to wie the value-of counter to function a5 4 switch, If we have the counter, ctr = ctr + 1, the value of becomes one (1). If the next instruction i& a@ @ecision symba asking if the value of C = 17, then the condition is TRUE, ber to variable Low. This is t mow move the first input num after moving the data to variable Low, the program retire symbol to accept the next sumber, After accepting the input, counter increrments io 2 (cir = ctr + 1), then the o the decision symbol C = 1 becomes FALSE, and it willl true because the value of counter will continue to increase the program to process the rest of the instructions ¥ the YES path of the switch, (C = 1) in the succeeding The rest of the program performs the filtering number inputted and storing it to variable Low, after five inputs, the program satisfies the condition C the lowest number and terminates the program.pritiOk ihe Lawes st Nemee 3. Switch fenetion: 1s the value of ctr = 17, YES, move value of ‘Now Lowthe Lowest Number Flowchart Continuation 1; Printing . | Simulation: START | 4, No ctr _= Fi] g 4 5 ] Ma = 0 G toce ——» Input number : § t—_ , 6 : x Ff & 2 ctr =ctr + 1; 2=1+1 i WY No ctr Low 6 6 5 6. Switch function: Is the value of ctr = 17, NO, pass to NO path. Notice here that the Condition forces the flow — to pass to the NO path. 7. Filtering: Is the value of NO Less than Low? , Is (8< 5)? NO 8. Monitoring number of users: Is the value of ctr = 5? NO, ctr = 2.; Loop and returns to Input and accepts a number.Is the value of ctr = 17, NO, pass to NO path. 12. Filtering: Is the value of NO Less than Low? Is(3<5)? YES move value of No to LowPrinting the Lowrst Somber Mowchart Continaation 3: | ‘i Sirvulacion | 13. Monitoring, ray af users: imity Ls the vahae of ctr 5 NO), cir eh: retums 1 Input and Ey aceepis a number, = id. No ctr Low s 8 8 z xc r+ §# cobb £ # 3 rs aja «= (pot number: & Is. No ctr Low 6 68 ‘ & F eo a £ 7 6 4 cir =etr +1; d= dw] 16. Sowhtch fumetion: Is the value of ctr = If, ici: NO), pass to NO path, [rete / le. 17. Filterimg: | 15 the value of NO (sor) Less than Low? — Is (6 <3)? NO,Flewehart Cuntinuation A: Priating thr Lowe! pore be Sprmubacion: i. Monitoring ef Users; Mle fs lhe values of MO, cir = 3; let nena: bo Input te. accepts 3 Mater 4. Ne Fi) © a 5 , rr * e ona 16, Switch function: Is the value of ety =f NC}, pass oo NO path | 17. Filtering: Is the value of NO Less than Low? Is (6-< 3)? NO,pein the Lowest Number = char Continuation 4: \ Bier) — Simulation: th Monitoring mumber fier ‘of users: Clmae ‘ x) ithe value of ctr = 5? ] : | NO, ctr ed; Loop and } "reg eedt Is the value of ctr = IT, NO), pass to NO pathPrtating the Lowest Number Flowchart Conta 7 / Simulathon: (amr) No ctr Low 7 6 68 «@ | et (aa £24 Nv twat? e a t e # 1 5 | ot teput (Fat 22. Filtering: i . Es the value of NO | 4 Less than Low? eeoret Is( 1<3)? YES, move value of Notoie ene ’ he she set By Une to fp lowest nutes, "or ne na fol ite the numbers dae WO highest otter ant tc a that are in the arcs: and we want 4 y to solve ‘our Odd sequence, can you thin “ ysesnent aM lUStration is shown ben mtettame. further Nun bers given ane ; a4 5, 6, 7, 8, 9, 10 Requirement: Separate the numbers in the odd sequence to manipulate, z a ire oof, ae Z EVEN SS, Na, Ss 3, 10 lt we look closely, we cam see that there is a pattern in separating Uhe mumbers im odd sequence {rom the numbers in the even sequence. If we replace a mamerit. code for odd and even by wero (il) and one (1) respectively, we will have: opp wh ah 0 EVEN he en 1. ‘ ic codes, we cas. sec that In the representation of aumney: Lat there is reallly a pate that spas eps vee EVEN sequence mumbers e analyze the paliem conclude that the nasmeric code _ aoa = ea rte this to peOgramain, °° changes form 0 10 lO, These charges 67 0 imple he pth in very lop ‘alysis the application F switch ele, = 1 Se eescaming Example feats a Flowchart that will print he odd sequence Integers sue oftvariable No, where. variable Noigequal to 10,” The variables | are:too SF = 10 NO, = 1 nd tetarn to counter. 4 No ow bot 2 Secret; 2— 1 +1 3. Switch function: hSW=O)NO.SWel and astign Oto SW. & = ‘Mesiioring = counter value: ctr = 107 NO, ctr = ‘2, boop and remen to courter. athe ODD sequence integers af 10 Continnation 2: 7. No SW ctr TAH io ke tog € a z No = 18,€ 3 Siw a gr=er+ 1:3 = 2a 1 | 8 Switch functhon: fteac+! (——" | is SW = 0f Veo | the value of ctr (3), ga] _—— jf isign 1 to SW. = a x swe No SW oe eal 10 g ¥ 7 a SWind Prind (ct) : 9. Monitoring value: Isctr = 107 NO, cirs and return tothe ODD. Psouation a: Cheers 1.42341 ae LL, Switeh functing: f Woe zi Is SW =07 NO. | * assign O to SW. No io oe hag ahuanng 12. Monitoring counter value: [set = 107 NO, ctr = 4, loop and retum fo countercs of 10 Printing the ODD sequence intege conthmantion 4: 13, No sw STANT | in of r o £ 0 wae ken Se ¥ | exaees 1; 52494 an ep Se + | 14 Switch function: “ Is SW = 0? YES, pr we eae | the value of ctr (5), a WO. ew we Hissign 1 to SW. ? Mo 10cs of 10 Printing the ODD sequence intege conthmantion 4: 13, No sw STANT | in of r o £ 0 wae ken Se ¥ | exaees 1; 52494 an ep Se + | 14 Switch function: “ Is SW = 0? YES, pr we eae | the value of ctr (5), a WO. ew we Hissign 1 to SW. ? Mo 10SW ctr io 0 6 is og o og x + A 1 sF 6 Potrect+1;6=541 teeter = 107 NOL ctr =6, loop and netumn to oounber.“rs of vi nieye Printing the OO sequen’ tal continuation 6: 19, No SW ctr 10 START 4 ie ky ee sw » | aig eh WAS a4 oe 20 Switeh function: toc yes fh Is SW = 0? YES Ie ee owe? } the value of ctr (7), and) : assign 1 bo SW, Sw 20 Print (ott Ae sw clr 0 a Zz x a £ # 7 | 21. Monitoring alne; Is ctr = 107 NO, | loop and return to a Ct ce + 1, 7 ag +1“rs of vi nieye Printing the OO sequen’ tal continuation 6: 19, No SW ctr 10 START 4 ie ky ee sw » | aig eh WAS a4 oe 20 Switeh function: toc yes fh Is SW = 0? YES Ie ee owe? } the value of ctr (7), and) : assign 1 bo SW, Sw 20 Print (ott Ae sw clr 0 a Zz x a £ # 7 | 21. Monitoring alne; Is ctr = 107 NO, | loop and return to a Ct ce + 1, 7 ag +1: of 10 Printing the ODD sequence integer® ‘continualion 6: 1 No SW ctr in Oo @ STAR! | a ao + of = a 4 "BIN tf 0 oe . 7 ms i ctr er + 1; oe I v | 20 Switch el ves is SW = 0? YES. print Sowao | the value of ct (7), an ee | assign to SW. i tr . Swed Print (ett = ” on i of a 2 + ¥ A # i. Ff e if t F ai OUTPUT Display 1,3, 5,7 ) + = 21. Monitoring counter valloe: ———» icir = 107 NO, eral | loop and retam tony the ODD | resto 7 MMRENCE Teteees of 10 Hiowchar o r z i = F x z & crectr+ |; B= 7+ 1 ‘a 23, Switch function: \ Is SW =07 NO. 4. Monitoring counter Tecir= 107 NO, ctr = 9, Joop and rerum to coWMES:Printing the OD? sequence integers of 10 comtineaition: 5: as. No sw ctr 10 wa fF Sian _ oo TAN ay aes he os t e a= | Z # . ron coe 3 9ey Seah Shag tape ny RY he RB creer | -We d+ 1 ikmercies: Create a floweli chiw 9, 10. Enter 10 numbers and print the 8” number 25 times. ict that will solve the given : Ener (CO members and pecs (he highest are the lorwest mumiber, Eniey 10 immbers and print the 7 surnber and thet sun of the and 149° pumnbete Reser 10 puenbers and print! wom of the EWEN sequen mune Enter if) cumbers and pent the highest eames in the CODD numbers Fister 10 mambers and peint the jowest in the EWEN sequence: Peder 10 nambers asd print the lowest number in the EVEN si and highest in the Odd sequence oumibers, 5 Enter UO) nuenbers and peiat the average of the ODD sequence x and the product of the EVEN sequence eumbers. Enter 10 student grades andl parvo ihe total mumber of passing and failing grades entered (passing grade is 75 and above). Enter 10 nurabers and print the elifference of the highest num odd! sequence and the Jowest number in the EWEN sequem. he numbers of the CTD sequemce| CHAPTER 7 | | | : = Functionswi rroONs Wy ¥ | yl baskethal| ig ¥ vhere Spectar Ske ye team 10 Win, uns Ate up aa their ge NO Watch. 1 ‘Sa Teal crowd gor tne! t with their ions heaping 4 basketball fame ig 5 L Bas ‘ oo Ij wers each pie Player 1D the tenetition between tw teams with § pie ies mong the Players Is iy ally tha a 4 Unique Tole to play. The * sm af orchestrating and Ball Ht or Point Guard: it yes Forward. This POSition has Se - Eame. ‘nother position in i Mjributing the ball and givin tO the uae *SSiSting the bill hare \ p cond tallest position in the tea the eed Mle 10 score \ The welping the Cen This position has a pole Bilis he Center. ™ Cc = ender the basket and on tat ‘ tio ee sing tk CDler ig tallest Player in the team; its pon sk 1S BENING the ball tinder the goals ending the | gor scoring. To make the tam compe, tae combines his eam | Mee wo Forward Players With one Guard, or two i a y » Or two Guard players with il forward player with a Center ang 4 Ball Handler to complete the in er five PHD ‘very Bame, the players perform their duties routinely, the jandier plans, the Center te the Forwards assists the ball ee cute the plan, and the Guards help the See te te Me ie These are the routinary duty of the players: pame er game. bouras ‘ Bir we Can understand that each player has a specific role to we LOOK CHORS Ts form, but no matter what unique function a player performs in a team Ca of ihe team is to play in harmony as one. the goal of i jor parts, the A, program is like a beeketel oe: oe two mor pas the : ogram and the be a eg ei jr orchestrates the implemen Ms | pote 2 esi se oF a ee is interesting i as one to like the other positions 10 nai : ability of all these sub-progr function harmonious! solve the problem. ‘ in this explanation ific task insh The underlying Ost pert co 4. function a junction iS @ apes a ae program. | e ion ca ; eee Popram. For fur unction ons i : iariction is executed. Fi the ine peo iler to after Pe ariable iistructs the compl program of all ioutine and returns to the Mase composed Hain program is the program 143Ayncuons imple entation, hs Ths , bil) inctian calls °C programming. becatige instruction execution Feit nod 1 Other authors refer to aS modules
You might also like
Discrete Structures
PDF
100% (1)
Discrete Structures
174 pages
Bca-222 'C' 'Programming
PDF
No ratings yet
Bca-222 'C' 'Programming
266 pages
BCA 103 - Mathematical Foundation of Computer SC - BCA
PDF
100% (1)
BCA 103 - Mathematical Foundation of Computer SC - BCA
274 pages
Portfolio MSPM 101 Principles of Mathematical Analysis
PDF
No ratings yet
Portfolio MSPM 101 Principles of Mathematical Analysis
16 pages
CSC 122 Data Structure Syllabi
PDF
No ratings yet
CSC 122 Data Structure Syllabi
7 pages
Prolog Versus You - An Introduction To Logic Programming (Johansson, Eriksson-Granskog & Edman
PDF
No ratings yet
Prolog Versus You - An Introduction To Logic Programming (Johansson, Eriksson-Granskog & Edman
298 pages
SAAD Lecture I - Introduction
PDF
No ratings yet
SAAD Lecture I - Introduction
36 pages
INTRODUCTION TO COMPUTING Part1
PDF
No ratings yet
INTRODUCTION TO COMPUTING Part1
9 pages
Lecture Notes On Operating Systems
PDF
80% (5)
Lecture Notes On Operating Systems
157 pages
Information Systems Analysis 488
PDF
No ratings yet
Information Systems Analysis 488
20 pages
Long Quiz 1-B
PDF
No ratings yet
Long Quiz 1-B
11 pages
Computer Architecture
PDF
No ratings yet
Computer Architecture
10 pages
Mathematical Logic Definition: Methods of Reasoning, Provides Rules and Techniques To Determine Whether An
PDF
No ratings yet
Mathematical Logic Definition: Methods of Reasoning, Provides Rules and Techniques To Determine Whether An
13 pages
Fields of Logic and Computation Essays Dedicated To Yuri Gurevich On The Occasion of His 70th Birthday PDF
PDF
No ratings yet
Fields of Logic and Computation Essays Dedicated To Yuri Gurevich On The Occasion of His 70th Birthday PDF
636 pages
Introduction To Java Presentation
PDF
100% (1)
Introduction To Java Presentation
16 pages
Lecture 2 Basic CPU Architectures
PDF
No ratings yet
Lecture 2 Basic CPU Architectures
7 pages
Mathematical Logic
PDF
No ratings yet
Mathematical Logic
47 pages
Discrete Mathematics
PDF
No ratings yet
Discrete Mathematics
61 pages
104 - Programming and Problem Solving Through 'C Language
PDF
No ratings yet
104 - Programming and Problem Solving Through 'C Language
3 pages
NETWORKING - Bits & Bytes - Peprah Adusei
PDF
No ratings yet
NETWORKING - Bits & Bytes - Peprah Adusei
159 pages
Ks Trivedi
PDF
0% (4)
Ks Trivedi
5 pages
Algorithms and Flowcharts 1
PDF
100% (1)
Algorithms and Flowcharts 1
32 pages
Lecture 1 - Neural Network Definitions and Concepts 1
PDF
No ratings yet
Lecture 1 - Neural Network Definitions and Concepts 1
4 pages
Cse1003 Digital-logic-And-Design Eth 1.1 47 Cse1003
PDF
0% (2)
Cse1003 Digital-logic-And-Design Eth 1.1 47 Cse1003
8 pages
Discrete Mathematics
PDF
No ratings yet
Discrete Mathematics
25 pages
Haskell
PDF
No ratings yet
Haskell
597 pages
CSE245 - Discrete Structures
PDF
No ratings yet
CSE245 - Discrete Structures
4 pages
Introduction To Programming Using Java
PDF
No ratings yet
Introduction To Programming Using Java
510 pages
Lecture 07 - Java Operators
PDF
No ratings yet
Lecture 07 - Java Operators
3 pages
Conditional Statements: CSCC 102 Kathrina T. Dacanay
PDF
No ratings yet
Conditional Statements: CSCC 102 Kathrina T. Dacanay
21 pages
Ict Programming "C" Language - Is A General-Purpose, Imperative Computer Programming Language, Supporting Structured
PDF
No ratings yet
Ict Programming "C" Language - Is A General-Purpose, Imperative Computer Programming Language, Supporting Structured
3 pages
Discrete Structures
PDF
No ratings yet
Discrete Structures
4 pages
Chapter 1 - Introduction To Computer Networks Basic Network Concepts
PDF
No ratings yet
Chapter 1 - Introduction To Computer Networks Basic Network Concepts
77 pages
Introduction To Programming
PDF
100% (4)
Introduction To Programming
240 pages
Disadvantages of File Processing System
PDF
No ratings yet
Disadvantages of File Processing System
17 pages
Operators and Expressions in C++
PDF
No ratings yet
Operators and Expressions in C++
32 pages
The Importance of Algorithms
PDF
No ratings yet
The Importance of Algorithms
22 pages
It Security
PDF
No ratings yet
It Security
33 pages
The Rules of Mathematical Logic Specify Methods of Reasoning Mathematical Statements
PDF
No ratings yet
The Rules of Mathematical Logic Specify Methods of Reasoning Mathematical Statements
8 pages
Syllabus-in-Living-in-the-IT-Era-BSIT
PDF
No ratings yet
Syllabus-in-Living-in-the-IT-Era-BSIT
16 pages
Predicate Logic
PDF
No ratings yet
Predicate Logic
30 pages
Number Systems and Codes
PDF
No ratings yet
Number Systems and Codes
78 pages
Ugc Net Solved
PDF
No ratings yet
Ugc Net Solved
39 pages
Automata FiniteAutomata
PDF
No ratings yet
Automata FiniteAutomata
44 pages
Computer Networking Lab 1 - FAST NUCES
PDF
No ratings yet
Computer Networking Lab 1 - FAST NUCES
11 pages
Computer Science Tapestry
PDF
No ratings yet
Computer Science Tapestry
879 pages
Chapter 5 Application Software: Tools For Productivity: Computers Are Your Future, 10e (Coyle)
PDF
No ratings yet
Chapter 5 Application Software: Tools For Productivity: Computers Are Your Future, 10e (Coyle)
9 pages
Discrete Mathematics Syllabus
PDF
No ratings yet
Discrete Mathematics Syllabus
3 pages
C++ Book
PDF
100% (2)
C++ Book
717 pages
Book
PDF
No ratings yet
Book
443 pages
Introduction To Computers and Programming
PDF
No ratings yet
Introduction To Computers and Programming
441 pages
Programming Matlab and C++
PDF
No ratings yet
Programming Matlab and C++
440 pages
Bielajew, A. F. - Introduction To Computers and Programming Using C++ and MATLAB - 2002
PDF
No ratings yet
Bielajew, A. F. - Introduction To Computers and Programming Using C++ and MATLAB - 2002
440 pages
Discussion 1
PDF
No ratings yet
Discussion 1
38 pages
Adobe Scan 28 Apr 2024
PDF
No ratings yet
Adobe Scan 28 Apr 2024
21 pages
Preeri Arora Chapter1 First Year
PDF
No ratings yet
Preeri Arora Chapter1 First Year
26 pages