Presentation is loading. Please wait.

Presentation is loading. Please wait.

May 19, 2015 1  Algorithm and Control  Diversion Handle  Binary Fork  Multiple Choice  Iterative /loop CS220 Introduction to Computer Science Algorithm.

Similar presentations


Presentation on theme: "May 19, 2015 1  Algorithm and Control  Diversion Handle  Binary Fork  Multiple Choice  Iterative /loop CS220 Introduction to Computer Science Algorithm."— Presentation transcript:

1 May 19, 2015 1  Algorithm and Control  Diversion Handle  Binary Fork  Multiple Choice  Iterative /loop CS220 Introduction to Computer Science Algorithm and Control Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

2 May 19, 2015 2  Algorithm and Control  Daily Routine Algorithm Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

3 May 19, 2015 3  Decision Evaluation  C++ allows to evaluate conditions in order to do different operations (decision) Evaluate Decision Making Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

4 May 19, 2015 4  Decision Evaluation  You can test for a condition being true or false, for various values of an expression. Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/  C++ allows to evaluate conditions in order to do different operations (decision) AND ORNot && || ! Both true--> T Either true -->T True --> F Equal == not equal != non-zero Logic

5 May 19, 2015 5  Algorithm and flow of control  Diversion Handle  Binary Fork  Multiple Choice  Iterative / Loop CS220 Introduction to Computer Science Algorithm and Control Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

6 May 19, 2015 6  Diversion Handle Walking Barking Calm down Yes, Scared NoNo Walking; if (dog barking ) { be more careful keep watching out } Continue to walk  Sometimes we have to be interrupted by some sudden event, and after we handle it and continue. Obviously, this is the case with If-statement Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

7 May 19, 2015 7  Diversion Handle  an example  In Visual GUI Check Box, we will decide to offer discount or not, just depends on the checked status ‘ After Calculate Button is clicked, following will be done int quantity = Int.Parse(QTextBox.Text); double = double.Parse(PTextBox.Text); double extPrice; double disc15Single = 0.0;// Initialize double finalPrice; extPriceSingle = quantityInteger * priceSingle; if (DiscountCheckBox.Checked) { disc15Single = 0.15 * extPriceSingle; } finalPrice = extPriceSingle - disc15Single; ETextBox.Text = extPriceSingle.ToString("C") DTextBox.Text = disc15Single.ToString("C") FTextBox.Text = finalPrice.ToString("C") if (discountCheckBox.Checked) { … } Software and Computer Science at APU Basic Flow of Control and Statements

8 May 19, 2015 8  Algorithm and Control  Diversion Evaluation  Binary Fork  Multiple Choice  Iterative / Loop CS220 Introduction to Computer Science Algorithm and Control Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

9 May 19, 2015 9  Life is uncertain  Binary Fork  Facing a fork, you have to choose either, then merge and continue your work Seeking L/R turn right RightLeft turn left Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

10 May 19, 2015 10  Through Check Box, we will decide to offer discount or not, just depends on the checked status If discountCheckBox.Checked Then Software and Computer Science at APU Basic Flow of Control and Statements ‘ After Calculate Button is clicked, following will be done int quantity = Int.Parse(QTextBox.Text); double = double.Parse(PTextBox.Text); double extPrice, disc15Single, finalPrice; extPriceSingle = quantityInteger * priceSingle; if (DiscountCheckBox.Checked) { disc15Single = 0.15 * extPriceSingle; } else { disc15Single = 0.0; } finalPrice = extPriceSingle - disc15Single; ETextBox.Text = extPriceSingle.ToString("C") DTextBox.Text = disc15Single.ToString("C") FTextBox.Text = finalPrice.ToString("C")  Life is uncertain  Binary Fork

11 May 19, 2015 11  Algorithm and Control  Diversion Handle  Binary Fork  Multiple Choice  Iterative / Loop CS220 Introduction to Computer Science Algorithm and Control Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

12 May 19, 2015 12  Facing a multi-choice, you have to choose one from many, then merge and continue your work Seeking LCR turn right RightLeft turn left straight Central Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/  Multi-Choice  Grading Scale

13 May 19, 2015 13  Multi-Choice  Grading Scale  switch and if statement can help us to decide the grading for students’ exam scale int score; char yourGrade; … … if (score >= 90) yourGrade = ‘A’; else if (score >=80) yourGrade = ‘B’; else if (score >=70) yourGrade = ‘C’; else if (score >=60) yourGrade = ‘D’; else yourGrade = ‘F’ ; May 19, 2015 Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/ int score; char yourGrade; … … switch (yourGrade) { case ‘A’: score is 90 + case ‘B’: score is 80 + case ‘C’: score is 70 + case ‘D’: score is 60 + default: score is below 60 }

14 May 19, 2015 14  Algorithm and Control  Diversion Handle  Binary Fork  Multiple Choice  Iterative / Loop CS220 Introduction to Computer Science Algorithm and Control Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

15 May 19, 2015 15  Algorithm and Control  Daily Routine Algorithm Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

16 May 19, 2015 16  For / Loop statement  Basic concept about loop a loop or iterative control structure stands for life long process. for (fclass; class continues; nclass) { Goto class; } Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

17 May 19, 2015 17  while / loop statement  Basic concept about loop First class; while (class continues) { Goto class; Next class; } Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

18 May 19, 2015 18  do while / loop statement  Basic concept about loop first class; do { goto class; next class; } while (class continues) Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/

19 May 19, 2015 19  while statement  guards first while statement Do Until pass_is_valid keep_trying Loop Do While Pass_is_valid keep_doing Loop Arrogant Security while (check first) { keep_doing_something } Check it first SSS: Strict to be safe & secured WWW: Too strict to have a try Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/ Other new forms

20 May 19, 2015 20  do while statement  Check-out last in do-while statement Do keep_trying Loop Until Satisfied Do keep_enjoying Loop While Want Warm Waitress do { keep_doing_something } while (no check) Check it last SSS: loose enough to have try WWW: Too loose to be safe & secured Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/ Other new forms

21 May 19, 2015 21 That is all Thank you very much! Questions? Software and Computer Science at APU Basic Flow of Control and Statements Azusa Pacific University, Azusa, CA 91702, Tel: (800) 825-5278 Department of Computer Science, http://www.apu.edu/clas/computerscience/http://www.apu.edu/clas/computerscience/


Download ppt "May 19, 2015 1  Algorithm and Control  Diversion Handle  Binary Fork  Multiple Choice  Iterative /loop CS220 Introduction to Computer Science Algorithm."

Similar presentations


Ads by Google