1.2 core programming [understand computer decision structures]

1,501 views
1,324 views

Published on

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,501
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
70
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

1.2 core programming [understand computer decision structures]

  1. 1. Core Programming<br />นายสมเกียรติ สอนนวล<br />Cimatt Business Group Co.,LTD.<br />
  2. 2. Core Programming<br />Understand computerstorage and data types<br />Understand computerdecision structures<br />Identify the appropriatemethod for handlingrepetition<br />Understand errorhandling<br />
  3. 3. Understand computer decision structures<br />Lesson Overview<br />Students will understand the decision structures used by computers. In this lesson, you will learn:<br />Various decision structures used in all computer programming languages<br />if decision structures<br />Multiple decision structures such as if…else and switch/Select Case<br />Reading flowcharts<br />Decision tables<br />Evaluating expressions<br />
  4. 4. Understand computer decision structures<br />Review Terms<br />Relational operator<br />Logical operator<br />and, or, not<br />Boolean<br />Expression<br />Condition<br />Value<br />if<br />else<br /><ul><li>switch
  5. 5. break
  6. 6. case
  7. 7. Algorithm
  8. 8. Compound statement
  9. 9. Nested statements
  10. 10. Precedence</li></li></ul><li>Understand computer decision structures<br />Decisions in Real Life<br />A decision is a statement that says that if something is true, then something will happen as a consequence.<br />For example:<br />If I do the dishes, then I will get my allowance.<br />If Pat gets a 90 percent or above, he will get an A.<br />Decisions are modeled in computers.<br />For example:<br />if (volume > 10)<br />radio.setVolume(2);<br />
  11. 11. Understand computer decision structures<br />Relational Expressions<br />A relational operator is used to compare two values, resulting in a relational expression.<br />For example:<br />number > 16<br />grade == ‘F’<br />passing >= 60<br />A list of relational operators:<br />< less than<br />> greater than<br /><= less than or equal to<br />>= greater than or equal to<br />== equal to<br />!= not equal to<br />
  12. 12. Understand computer decision structures<br />Logical Operators<br />&& and<br />|| or<br />! not<br />
  13. 13. Understand computer decision structures<br />if-else Statement:<br />if (condition)<br />{<br />statement1;<br />}<br />else<br />{<br /> statement2;<br />}<br />
  14. 14. Understand computer decision structures<br />if-else if Statement:<br />if (condition1)<br />{<br /> statement1;<br />}<br />else if (condition2)<br />{<br /> statement2;<br />}<br />else<br />{<br /> statement3;<br />}<br />
  15. 15. Understand computer decision structures<br />switch Statement:<br />intcaseSwitch = 1;<br />switch (caseSwitch)<br />{<br />case 1:<br />Console.WriteLine("Case 1");<br />break;<br />case 2:<br />Console.WriteLine("Case 2");<br />break;<br />default:<br />Console.WriteLine("Default case");<br />break;<br />}<br />
  16. 16. Understand computer decision structures<br />Decision Table<br />A concise way of demonstrating logic<br />Creates an association between conditions and actions to execute<br />
  17. 17. Assignment 1<br />boolisFun = F;<br />boolisKind = F;<br />boolisPopular = T;<br />if isFun && isKind || isPopular;<br />Console.WriteLine("You are my friend.");<br />else<br />Console.WriteLine("Who are you?");<br />
  18. 18. Answer 1<br />boolisFun = false;<br />boolisKind = false;<br />boolisPopular = true;<br />if (isFun && isKind || isPopular)<br />Console.WriteLine("You are my friend.");<br />else<br />Console.WriteLine("Who are you?");<br />
  19. 19. Assignment 2<br />1. You set the high score in Donkey Kong if your score is over 1,050,200 points.<br /> if (score > 1050200)<br />2. Patrick wants to buy a shirt. He will buy the shirt if the shirt's coolness rating is above a 5 out of 10 and the cost is $25 or less.<br /> if ________________________________________________________<br />3. Morgan has different criteria for buying a shirt. The shirt must have at least 3 buttons and cost less than $50.<br /> if ________________________________________________________<br />4. Melissa is deciding whether to date Jarid. She will go out with him if he combed his hair or if he doesn’t smell.<br /> if ________________________________________________________<br />5. Jill has three criteria for deciding whether someone can be her friend. The person can be fun and kind… or they can just be rich.<br /> if ________________________________________________________<br />
  20. 20. Answer 2<br />1. You set the high score in Donkey Kong if your score is over 1,050,200 points.<br /> if(score > 1050200)<br />2. Patrick wants to buy a shirt. He will buy the shirt if the shirt's coolness rating is above a 5 out of 10 and the cost is $25 or less.<br /> if((coolness > 5) && (cost<=25))<br />3. Morgan has different criteria for buying a shirt. The shirt must have at least 3 buttons and cost less than $50.<br /> if((buttons>=3) && (cost < 50))<br />4. Melissa is deciding whether to date Jarid. She will go out with him if he combed his hair or if he doesn’t smell.<br /> if(combed || smell)<br />5. Jill has three criteria for deciding whether someone can be her friend. The person can be fun and kind… or they can just be rich.<br /> if((fun && kind) || rich)<br />

×