You are on page 1of 16

CHAPTER 1 INTRODUCTION TO PROBLEM SOLVING

Objectives

Introducing programming concept Introducing technique to develop a program

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

1.1

Definition of Program Programming an! Programmer To under$tand program de$ign in application $o%t&are' u$er $hould (no& de%inition$ o%)

Program"

A $et o% $tep*+,*$tep in$truction$ that direct$ a computer to per%orm a $peci%ic ta$( and to produce the required re$ult$-

Programming"

Programming i$ a proce$$ o% de$igning or creating a program-

Programmer"

Programmer i$ a per$on &ho &rite$ the program-

1.1.1

Ste#$ of Program E%e&'tion

INPUT 0data1

PROCESS 0proce$$or1

OUTPUT 0in%ormation1

In#'t . Re%er to the proce$$ o% entering data' program and in$truction$ into the computer $,$tem u$ing input device$-

Pro&e$$ . Computer proce$$ed ra& data into u$a+le in%ormation to +e u$ed +, u$er- The proce$$ i$ done +, the CP/ 0Central Processing Unit 1-

O't#'t . Output i$ ra& data that ha$ +een proce$$ed +, the computer 0re$ult1Output &ill +e converted to under$tanda+le %orm +e%ore di$pla,ed or printed-

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

E%am#(e" )(o* of ATM #rogram A$$ume that our tran$action i$ mone, &ithdra&al- The in$truction$ are) a- Get card num+er %rom u$er 0Input1 +- Get pin num+er %rom u$er 0Input1 cProce$$ the input data 0Proce$$1 d- Get the tran$action cho$en +, u$er 0Input1 e- Get the account t,pe %rom u$er 0Input1 %Proce$$ the tran$action 0Proce$$1 g- 3ithdra& amount o% mone, required +, u$er 0Output1 h- Print Receipt %or u$er 0Output1

INPUT

PROCESS

OUTPUT

In#'t"

#4ample) Card num+er' pin num+er' t,pe o% tran$action' t,pe o% account' amount o% mone, to &ithdra&-

Pro&e$$"

#4ample) Proce$$ to identi%, card num+er' valid pin num+er' t,pe o% tran$action' t,pe o% account and deduct$ the &ithdra&al %rom u$er account-

O't#'t"

#4ample) Receipt &ill $ho& +alance in u$er account and mone, &ithdra&al-

1.1.+

E%e&'ting A Program To e4ecute a program' CP/ &ill e4amine each program in$truction in memor, and $end out the required command $ignal$ to carr, out the in$truction5uring e4ecution' data can +e entered into memor, and manipulated in $ome $peci%ied &a, 0delete and modi%,1 a$ requiredProgram in$truction$ are u$ed to cop, a program6$ data 0data input1 into memor,A%ter the input data are proce$$ed' in$truction$ %or di$pla,ing or printing are e4ecutedRe$ult di$pla,ed +, a program i$ called 7program output83

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

E%am#(e"

one, &ithdra&al %rom AT

machine-

Ste# 1
Input data) Card !um+er' PI! !um+er' and tran$action-

achine language program %or proce$$ing card num+er and PI! num+er-

Ste# +
Central Proce$$ing /nit-

5ata entered during e4ecution-

Ste# 0
Computed re$ult$Program Output Output re$ult$) Receipt and mone,

)ir$t $te#" 5ata entered +, u$er and $tored in memor, 0input1Se&on! $te#" CP/ &ill in$truct program to proce$$ the card num+er and AT u$er and $tore the re$ult in memor,T,ir! $te#" The output$ are mone, and receipt 0output1pin num+er &ith the data in memor, at the $ame time- Program &ill e4ecute the tran$action choo$e +,

1.+ Programming Pro&e$$ -Programming Life C.&(e/ C.&(e" Re%er$ to the need$ %or change$ o% old program to ne& program 0the c,cle &ill $tart again1Programming Life C.&(e" A %rame&or( or di$cipline' &hich u$ing the technique$ needed in computer programming development-

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

Ste#$ t,at in1o(1e! #rogramming (ife &.&(e"

PROBLEM ANAL2SIS PROBLEM ANAL2SIS PROGRAM DESIGN PROGRAM DESIGN PROGRAM CODING PROGRAM CODING TESTING AND TESTING AND DEBUGGING DEBUGGING MAINTENANCE MAINTENANCE

D O C U M E N T A T I O N

Do&'mentation" Proce$$ o% recording the $tep$ carried out during the developmentDo&'mentation" Proce$$ o% recording the $tep$ carried out during the development#ach $tep mu$t +e completed +e%ore moving to ne4t $tep#ach $tep mu$t +e completed +e%ore moving to ne4t $tep-

STEP 1" PROBLEM ANAL2SIS P'r#o$e" To de$cri+e in detail$ a $olution to a pro+lem +, providing the needed in%ormation %or the pro+lemHow? :ir$t' under$tand ; $tud, the pro+lemIdenti%,) o o o The input to the pro+lemThe required outputThe relevant proce$$- :or e4ample' $cienti%ic %ormula or appropriate theorie$ i% an,3rite a program that get 3 num+er$ a$ input %rom u$er- :ind the average and di$pla, the num+er$ and the averageProblem Analysis: In#'t" Pro&e$$" 3 num+er$1- Add the num+er$ 2- 5ivide the total &ith 3

Pro3(em 1"

Lecturer: Wannoraini Abdul Latif

<

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1
The 3 num+er$ and average

O't#'t"

INPUT

PROCESS

OUTPUT

STEP +" PROGRAM DESIGN Definition" It de%ine$ the %rame&or( or the %lo& or the pro+lem $olution ethod to de$ign a program) 1. A(gorit,m

Algorithm i$ a $equence o% in$truction$ to $olve a pro+lem &ritten in human language and pro+lem can +e $olved i% %ollo& the correct procedure A programmer &rite$ the $olution in the %orm o% an algorithm +e%ore coding it into computer languageE%am#(e of a(gorit,m to &a(&'(ate t,e a1erage of 0 n'm3er$" 1- Set Total=0' average=0> 2- Input 3 num+er$ 3- Total up the 3 num+er$ Total= total o% 3 num+er$ 9- Calculate average average=Total?3 <- 5i$pla, 3 num+er$ and the average

+. )(o*&,art

A graphical repre$entation o% data' in%ormation and proce$$ or an orderl, $tep*+,*$tep $olution to a pro+lemE%am#(e"

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

0. P$e'!o&o!e Step$ in pro+lem $olving &ritten in certain o% programming code and certain in human language:or e4ample' $ome part u$e CAA language code and $ome part u$e #ngli$h*li(e phra$e$ E%am#(e"

START I!P/T a' +' c Total = a A + A c average = Total ? 3 O/TP/T a' +' c O/TP/T average #!5

STEPS 0" PROGRAM CODING Definition" 3rite a $o('tion into a $peci%ic programming language $uch a$ C' CAA' COBO" C include Dio$tream-hE #4ample o% $,nta4 in C7 and etc7 (ang'age toIn$truction$ di$pla, So('tion" +e%ore it i$ coded into programming languagemain0 1 F in$truction %or u$er to P'r#o$e" int a' +' c' Ga$ilTam+ah> enter 3 num+er$ on dou+le purata> To produce a program to develop a $,$temcomputer $creen&o't445 Enter 0 n'm3er$"56 cinEEa EE + EE c> Ga$ilTam+ah = a A + A c> purata = Ga$ilTam+ah ? 3> coutDD a = 7DDa DD8Hn8> coutDD+ = 7DD+DDendl> coutDD8Hnc = 7DDc> Lecturer: Wannoraini Abdul Latif coutDDIAverage i$ = 7DDpurata> return 0> J

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

#4ample o% programming in CAA language)

CincludeDio$tream-hE CincludeDconio-hE main0 1 F int a'+'c> ?? input varia+le$ int $um> ?? varia+le * hold$ the re$ult o% 0a A + A c1 %loat avg> ?? output varia+le clr$cr0 1> ?? A$( u$er to enter 3 num+er$ coutDDIHn Input three num+er$ ) I> cinEEa EE + EE c> $um = a A + A c> ?? calculate the addition o% a' +' c avg = $um ? 3> ?? calculate the average o% a' +' c ?? di$pla, the average o% the 3 num+er$ coutDDIHn Average o% the num+er$ ) IDDavg> return 0> J

O't#'t S&reen" In#'t" Three num+er$ entered +, u$erIn#'t t,ree n'm3er$" 8 8 8 A1erage of t,e n'm3er$" 8.99:

O't#'t) The average o% 3 num+er$

STEP 8" TESTING AND DEBUGGING Definition of Te$ting"

/$ing a $et o% data to di$cover error$ and to en$ure accurac, o% the program-

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

Te$ting Pro&e$$"

5iagram indicate$ the proce$$ o% te$ting#4ecuting Program Output 0%unctioning &ell or error di$covered

Input $ample o% data $et E%am#(e 1"

A$$ume that a program to %ind the average o% 3 num+er$ ha$ +een coded- Then' e4ecute the program &ith a %e& $ample data 0value1 in order to veri%, &hether the program i$ %unctioning &ell and produce the accurate output 0re$ult1Te$ting 1" Input )9'<'K Te$ting +" Input )7'K'@ :rom the output' i$ the program produce the correct outputM

Definition of De3'gging"

An error i$ called a$ bugBug mu$t +e identi%ied and corrected> the proce$$ i$ called de+ugging-

T*o t.#e$ of error" 1. S.nta% Error -grammati&a( error/ Occur$ &hen the rule$ o% programming language are not appliedIt i$ u$uall, %ound and corrected during coding a programCan +e traced +, the compiler during compilationAl$o (no&n a$ compile-time error u$t +e corrected +e%ore e4ecuting and te$ting the program-

+. Logi& error Cannot +e traced +, compilerAl&a,$ %ound and corrected during pro+lem $olvingAl$o (no&n a$ run time error#4ample) The correct output i$ 9 +ut &hen it run$ the output i$ 2S,nta4 error &ill occur i% an, mi$ta(e in the program#4ample) !o $emicolon-

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

"ine L &here the $,nta4 error occurred-

S,nta4 error me$$age

S2NTA< ERROR

CincludeDio$tream-hE Cinclude Dconio-hE main01 F int a' +' c> int $um> %loat avg> clr$cr01> coutDD7Input three num+er$) 7 > cinEEa EE + EE c> $um = a A + A c> avg = $um?@> coutDD7Average o% the three num+er$) 7DDavg> J "ogic error i$ an error that occurred "ogic error i$ an error that occurred +ecau$e o% incorrect o% logical $tatement +ecau$e o% incorrect o% logical $tatement in programin program#4ample) #4ample) Sum i$ total o% the 3 num+er$Sum i$ total o% the 3 num+er$Suppo$ed the average i$ $um ? 3 Suppo$ed the average i$ $um ? 3 +ecau$e there are 3 num+er$+ecau$e there are 3 num+er$-

Logic Error Logic Error In#'t t,ree n'm3er$" 888 A1erage of t,e n'm3er$" +

The &rong output The &rong output

STEP ;" MAINTENANCE Definition"

LOGIC ERROR

Activit, to veri%, that the operational $,$tem i$ $till per%orming a$ planned or modi%ied to enhance the $,$tem to meet the current requirement-

Lecturer: Wannoraini Abdul Latif

10

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

The proce$$ o% changing a $,$tem a%ter it ha$ +een applied i$ to maintain it$ a+ilit,- The change$ ma, involve $imple change$ $uch a$ correct error$' coding and enhancement-

Ho* to !o maintenan&e= B, per%orming activitie$ $uch a$) o o o o o o Te$ting . te$t the a+ilit, o% the $,$temea$urement . acce$$ data time- #4ample' time to $ave, print and other$Replacement . replace the old $,$tem to ne& $,$temAdNu$tment$ . adding need$ to ne& $,$temRepair$ . #4ample' old $,$tem cannot update ne& data' /pdating . modi%, data+a$eaintenance o% Telecommunication S,$tem T#"#OO Telecommunication 7 digit$o digit$o o Programmer &ill change the old $,$tem to ne& $,$tem and te$t the $,$tem &hether it %unctioning &ell or notThen' ne& $,$tem &ill +e te$te! it$ capa+ilit, overall- :or e4ample' te$t the capa+ilit, to identi%, callerP$ and u$erP$ location and time i$ ta(en to connect them 0mea$'rement1o An, old %unction that no longer u$ed &ill +e replaced &ith ne& %unction 0re#(a&ement1A$$ume that management &ant$ to change 7 digit$ to K S,$tem T#"#OO provide$

E%am#(e" o

communication $ervice %rom one hou$e to another hou$e- The telephone num+er i$

STEP >" DOCUMENTATION Definition" 5ocumentation i$ a &ritten report or graphic record o% the $tep$ carried out during the development o% programP'r#o$e) It i$ u$e%ul in the %uture i% the program need$ modi%ication?maintenance- It i$ a re%erence %or the development teamContent of Do&'mentation" o o o o 5e$cription o% the programSpeci%ication requirement o% program Program de$ign $uch a$ p$eudocode and %lo&chart "i$t o% program and comment$ 0to e4plain a+out the program1-

Lecturer: Wannoraini Abdul Latif

11

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

o o o

Te$t re$ult$#nd u$er manualProgram capa+ilitie$ and limitation-

E%am#(e" Pro3(em $o(1ing '$ing t,e $te#$ in Programming Life C.&(e Pro3(em" To calculate total pa,ment %or %ee in pac(age$) Pa&?age 1 -RM ;;/" Pa&?age + -RM ;9/" Pa&?age 0 -RM ;9/" Pa&?age 8 -RM ;;/" Pa&?age ; -RM ;9/" Pa&?age > -RM ;;/" STEP1" Pro3(em Ana(.$i$ In#'t" Su+Nect$ ta(en according to pac(age Pro&e$$" O't#'t" STEP +" A(gorit,m 1- Set pa,ment) Pac(ageQ1) R Pac(ageQ2) R Pac(ageQ3) R Pac(ageQ9) R Pac(ageQ<) R Pac(ageQ@) R 2- Set :ee = 0 3- #nter name and pac(age 9- I% Pac(age = 1 :ee = :ee A Pac(ageQ1 #l$e I% Pac(age = 2 :ee = :ee A Pac(ageQ2 #l$e I% Pac(age = 3 :ee = :ee A Pac(ageQ3 #l$e I% Pac(age = 9 :ee = :ee A Pac(ageQ9 12 << <0 <0 << <0 << Calculate %ee$ +a$ed on the pac(age onthl, %ee$ to pa, Baha$a Baha$a Baha$a ela,u' Baha$a Inggeri$' SeNarah ela,u' atemati(' SeNarah atemati(' Sain$' Geogra%i Baha$a Inggeri$' Sain$' Geogra%i ela,u' Sain$' Geogra%i atemati(' SeNarah Baha$a Inggeri$' urni Tuition Centre- Provided

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

#l$e I% Pac(age = < :ee = :ee A Pac(ageQ< #l$e I% Pac(age = @ :ee = :ee A Pac(ageQ@ #l$e 7Invalid data8

<- 5i$pla, name and %ee )(o*&,art

Lecturer: Wannoraini Abdul Latif

13

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

P$e'!o&o!e START Pac(ageQ1= R Pac(ageQ2= R Pac(ageQ3= R Pac(ageQ9= R

<< <0 <0 << 19

Lecturer: Wannoraini Abdul Latif

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

Pac(ageQ<= R <0 Pac(ageQ@= R << :ee = 0 Input name' Pac(age I% Pac(age = 1 :ee = :ee A Pac(ageQ1 #l$e I% Pac(age = 2 :ee = :ee A Pac(ageQ2 #l$e I% Pac(age = 3 :ee = :ee A Pac(ageQ3 #l$e I% Pac(age = 9 :ee = :ee A Pac(ageQ9 #l$e I% Pac(age = < :ee = :ee A Pac(ageQ< #l$e I% Pac(age = @ :ee = :ee A Pac(ageQ@ #l$e 7Invalid 5ata8 O/P/T name' :ee #!5 STEP 0" Program Co!ing -C Lang'age/ #include <iostream.h> main () { float Package_1= 55, Package_ = 5!, Package_"= 5!, Package_#= 55$ float Package_5= 5! , Package_%= 55, &ee = !$ cout<<'(nter student name)<<*+n*$ cin>> nama$ do{ cout<<'(nter Package)* <<*+n*$ cin >>Package$ if (Package == 1) &ee = &ee , Package_1$ else if (Package == ) &ee = &ee , Package_ $ else if (Package == ") &ee = &ee , Package_"$ else if (Package == #) &ee = &ee , Package_#$ else if (Package == 5) &ee = &ee , Package_5$ else if (Package == %)

Lecturer: Wannoraini Abdul Latif

1<

TCS1073 PROGRA

I!G PRI!CIP"#S

CHAPTER 1

&ee = &ee , Package_%$ else cout<<'-n.alid data*$ cout<<'/o 0ou 1ant to continue2*$ cin>>terus$ 3 1hile (terus == 456)$ cout<<'7ame) *<<nama$ cout<<'8onthl0 fee to 9a0)*<<&ee$

STEP 8" Te$ting an! De3'gging !o error ha$ detected- Program run$ e%%icientl, a%ter te$tingOutput a$ required-

STEP ;" Maintenan&e o o data 0mea$'rement1o An, old %unction that no longer u$ed &ill +e replaced &ith ne& %unction 0re#(a&ement1aintenance to ena+le the program to proce$$ num+er o% $tudent$ in one timeProgrammer &ill modi%, current $,$tem to ne& $,$tem and te$t the $,$tem &hether itP$ %unctioning or notThen' ne& $,$tem &ill +e te$ted overall- :or e4ample' te$t the capa+ilit, to proce$$ $tudentP$ data in one time and the duration to proce$$ the

Lecturer: Wannoraini Abdul Latif

1@