SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Chapter 4 – Control Structures Part 1 Outline 4.1  Introduction 4.2  Algorithms 4.3  Pseudocode 4.4  Control Structures 4.5  if  Selection Structure 4.6  if/else  Selection Structure 4.7  while  Repetition Structure 4.8  Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) 4.9  Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) 4.10  Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) 4.11  Assignment Operators 4.12  Increment and Decrement Operators 4.13 Introduction to Windows Application Programming
4.1  Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object]
4.2  Algorithms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.3  Pseudocode ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.4  Control Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.4  Control Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.4  Control Structures Fig. 4.1 Flowcharting C#’s sequence structure. add grade to total add 1 to counter total = total + grade; counter = counter + 1;
4.4  Control Structures
4.5  if  Selection Structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.5  if  Selection Structure Fig. 4.3 Flowcharting a single-selection  if  structure. print “Passed” Grade >= 60 true false
4.6  if/else  selection structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.6  if/else  Selection Structure Fig. 4.4 Flowcharting a double-selection  if / else  structure. Grade >= 60 print “Passed” print “Failed” false true
Conditional Operator (?:) ,[object Object],[object Object],[object Object],[object Object],[object Object]
4.7  while  Repetition Structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.7  while  Repetition Structure Fig. 4.5 Flowcharting the  while  repetition structure. true false Product = 2 * product Product <= 1000
4.8  Formulating Algorithms: Case Study 1 (Counter Controlled Repetition) ,[object Object],[object Object],[object Object],[object Object],[object Object]
4.8  Formulating Algorithms: Case Study 1 (Counter Controlled Repetition) Fig. 4.6 Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Add one to the grade counter Set the class average to the total divided by ten Print the class average
Average1.cs 1  // Fig. 4.7: Average1.cs 2  // Class average with counter-controlled repetition. 3  4  using  System; 5  6  class  Average1 7  { 8  static   void  Main(  string [] args ) 9  { 10  int  total,  // sum of grades 11  gradeCounter,  // number of grades entered 12  gradeValue,  // grade value 13  average;  // average of all grades 14  15  // initialization phase 16   total = 0;  // clear total 17   gradeCounter = 1;  // prepare to loop 18  19  // processing phase 20   while  ( gradeCounter <= 10 )  // loop 10 times 21  { 22  // prompt for input and read grade from user 23   Console.Write(  &quot;Enter integer grade: &quot;  ); 24  25  // read input and convert to integer 26  gradeValue = Int32.Parse( Console.ReadLine() ); 27  28  // add gradeValue to total 29   total = total + gradeValue; 30  31  // add 1 to gradeCounter 32   gradeCounter = gradeCounter + 1; 33  } The  while  loop will loop through 10 times to get the grades of the 10 students Initialize gradeCounter to 1 Accumulate the total of the 10 grades Add 1 to the counter so the loop will eventually end Initialize total to 0 Prompt the user to enter a grade
Average1.cs  Program Output 34  35  // termination phase 36   average = total / 10;  // integer division 37  38  // display average of exam grades 39   Console.WriteLine(  &quot;Class average is {0}&quot; , average ); 40  41  }  // end Main 42  43  }  // end class Average1 Enter integer grade: 100 Enter integer grade: 88 Enter integer grade: 93 Enter integer grade: 55 Enter integer grade: 68 Enter integer grade: 77 Enter integer grade: 83 Enter integer grade: 95 Enter integer grade: 73 Enter integer grade: 62 Class average is 79   Divide the total by ten to get the average of the ten grades Display the results
4.9  Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel Controlled Repetition) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.9  Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel Controlled Repetition) Fig. 4.8 Pseudocode algorithm that uses sentinel-controlled repetition to solve the class-average problem. Initialize total to zero Initialize counter to zero Input the first grade (possibly the sentinel) While the user has not as yet entered the sentinel  Add this grade into the running total Add one to the grade counter Input the next grade (possibly the sentinel) If the counter is not equal to zero Set the average to the total divided by the counter Print the average Else Print “No grades were entered”
Average2.cs 1  // Fig. 4.9: Average2.cs 2  // Class average with sentinel-controlled repetition. 3  4  using  System; 5  6  class  Average2 7  { 8  static   void  Main(  string [] args ) 9  { 10  int  total,  // sum of grades 11  gradeCounter,  // number of grades entered 12  gradeValue;  // grade value 13  14   double  average;  // average of all grades 15  16  // initialization phase 17   total = 0;  // clear total 18  gradeCounter = 0;  // prepare to loop 19  20  // processing phase 21  // prompt for input and convert to integer 22   Console.Write(  &quot;Enter Integer Grade, -1 to Quit: &quot;  ); 23  gradeValue = Int32.Parse( Console.ReadLine() ); 24  The variable average is set to a double so that it can be more exact and have an answer with decimals Variables gradeCounter and total are set to zero at the beginning Get a value from the user and store it in gradeValue
Average2.cs 25  // loop until a -1 is entered by user 26   while  ( gradeValue != -1 ) 27  { 28  // add gradeValue to total 29   total = total + gradeValue; 30  31  // add 1 to gradeCounter 32   gradeCounter = gradeCounter + 1; 33  34  // prompt for input and read grade from user 35  // convert grade from string to integer 36   Console.Write(  &quot;Enter Integer Grade, -1 to Quit: &quot;  ); 37  gradeValue = Int32.Parse( Console.ReadLine() ); 38  39  }  // end while 40  41  // termination phase 42   if  ( gradeCounter != 0 )  43  { 44   average = (  double  ) total / gradeCounter; 45  46  // display average of exam grades 47   Console.WriteLine(  &quot;Class average is {0}&quot; , average ); 48   } 49  else 50   { 51   Console.WriteLine(  &quot;No grades were entered&quot;  ); 52   } 53  54  }  // end method Main 55  56  }  // end class Average2 Have the program loop as long as gradeValue is not -1 Accumulate the total of the grades Add 1 to the counter in order to know the student count Prompt the user for another grade, this time it is in the loop so it can happen repeatedly Make sure the total amount of entered grades was not zero to prevent any errors Divide the total by the number of times the program looped to find the average Display the average Inform user if no grades were entered
Average2.cs  Program Output Enter Integer Grade, -1 to Quit: 97 Enter Integer Grade, -1 to Quit: 88 Enter Integer Grade, -1 to Quit: 72 Enter Integer Grade, -1 to Quit: -1 Class average is 85.6666666666667
4.10  Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) ,[object Object],[object Object],[object Object],[object Object]
4.10  Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) Fig. 4.10 Pseudocode for examination-results problem. Initialize passes to zero Initialize failures to zero Initialize student to one   While student counter is less than or equal to ten Input the next exam result   If the student passed Add one to passes Else Add one to failures   Add one to student counter   Print the number of passes Print the number of failures   If more than eight students passed Print “Raise tuition”
Analysis.cs 1  // Fig. 4.11: Analysis.cs 2  // Analysis of Examination Results. 3  4  using  System; 5  6  class  Analysis 7  { 8  static   void  Main(  string [] args ) 9  { 10  int  passes = 0,  // number of passes 11   failures = 0,  // number of failures 12  student = 1,  // student counter 13  result;  // one exam result 14  15  // process 10 students; counter-controlled loop 16   while  ( student <= 10 )  17  { 18  Console.Write(  &quot;Enter result (1=pass, 2=fail): &quot;  ); 19  result = Int32.Parse( Console.ReadLine() ); 20  21   if  ( result == 1 ) 22   passes = passes + 1; 23  24  else   25   failures = failures + 1; 26  27   student = student + 1; 28  } 29 A while loop that will loop 10 times A nested if statement that determines which counter should be added to If the user enters 1 add one to passes If the user enters 2 then add one to failures Keep track of the total number of students Initialize both passes and failures to 0 Set the student count to 1
Analysis.cs  Program Output 30  // termination phase 31  Console.WriteLine(); 32   Console.WriteLine(  &quot;Passed: &quot;  + passes ); 33  Console.WriteLine(  &quot;Failed: &quot;  + failures ); 34  35  if  ( passes > 8 ) 36   Console.WriteLine(  &quot;Raise Tuition&quot;  ); 37  38  }  // end of method Main 39  40  }  // end of class Analysis Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Passed: 9 Failed: 1 Raise Tuition   Display the results to the user If the total number of passes was greater than 8 then also tell the user to raise the tuition
Analysis.cs  Program Output Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Passed: 5 Failed: 5
4.11  Assignment Operators ,[object Object],[object Object],[object Object],[object Object],[object Object]
4.11  Assignment Operators
4.12  Increment and Decrement Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.12  Increment and Decrement Operators
Increment.cs  Program Output 1  // Fig. 4.14: Increment.cs 2  // Preincrementing and postincrementing 3  4  using  System; 5  6  class  Increment 7  { 8  static   void  Main( string [] args) 9  {  10  int  c; 11  12  c = 5; 13  Console.WriteLine( c );  // print 5 14  Console.WriteLine( c++ );  // print 5 then postincrement 15  Console.WriteLine( c );  // print 6 16  17  Console.WriteLine();  // skip a line 18  19  c = 5; 20  Console.WriteLine( c );  // print 5 21  Console.WriteLine( ++c );  // preincrement then print 6 22  Console.WriteLine( c );  // print 6 23  24  }  // end of method Main 25  26  }  // end of class Increment 5 5 6   5 6 6   Declare variable c c is set to 5 Display c (5) Display c (5) then add 1 Display c (6) Display c (6) Add 1 then display c (6) Display c (5) Set c equal to 5
4.12  Increment and Decrement Operators
4.13  Introduction to Windows Application Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4.13  Introduction to Windows Application Programming Fig. 4.16 IDE showing program code for Fig. 2.15.   Collapsed comment Collapsed code
4.13  Introduction to Windows Application Programming Fig. 4.17 Windows Form Designer generated code when expanded.   Expanded code
4.13  Introduction to Windows Application Programming Fig. 4.18 Code generated by the IDE for  welcomeLabel .   Property initializations for  WelcomeLabel Click here for design view Click here for code view
4.13  Introduction to Windows Application Programming Fig. 4.19 Using the  Properties   window to set a property value.   Text  property
4.13  Introduction to Windows Application Programming Fig. 4.20 Windows Form Designer generated code reflecting new property values.
4.13  Introduction to Windows Application Programming Fig. 4.21 Changing a property in the code view editor.   Text  property
4.13  Introduction to Windows Application Programming Fig. 4.22 New   Text   property value reflected in design mode.   Text  property value
4.13  Introduction to Windows Application Programming Fig. 4.23 Method  ASimpleProgram_Load .   ASimpleProgram_Load  method
4.13  Introduction to Windows Application Programming Fig. 4.24 Changing a property value at runtime.

Weitere ähnliche Inhalte

Was ist angesagt?

Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10HUST
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignmentSaket Pathak
 
more loops lecture by Professor Evan korth
more loops  lecture by Professor Evan korth more loops  lecture by Professor Evan korth
more loops lecture by Professor Evan korth hammad ali
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15HUST
 
Equivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysisEquivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysisniharika5412
 
White Box Testing (Introduction to)
White Box Testing (Introduction to)White Box Testing (Introduction to)
White Box Testing (Introduction to)Henry Muccini
 
Whitebox testing
Whitebox testingWhitebox testing
Whitebox testingOana Feidi
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challengesDhanu Srikar
 
Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchartlotlot
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05HUST
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileBlue Elephant Consulting
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2Jomel Penalba
 

Was ist angesagt? (20)

Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 
more loops lecture by Professor Evan korth
more loops  lecture by Professor Evan korth more loops  lecture by Professor Evan korth
more loops lecture by Professor Evan korth
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15
 
Path Testing
Path TestingPath Testing
Path Testing
 
Equivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysisEquivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysis
 
White Box Testing (Introduction to)
White Box Testing (Introduction to)White Box Testing (Introduction to)
White Box Testing (Introduction to)
 
Ch 6 randomization
Ch 6 randomizationCh 6 randomization
Ch 6 randomization
 
White box testing
White box testingWhite box testing
White box testing
 
Whitebox testing
Whitebox testingWhitebox testing
Whitebox testing
 
Ch4 Expressions
Ch4 ExpressionsCh4 Expressions
Ch4 Expressions
 
Sta unit 4(abimanyu)
Sta unit 4(abimanyu)Sta unit 4(abimanyu)
Sta unit 4(abimanyu)
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
 
Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05
 
Path testing
Path testingPath testing
Path testing
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … While
 
Whitebox
WhiteboxWhitebox
Whitebox
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
 

Ähnlich wie Csphtp1 04

04 control structures 1
04 control structures 104 control structures 1
04 control structures 1Jomel Penalba
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptSuleman Khan
 
Chapter 3 Control structures.ppt
Chapter 3 Control structures.pptChapter 3 Control structures.ppt
Chapter 3 Control structures.pptRahulBorate10
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements IReem Alattas
 
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...ronistgdr
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.pptsanjay
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchartJordan Delacruz
 
Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01VincentAcapen1
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxalanfhall8953
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 

Ähnlich wie Csphtp1 04 (20)

Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
 
Ch05
Ch05Ch05
Ch05
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
Chapter 3 Control structures.ppt
Chapter 3 Control structures.pptChapter 3 Control structures.ppt
Chapter 3 Control structures.ppt
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
 
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
algo
algoalgo
algo
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 

Mehr von HUST

Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23HUST
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24HUST
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24HUST
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22HUST
 
Csphtp1 21
Csphtp1 21Csphtp1 21
Csphtp1 21HUST
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20HUST
 
Csphtp1 19
Csphtp1 19Csphtp1 19
Csphtp1 19HUST
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18HUST
 
Csphtp1 17
Csphtp1 17Csphtp1 17
Csphtp1 17HUST
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16HUST
 
Csphtp1 14
Csphtp1 14Csphtp1 14
Csphtp1 14HUST
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13HUST
 
Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12HUST
 
Csphtp1 11
Csphtp1 11Csphtp1 11
Csphtp1 11HUST
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08HUST
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07HUST
 
Csphtp1 03
Csphtp1 03Csphtp1 03
Csphtp1 03HUST
 
Csphtp1 02
Csphtp1 02Csphtp1 02
Csphtp1 02HUST
 
Csphtp1 01
Csphtp1 01Csphtp1 01
Csphtp1 01HUST
 

Mehr von HUST (20)

Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22
 
Csphtp1 21
Csphtp1 21Csphtp1 21
Csphtp1 21
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
 
Csphtp1 19
Csphtp1 19Csphtp1 19
Csphtp1 19
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
Csphtp1 17
Csphtp1 17Csphtp1 17
Csphtp1 17
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16
 
Csphtp1 14
Csphtp1 14Csphtp1 14
Csphtp1 14
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13
 
Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12
 
Csphtp1 11
Csphtp1 11Csphtp1 11
Csphtp1 11
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
 
Csphtp1 03
Csphtp1 03Csphtp1 03
Csphtp1 03
 
Csphtp1 02
Csphtp1 02Csphtp1 02
Csphtp1 02
 
Csphtp1 01
Csphtp1 01Csphtp1 01
Csphtp1 01
 

Kürzlich hochgeladen

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Csphtp1 04

  • 1. Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7 while Repetition Structure 4.8 Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) 4.9 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) 4.10 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) 4.11 Assignment Operators 4.12 Increment and Decrement Operators 4.13 Introduction to Windows Application Programming
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. 4.4 Control Structures Fig. 4.1 Flowcharting C#’s sequence structure. add grade to total add 1 to counter total = total + grade; counter = counter + 1;
  • 8. 4.4 Control Structures
  • 9.
  • 10. 4.5 if Selection Structure Fig. 4.3 Flowcharting a single-selection if structure. print “Passed” Grade >= 60 true false
  • 11.
  • 12. 4.6 if/else Selection Structure Fig. 4.4 Flowcharting a double-selection if / else structure. Grade >= 60 print “Passed” print “Failed” false true
  • 13.
  • 14.
  • 15. 4.7 while Repetition Structure Fig. 4.5 Flowcharting the while repetition structure. true false Product = 2 * product Product <= 1000
  • 16.
  • 17. 4.8 Formulating Algorithms: Case Study 1 (Counter Controlled Repetition) Fig. 4.6 Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Add one to the grade counter Set the class average to the total divided by ten Print the class average
  • 18. Average1.cs 1 // Fig. 4.7: Average1.cs 2 // Class average with counter-controlled repetition. 3 4 using System; 5 6 class Average1 7 { 8 static void Main( string [] args ) 9 { 10 int total, // sum of grades 11 gradeCounter, // number of grades entered 12 gradeValue, // grade value 13 average; // average of all grades 14 15 // initialization phase 16 total = 0; // clear total 17 gradeCounter = 1; // prepare to loop 18 19 // processing phase 20 while ( gradeCounter <= 10 ) // loop 10 times 21 { 22 // prompt for input and read grade from user 23 Console.Write( &quot;Enter integer grade: &quot; ); 24 25 // read input and convert to integer 26 gradeValue = Int32.Parse( Console.ReadLine() ); 27 28 // add gradeValue to total 29 total = total + gradeValue; 30 31 // add 1 to gradeCounter 32 gradeCounter = gradeCounter + 1; 33 } The while loop will loop through 10 times to get the grades of the 10 students Initialize gradeCounter to 1 Accumulate the total of the 10 grades Add 1 to the counter so the loop will eventually end Initialize total to 0 Prompt the user to enter a grade
  • 19. Average1.cs Program Output 34 35 // termination phase 36 average = total / 10; // integer division 37 38 // display average of exam grades 39 Console.WriteLine( &quot;Class average is {0}&quot; , average ); 40 41 } // end Main 42 43 } // end class Average1 Enter integer grade: 100 Enter integer grade: 88 Enter integer grade: 93 Enter integer grade: 55 Enter integer grade: 68 Enter integer grade: 77 Enter integer grade: 83 Enter integer grade: 95 Enter integer grade: 73 Enter integer grade: 62 Class average is 79 Divide the total by ten to get the average of the ten grades Display the results
  • 20.
  • 21. 4.9 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel Controlled Repetition) Fig. 4.8 Pseudocode algorithm that uses sentinel-controlled repetition to solve the class-average problem. Initialize total to zero Initialize counter to zero Input the first grade (possibly the sentinel) While the user has not as yet entered the sentinel Add this grade into the running total Add one to the grade counter Input the next grade (possibly the sentinel) If the counter is not equal to zero Set the average to the total divided by the counter Print the average Else Print “No grades were entered”
  • 22. Average2.cs 1 // Fig. 4.9: Average2.cs 2 // Class average with sentinel-controlled repetition. 3 4 using System; 5 6 class Average2 7 { 8 static void Main( string [] args ) 9 { 10 int total, // sum of grades 11 gradeCounter, // number of grades entered 12 gradeValue; // grade value 13 14 double average; // average of all grades 15 16 // initialization phase 17 total = 0; // clear total 18 gradeCounter = 0; // prepare to loop 19 20 // processing phase 21 // prompt for input and convert to integer 22 Console.Write( &quot;Enter Integer Grade, -1 to Quit: &quot; ); 23 gradeValue = Int32.Parse( Console.ReadLine() ); 24 The variable average is set to a double so that it can be more exact and have an answer with decimals Variables gradeCounter and total are set to zero at the beginning Get a value from the user and store it in gradeValue
  • 23. Average2.cs 25 // loop until a -1 is entered by user 26 while ( gradeValue != -1 ) 27 { 28 // add gradeValue to total 29 total = total + gradeValue; 30 31 // add 1 to gradeCounter 32 gradeCounter = gradeCounter + 1; 33 34 // prompt for input and read grade from user 35 // convert grade from string to integer 36 Console.Write( &quot;Enter Integer Grade, -1 to Quit: &quot; ); 37 gradeValue = Int32.Parse( Console.ReadLine() ); 38 39 } // end while 40 41 // termination phase 42 if ( gradeCounter != 0 ) 43 { 44 average = ( double ) total / gradeCounter; 45 46 // display average of exam grades 47 Console.WriteLine( &quot;Class average is {0}&quot; , average ); 48 } 49 else 50 { 51 Console.WriteLine( &quot;No grades were entered&quot; ); 52 } 53 54 } // end method Main 55 56 } // end class Average2 Have the program loop as long as gradeValue is not -1 Accumulate the total of the grades Add 1 to the counter in order to know the student count Prompt the user for another grade, this time it is in the loop so it can happen repeatedly Make sure the total amount of entered grades was not zero to prevent any errors Divide the total by the number of times the program looped to find the average Display the average Inform user if no grades were entered
  • 24. Average2.cs Program Output Enter Integer Grade, -1 to Quit: 97 Enter Integer Grade, -1 to Quit: 88 Enter Integer Grade, -1 to Quit: 72 Enter Integer Grade, -1 to Quit: -1 Class average is 85.6666666666667
  • 25.
  • 26. 4.10 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) Fig. 4.10 Pseudocode for examination-results problem. Initialize passes to zero Initialize failures to zero Initialize student to one   While student counter is less than or equal to ten Input the next exam result   If the student passed Add one to passes Else Add one to failures   Add one to student counter   Print the number of passes Print the number of failures   If more than eight students passed Print “Raise tuition”
  • 27. Analysis.cs 1 // Fig. 4.11: Analysis.cs 2 // Analysis of Examination Results. 3 4 using System; 5 6 class Analysis 7 { 8 static void Main( string [] args ) 9 { 10 int passes = 0, // number of passes 11 failures = 0, // number of failures 12 student = 1, // student counter 13 result; // one exam result 14 15 // process 10 students; counter-controlled loop 16 while ( student <= 10 ) 17 { 18 Console.Write( &quot;Enter result (1=pass, 2=fail): &quot; ); 19 result = Int32.Parse( Console.ReadLine() ); 20 21 if ( result == 1 ) 22 passes = passes + 1; 23 24 else 25 failures = failures + 1; 26 27 student = student + 1; 28 } 29 A while loop that will loop 10 times A nested if statement that determines which counter should be added to If the user enters 1 add one to passes If the user enters 2 then add one to failures Keep track of the total number of students Initialize both passes and failures to 0 Set the student count to 1
  • 28. Analysis.cs Program Output 30 // termination phase 31 Console.WriteLine(); 32 Console.WriteLine( &quot;Passed: &quot; + passes ); 33 Console.WriteLine( &quot;Failed: &quot; + failures ); 34 35 if ( passes > 8 ) 36 Console.WriteLine( &quot;Raise Tuition&quot; ); 37 38 } // end of method Main 39 40 } // end of class Analysis Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Passed: 9 Failed: 1 Raise Tuition Display the results to the user If the total number of passes was greater than 8 then also tell the user to raise the tuition
  • 29. Analysis.cs Program Output Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 2 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Enter result (1=pass, 2=fail): 1 Passed: 5 Failed: 5
  • 30.
  • 31. 4.11 Assignment Operators
  • 32.
  • 33. 4.12 Increment and Decrement Operators
  • 34. Increment.cs Program Output 1 // Fig. 4.14: Increment.cs 2 // Preincrementing and postincrementing 3 4 using System; 5 6 class Increment 7 { 8 static void Main( string [] args) 9 { 10 int c; 11 12 c = 5; 13 Console.WriteLine( c ); // print 5 14 Console.WriteLine( c++ ); // print 5 then postincrement 15 Console.WriteLine( c ); // print 6 16 17 Console.WriteLine(); // skip a line 18 19 c = 5; 20 Console.WriteLine( c ); // print 5 21 Console.WriteLine( ++c ); // preincrement then print 6 22 Console.WriteLine( c ); // print 6 23 24 } // end of method Main 25 26 } // end of class Increment 5 5 6   5 6 6 Declare variable c c is set to 5 Display c (5) Display c (5) then add 1 Display c (6) Display c (6) Add 1 then display c (6) Display c (5) Set c equal to 5
  • 35. 4.12 Increment and Decrement Operators
  • 36.
  • 37. 4.13 Introduction to Windows Application Programming Fig. 4.16 IDE showing program code for Fig. 2.15. Collapsed comment Collapsed code
  • 38. 4.13 Introduction to Windows Application Programming Fig. 4.17 Windows Form Designer generated code when expanded. Expanded code
  • 39. 4.13 Introduction to Windows Application Programming Fig. 4.18 Code generated by the IDE for welcomeLabel . Property initializations for WelcomeLabel Click here for design view Click here for code view
  • 40. 4.13 Introduction to Windows Application Programming Fig. 4.19 Using the Properties window to set a property value. Text property
  • 41. 4.13 Introduction to Windows Application Programming Fig. 4.20 Windows Form Designer generated code reflecting new property values.
  • 42. 4.13 Introduction to Windows Application Programming Fig. 4.21 Changing a property in the code view editor. Text property
  • 43. 4.13 Introduction to Windows Application Programming Fig. 4.22 New Text property value reflected in design mode. Text property value
  • 44. 4.13 Introduction to Windows Application Programming Fig. 4.23 Method ASimpleProgram_Load . ASimpleProgram_Load method
  • 45. 4.13 Introduction to Windows Application Programming Fig. 4.24 Changing a property value at runtime.