Download presentation
Presentation is loading. Please wait.
Published byAlexina Richardson Modified over 9 years ago
1
Introduction to C Programming CE00312-1 Lecture 5 Program Design in C
2
Design theory Difference between functional and object- oriented programming paradigm and design of resulting code. Top-down design Stepwise refinement Functional decomposition
3
Design of Processes functional analysis used to design resulting code Break down design into logical blocks Stepwise refinement Functional decomposition
4
Functional Analysis Get up Go to University For as long as there is a lecture to attend Go to lecture Take notes attentively and enthusiastically! Eat tea Go to town For as long as you have money and are thirsty Buy a drink Go home If you have spare money go by taxi Else walk Go Function College Function Food Function Go out Function Go home Function
5
Design Notation Top Down design Problem decomposition expressed as combinations of sequence, selection, iteration both Inter-function and intra- function Level of abstraction or degree of modularity determined by complexity of problem and design notation used Object Design Uses object modeling to determine level of abstraction Problem decomposition determined by object definition Processes expressed as behaviour of objects
6
Top-Down design Take main functions Systematically break into smaller chunks Use a method to ‘represent’ solution Stop when resulting modules are small enough to be easily implemented (but not too cumbersome) ‘Clever’ chunking results in reusable modules
7
Top Down design notation Representative of problem Diagrammatic notation; sequence, selection, iteration JSP Nassi-Scneidermann Pseudo Code/ Structured English Embeds descriptive language into basic construct syntax
8
Pseudocode/Structured English While valid input If mark entry enter name enter mark Case {mark 0 - 39 “refer” mark 40 – 59 “pass” mark 60 – 79 “merit” mark 80 – 100 “Distinction”} else “Error” output name and grade Else Clear
9
Jackson Structured Design Inputs Output
10
Nassi-Schneidermann Enter details While user input If Not Clear Clear R P M DE Output mark & name
11
Testing Purpose of testing Designing test cases and test case data with corresponding input and expected output Black and White box testing Difference between these two categories of test; when test data can be designed and purpose.
12
Black Box testing Black Box testing consists of Categories Functional Tests Invalid Tests Boundary Tests Special Tests
13
White Box testing Categories Path Analysis Complex Conditions
14
Testing Example Consider the example used as one of the week 2 practical exercises; reading in percentage scores greater than 0 and printing out the corresponding letter grade. This is repeated until a negative value is read in. At this stage, the total number of values in each grade range is printed. An error message is printed for any input value greater than 100.
15
Black Box Tests 1. Functional Tests F1: Read in a percentage score and print the corresponding letter grade F2: Produce an error message if a positive number greater than 100 is input F3: Print out the number of input values in each of the letter grade ranges F4: Terminate input when a negative value is read in.
16
2. Invalid Tests I1: A positive number greater than 100 should produce an error message
17
3. Boundary Tests B1: Input largest valid value B2: Input smallest invalid positive value B3: Input lowest valid positive value B4: Input largest invalid negative value B5: Input lowest value in ‘A’ range B6: Input highest value in ‘B’ range B7: Input lowest value in ‘B’ range B8: Input highest value in ‘C’ range B9: Input lowest value in ‘C’ range B10: Input highest value in ‘D’ range B11: Input lowest value in ‘D’ range B12: Input highest value in ‘F’ range
18
4. Special Test Cases S1: First input value is negative S2: No values are input in a particular letter grade range
19
White Box Tests Can only be designed after the code has been written. Complex Conditions None in this example Path Analysis
20
P7 P1 Not P2 P5 P3 Not P3 P4 Not P4 Not P6 Not P5 P6 P2 Path Analysis
21
P1: Initial sequence P2: Value greater than 100 Not P2: Positive value less than or equal to 100 P3: A’ grade Not P3: value below an ‘A’ grade P4: ‘B’ grade Not P4: value below a ‘B’ grade P5: ‘C’ grade Not P5: value below a ‘C’ grade P6: ‘D’ grade Not P6: ‘F’ grade P7: Print out total number of values in each grade range
22
Test Data F1: 90 -2 F2: 110 –2 F3: 67 78 89 90 93 53 54 65 72 73 -3 F4: As for F1 I1: As for F2 B1: 100 -1 B2: 101 -1 B3: 0 -1 B4: -1 B5: As for F1 B6: 89 -1 B7: 80 -1 B8: 79 -1 B9: 70 -2 B10: 69 -1 B11: 60 -1 B12: 59 –1 S1: As for B4 S2: 90 89 78 -1 P1: As for F1 P2: As for F2 P3: As for F1 Not P3: As for B12 P4: As for B7 Not P4: As for B12 P5: As for B9 Not P5: As for B12 P6: As for B12 Not P6: As for F3 P7: As for F1
23
Complex Conditions Consider the following if condition if (age =65) Resulting complex conditions: age =65 C1:TrueTrue C2:TrueFalse C3:FalseTrue C4:FalseFalse C1: impossible C2: age = 16 C3: age = 70 C4: age = 21
24
The number of complex conditions is equal to 2 N, where N is the number of parts to the condition. e.g. if ( age =65) && (gender==’m’ || gender==’f’) 2 4 = 16 conditions
25
Truth Table age =65 gender==’m’gender==’f’ FalseFalseFalseFalse FalseFalseFalseTrue False FalseTrueFalse FalseFalseTrueTrue FalseTrueFalseFalse FalseTrueFalseTrue False TrueTrueFalse False True TrueTrue Repeated with column 1 containing True and columns 2, 3 and 4 unchanged. e.g. C3: age=21, gender=’m’ C4: impossible (gender can’t be both ‘f’ and ‘m’) C6: age = 70, gender=’f’ C9: age = 16 gender =’z’
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.