Chapter05
Upcoming SlideShare
Loading in...5
×
 

Chapter05

on

  • 147 views

หลักการเขียนโปรแกรมคอมพิวเตอร์เบื้องต้น โดยใช้ภาษา C# และใช้โปรแกรม RAPTOR ...

หลักการเขียนโปรแกรมคอมพิวเตอร์เบื้องต้น โดยใช้ภาษา C# และใช้โปรแกรม RAPTOR ในการออกแบบ Flowchart

Statistics

Views

Total Views
147
Views on SlideShare
147
Embed Views
0

Actions

Likes
0
Downloads
12
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Chapter05 Chapter05 Presentation Transcript

  • 5 Selecting Programming Company LOGO
  •     Boolean Expression If Nested If Switch…case
  • Boolean Expression      Comparison) equal) Not equal) Less) Greater) Less than or equal to)  Greater than or equal to)
  • X = 10 Y = "com") X == 10 X != 10 X < 10 X > 10 X <= 10 X >= 10 y+"puter" == "computer" Y == "Com" Y != "com" True False False False True True True False False
  • Boolean Expression  Boolean) And)  Or)  Not)
  • A = 10, B = 5, Y = "com", Z = true) A == 10 && B+5 == A) A + B > 10) && B == 5) (B <= A) || (B == A) !(10 == B) !(A >= B) (A == 10) && (Y == "com") (Y == "Com") || (Y == "com") (Y == "Com") || !(Z) !(!(Z)) || !(Z) True False True True False True True False True True
  • If If   condition) If if if…else True else) 2 False
  • If if (condition) statement; (A=5, B=10) If (A == B/2) Console.WriteLine("True"); if (condition) statement; If (B/2 == A) Console.WriteLine(B+"/2 = " + A); if (condition) { statement1; statement2; statement3; : } If (A != B) { Console.WriteLine("A = {0}",A); Console.WriteLine("B = {0}",B); Console.WriteLine("{0} != {1}",A,B); }
  • static void Main(string[] args) { int A = 5; int B = 10; if (A != B) { Console.WriteLine("A = {0}", A); Console.WriteLine("B = {0}", B); Console.WriteLine("{0} != {1}", A, B); } Console.ReadKey(); }
  • static void Main(string[] args) { char Member; float Discount = 0f; Console.Write("Are you Member (Y or N) : "); Member = char.Parse(Console.ReadLine()); if ((Member == 'y') || (Member == 'Y')) { Discount = 0.05f; } Console.WriteLine("Discount is {0:p}", Discount); Console.ReadLine(); }
  • If…else if (condition) statement; else statement; if (condition) { statement1; statement2; : } else { statement1; statement2; : } (A=5, B=10) If (A == B) Console.WriteLine(A+" = " + B); else Console.WriteLine(A+" != " + B); If (A <= B) { Console.WriteLine("A = {0}",A); Console.WriteLine("B = {0}",B); Console.WriteLine("{0} <= {1}",A,B); } else { Console.WriteLine("A = {0}",A); Console.WriteLine("B = {0}",B); Console.WriteLine("{0} > {1}",A,B); }
  • static void Main(string[] args) { int Age, Ticket; Console.Write("How old are You? : "); Age = int.Parse(Console.ReadLine()); if (Age >= 13) { Ticket = 50; } else { Ticket = 20; } Console.WriteLine("You are {0} years old", Age); Console.Write("The price of Ticket is "} Console.Write("{0} Baht", Ticket); Console.ReadLine(); }
  • Nested If If If Nested If If
  • Nested If if (condition) { if (condition) { statement; } } (A=13, B=60) if (A == 13) { if (B == 60) { Console.WriteLine("A = {0} and B = {1}", A, B); } }
  • Nested If if (condition) { if (condition) { statement; } } else { if (condition) { statement; } } (A=13, B=60) if (salary < 1650) { SocialSecurity = 0; } else { if (salary < 15000) { SocialSecurity = salary * 0.05f; } else { SocialSecurity = 15000*0.05f; } }
  • 5 A-F
  • 50 If (Mark < 50) F 60 If (Mark < 60) D 70 If (Mark < 70) C 80 If (Mark < 80) B A
  • 80 If (Mark >= 80) A 70 If (Mark >= 70) B 60 If (Mark >= 60) C 50 If (Mark >= 50) D F
  • Switch…case C# Nested if switch...case
  • switch (expression) { case constant-expression-1: statements; break; case constant-expression-2: statements; break; case constant-expression-3: statements; break; : default: statements; break; } Switch…case using System; namespace SwitchCase { class Program { static void Main(string[] args) { char Operator; int A = 5, B = 10, Total; Operator = char.Parse(Console.ReadLine()); switch(Operator) { case '+': Total = A + B; break; case '-': Total = A - B; break; case '*': Total = A * B; break; case '/': Total = A / B; break; default: Total = 0; break; } Console.WriteLine("Answer is {0}", Total); } } }
  • Switch…case RAPTOR default If If switch…case switch…case char) switch…case If integer) string)
  • Try…catch  C# Console.ReadLine() int int int.Parse(Console.ReadLine()) A try…catch…finally A
  • int Operator = 0; int A = 5, B = 10, Total; try { Operator = int.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Input is not integer...Error!!!"); } finally { Console.WriteLine("Write everytime"); }
  • try...catch...finally       Run Time Process) Init Process) Block try Block catch Block finally 1 try Block catch Block finally try 1 Block
  •   5 /