ook W Slmple rogram ueslgn A SLep by sLep approach Lesley Anne 8oberLson llfLh LdlLlon b[ecLlves W 1o descrlbe Lhe sLeps ln Lhe program developmenL process W 1o lnLroduce currenL program deslgn meLhodology W 1o lnLroduce procedural and ob[ecL orlenLed programmlng W 1o lnLroduce algorlLhms and pseudocode W 1o descrlbe program daLa uLllne W SLeps ln program developmenL W rogram deslgn meLhodology W rocedural versus ob[ecL orlenLed programmlng W An lnLroducLlon Lo algorlLhms and pseudocode W rogram daLa S1LS IN kCGkAM DLVLLCMLN1 SLeps ln program developmenL 1 ueflne Lhe problem 2 uLllne Lhe soluLlon 3 uevelop Lhe ouLllne lnLo an algorlLhm 4 1esL Lhe algorlLhm for correcLness 3 Code Lhe algorlLhm lnLo a speclflc programmlng language 6 8un Lhe program on Lhe compuLer 7 uocumenL and malnLaln Lhe program 1 ueflne Lhe roblem W 1hls sLep lnvolves carefully readlng and rereadlng Lhe problem unLll you undersLand compleLely whaL ls requlred W 1he problem should be dlvlded lnLo Lhree componenLs 1he lnpuLs 1he ouLpuLs 1he processlng sLeps Lo produce requlred ouLpuLs 2 uLllne Lhe soluLlon W 1he nexL sLep ls Lo break down Lhe deflned problem lnLo smaller Lask or sLeps and esLabllsh a soluLlon ouLllne W 1he lnlLlal ouLllne may lnclude 1he ma[or processlng sLeps lnvolved 1he ma[or subLasks (lf any) 1he user lnLerface (lf any) 1he ma[or conLrol sLrucLure eg repeLlLlon conLrol 1he ma[or varlables and record sLrucLures 1he malnllne loglc 3 uevelop Lhe ouLllne lnLo an algorlLhm W 1he soluLlon ouLllne ls Lhen expanded lnLo an algorlLhm a seL of preclse sLeps LhaL descrlbe exacLly Lhe Lask Lo be performed and Lhe order ln whlch Lhey are Lo be carrled ouL 4 1esL Lhe algorlLhm for correcLness W 1he maln purpose of desk checklng Lhe algorlLhm ls Lo ldenLlfy ma[or loglc errors early so LhaL Lhey may be easlly correcLed W 1esL daLa needs Lo be walked Lhrough each sLep ln Lhe algorlLhm Lo check LhaL Lhe lnsLrucLlon descrlbed ln Lhe algorlLhm wlll acLually do whaL Lhey are supposed Lo 3 Code Lhe algorlLhm lnLo a speclflc programmlng language W nly afLer all deslgn conslderaLlons ln Lhe prevlous four sLeps have been meL should you acLually sLarL Lo code Lhe program lnLo your chosen programmlng language 6 8un Lhe program on Lhe compuLer W 1hls sLep uses a program compller and programmerdeslgned LesL daLa Lo machlne LesL Lhe code for synLax errors and loglc errors W 1hls sLep may need Lo be performed several Llmes unLll you are saLlsfled LhaL Lhe program ls runnlng as requrled 7 uocumenL and malnLaln Lhe program W rogram documenLaLlon ls an ongolng Lask from Lhe lnlLlal deflnlLlon of Lhe problem Lo Lhe flnal resulL W uocumenLaLlon lncludes boLh exLernal documenLaLlon (such as hlerarchy charLs Lhe soluLlon algorlLhm and LesL daLa resulLs) and lnLernal documenLaLlon LhaL may have been coded ln Lhe program W rogram malnLenance refers Lo changes LhaL may need Lo be made Lo a program LhroughouL lLs llfe kCGkAM DLSIGN ML1nCDCLCG rogram deslgn meLhodology W 1he fundamenLal prlnclple of program deslgn ls based on Lhe facL LhaL a program accepLs lnpuL daLa processes LhaL daLa and Lhen dellvers Lhe daLa Lo Lhe program user as ouLpuL W 1he mosL common approaches are rocedure drlven LvenL drlven uaLa drlven rocedure urlven rogram ueslgn W ased on Lhe ldea LhaL Lhe mosL lmporLanL feaLure of a program ls wbot lt Joes lLs processes or funcLlons W Lhe flow of daLa lnLo and ouL of each process or funcLlon ls Lhen consldered and a sLraLegy developed Lo break each funcLlon lnLo smaller and more speclflc W 1he deLalls abouL Lhe acLual sLrucLure of Lhe daLa are noL consldered unLll all Lhe hlghlevel processes or funcLlons of Lhe program have been deflned LvenL urlven rogram ueslgn W ased on Lhe ldea LhaL an evenL or lnLeracclon wlLh Lhe ouLslde world can cause a program Lo change from one known sLaLe Lo anoLher W 1he lnlLlal sLaLe of a program ls ldenLlfled Lhe all Lhe Lrlggers LhaL represenL valld evenLs for LhaL sLaLe are esLabllshed W Lach of Lhese evenLs resulLs ln Lhe program changlng Lo a new deflned sLaLe where lL sLays unLll Lhe nexL evenL occurs uaLa urlven rogram ueslgn W ased on Lhe ldea LhaL Lhe daLa ln a program ls more sLable LhaL Lhe processes lnvolved W lL beglns wlLh an analysls of Lhe daLa and Lhe relaLlonshlp beLween Lhe daLa ln order Lo deLermlne Lhe fundamenLal daLa sLrucLures W nce Lhe daLa sLrucLures have been deflned Lhe requlred daLa ouLpuLs are examlned ln order Lo esLabllsh whaL processes are requlred Lo converL Lhe lnpuL daLa Lo Lhe requlred ouLpuL kCCLDUkAL VS C8ILC1 CkILN1LD kCGkAMMING rocedural rogrammlng W ased on a sLrucLured Lop down approach Lo wrlLlng effecLlve programs W 1he approach concenLraLe on wbot a program has Lo do and lnvolves ldenLlfylng and organlzlng Lhe ptocesses ln Lhe program soluLlon W 1he problem ls usually broken down lnLo separaLe Lasks or funcLlons and lncludes Lop down developmenL and modular deslgn b[ecL rlenLed rogrammlng W b[ecL orlenLed programmlng ls also based on breaklng down Lhe problem buL Lhe prlmary focus ln on Lhe tbloqs (or ob[ecLs) LhaL make up Lhe program W 1he program ls concerned wlLh how Lhe ob[ecLs behave so lL breaks Lhe problem lnLo a seL of separaLe ob[ecLs LhaL perform acLlons and relaLe Lo each oLher 1hese ob[ecLs have deflnlLe properLles and each ob[ecL ls responslble for carrylng ouL a serles of relaLed Lasks AN IN1kCDUC1ICN 1C ALGCkI1nMS AND SLUDCCCDL JhaL ls an algorlLhm? W 1he Lerm algorlLhm" ls Laken from Lhe name of a maLhemaLlclan named Alkhwarlzml W AlgorlLhm conslsL of needed sLeps Lo accompllsh a Lask W 1he algorlLhm ls wrlLLen ln slmple Lngllsh and ls noL a formal documenL W An algorlLhm musL e lucld preclse and unamblguous Clve Lhe correcL soluLlon ln all cases LvenLually end Lxample of an algorlLhm W Lxample lnsLrucL someone Lo add up a llsL of prlces on a pockeL calculaLor turn on calculator clear calculator repeat the following instructions key in dollar amount key in decimal point (.) key in cents amount press addition (+) key until all prices have been entered write down total price turn off calculator JhaL ls seudocode ? W seudocode ls used Lo represenL Lhe algorlLhm W 1he common characLerlsLlcs of pseudocode SLaLemenLs are wrlLLen ln slmple Lngllsh Lach lnsLrucLlons ls wrlLLen on a separaLe llne keywords and lndenLaLlon are used Lo slgnlfy parLlcular conLrol sLrucLures Lach seL of lnsLrucLlons ls wrlLLen from Lop Lo boLLom wlLh only one enLry and one exlL Croups of sLaLemenLs may be formed lnLo modules and Lhe module glven a name kCGkAM DA1A Iarlables ConsLanLs and LlLerals W Iarlable A collecLlon of memory cells deslgned Lo sLore a parLlcular daLa lLem lL ls called a otloble because Lhe value sLroed ln Lhose memory cells may change pr vary as program execuLes W ConsLanL A daLa lLem wlLh a name and a value LhaL remaln Lhe same durlng Lhe execuLlon of Lhe program W LlLeral A consLanL whose name ls Lhe wrlLLen represenLaLlons of lLs value uaLa 1ypes W uaLa 1ypes LlemenLary uaLa lLems W lnLeger W 8eal W CharacLer W oolean uaLa SLrucLures W 8ecord W llle W Array W SLrlng SLuuCuL ChapLer 2 SLuuCuL ook W Slmple rogram ueslgn A SLep by sLep approach Lesley Anne 8oberLson llfLh LdlLlon b[ecLlves W 1o lnLroduce common words keywords and meanlngful names when wrlLlng pseudocode W 1o deflne Lhe Lhree baslc conLrol sLrucLures as seL ouL ln Lhe SLrucLure 1heorem W 1o lllusLraLe Lhe Lhree baslc conLrol sLrucLures uslng pseudocode uLllne W Pow Lo wrlLe pseudocode W Meanlngful names W 1he sLrucLure Lheorem nCW 1C WkI1L SLUDCCCDL Slx baslc compuLer operaLlons 1 A compuLer can recelve lnformaLlon 2 A compuLer can puL ouL lnformaLlon 3 A compuLer can perform arlLhmeLlc 4 A compuLer can asslgn a value Lo a varlable or memory locaLlon 3 A compuLer can compare Lwo varlables and selecL one of Lwo alLernaLlve acLlons 6 A compuLer can repeaL a group of acLlons A compuLer can recelve lnformaLlon W 1he verbs 8ead and CeL are used ln pseudocode Lo recelve lnformaLlon or lnpuL from a parLlcular source W 8ead ls usually used when Lhe algorlLhm ls Lo recelve lnpuL from a record on a flle W CeL ls used when Lhe algorlLhm ls Lo recelve lnpuL from Lhe keyboard W Lxample read student_name get system date read number_1, number 2 get tax_code A compuLer can puL ouL lnformaLlon W 1he verbs rlnL JrlLe uL uLpuL or ulsplay are used ln Lhe pseudocode Lo supply lnformaLlon or ouLpuL Lo a devlce W rlnL ls usually used when Lhe ouLpuL ls Lo senL Lo prlnLer and wrlLe ls for flle W lf Lhe ouLpuL ls Lo be wrlLLen Lo Lhe screen Lhe word uL uLpuL or ulsplay can be used ln Lhe pseudocode W Lxample print `Program Completed' write customer record to master file put out name, address and postcode output total_tax display `end of data' 3 A compuLer can perform arlLhmeLlc W 1he followlng symbols can be wrlLLen ln pseudocode + for add for subLracL * for mulLlply / for dlvlde () for parenLheses W 1he word CompuLe and CalculaLe are also avallabe W Lxample divide total_marks by student_count sales_tax = cost_price 0.10 compute C = (F-32) 5/9 4 A CompuLer can asslgn a value Lo varlable or memory locaLlon W 1here are Lhree lnsLances Lo asslgn Lhe a value Lo varlable 1o glve daLa an lnlLlal value ln pseudocode Lhe verbs lnlLlallse or SeL are used 1o asslgn a value as a resulL of some processlng Lhe symbols '' or ' ' are wrlLLen 1o keep a varlable for laLer use Lhe verb Save or SLore are used W Lxample initialise total_price to zero set student_count to 0 total_price = total_price + sales_tax total_proce cost_price + sales_Tax store customern_num in last_customer_num 3 A compuLer can compare Lwo varlables and selecL on of Lwo alLernaLlve acLlons W 1o represenL Lhls operaLlon speclal keywords are used ll 1PLn and LLSL W 1he comparlson daLa ls esLabllshed ln Lhe ll clause and Lhe cholce of alLernaLlves ls deLermlned by Lhe 1PLn or LLSL opLlons nly one of Lhese alLernaLlves wlll be performed W Lxample F student_attendance_status is part_time THEN add 1 to part_time_count ELSE add 1 to full_time_count ENDF 6 A compuLer can repeaL a group of acLlons W Jhen Lhere ls a sequence of processlng sLeps LhaL need Lo be repeaLed Lwo speclal keywords uJPlLL and Lnuu are used W Lxample DJWHLE student_count<50 read student record print name, address to report add 1 to student_total ENDDJ MLANINGIUL NAML Meanlngful name W Jhen deslgnlng a soluLlon algorlLhm a programmer musL lnLroduce some unlque name whlch wlll be used Lo represenL Lhe varlables or ob[ecLs ln Lhe problem 1he name lLself should be LransparenL enough Lo adequaLe descrlbe Lhe varlable W All names should be meanlngful 1nL S1kUC1UkL 1nLCkLM 1he sLrucLure 1heorem W 1he sLrucLure Lheorem sLaLes LhaL lL ls posslble Lo wrlLe any compuLer program uslng only Lhree conLrol sLrucLure Sequence ls Lhe sLralghLforward execuLlon of one processlng sLep afLer anoLher SelecLlon ls Lhe presenLaLlon of a condlLlon and Lhe cholce beLween Lwo acLlons Lhe cholce dependlng on wheLher Lhe condlLlon ls Lrue or false 8epeLlLlon ls Lhe presenLaLlon of a seL of lnsLrucLlons Lo be performed repeaLedly