Presentation is loading. Please wait.

Presentation is loading. Please wait.

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.

Similar presentations


Presentation on theme: "מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון."— Presentation transcript:

1

2 מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון

3 שלום! המייל של אבי: rosenfa@gmail.comrosenfa@gmail.com המייל של אריאלה: ariellarich@gmail.comariellarich@gmail.com כתובת האתר: www.jct.ac.il/~rosenfa/ibudwww.jct.ac.il/~rosenfa/ibud סילאבוס הקורס: www.jct.ac.il/~rosenfa/ibud/syllabus.htm www.jct.ac.il/~rosenfa/ibud/syllabus.htm

4 מה לומדים? מבנה נתונים אלגוריתמים תכנות WINDOWS

5 דרישות הקורס חשיבה! דרך ארץ! (אין חובת נוכחות!) תרגילים – 20% מבחן – 80%

6 מערכים

7 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע.

8 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו בעיה ?

9 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו הגדרת מערך Dim שם (גודל) As סוג Dim A (9) As Integer הגדרת מערך לדוגמא אבל יש כאן 10 תאים! מערכים Arrays

10 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו 9-40367175 -2 A[5]? Dim A (9) As Integer 7 מערכים Arrays

11 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו מספר כללים מספור התאים - החל מאפס האינדקס חייב להיות בתחום מערכים Arrays

12 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו I A(I) אינדקס תוכן מערכים Arrays שימו לב להבדל

13 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו מערך של מחרוזות Dim A (5) As String moshedavid gadyossiyair avi מערכים Arrays

14 מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו moshedavid gadyossiyair avi מערכים Arrays Len(a(2))3 Mid(a(1),2,3)avi a(2) + a(4)gadyair

15 דוגמא Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer Dim num As New Random() For i = 0 To 10 'Why 10? x(i) = num.Next(1, 10) Next For i = 0 To 10 Console.WriteLine(x(i)) Next End Sub End Module

16 תרגיל כיתה: יש לקלוט 10 מספרים למערך ולהדפיס את הסכום והערך המקסימלי. Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer For i = 1 To 10 'Why not 0? x(i) = Console.ReadLine() Next Dim sum As Integer = 0 Dim max = x(1) For i = 1 To 10 sum += x(i) If (x(i) > max) Then max = x(i) End If Next Console.WriteLine(sum) Console.WriteLine("Max is {0} ", max) End Sub End Module

17 תרגיל כיתה: יש לקלוט 10מספרים למערך. להוסיף לכל מספר את המספר שבא אחריו במערך. למספר האחרון במערך לא להוסיף דבר. יש להדפיס את המערך. Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer For i = 0 To 9 'Why not 10? x(i) = Console.ReadLine() Next For i = 0 To 9 x(i) = x(i) + x(i + 1) Next For i = 0 To 9 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub End Module

18 שיפורים... Module Module1 Sub Main() Dim x(10) As Integer Dim i As Integer Dim len As Integer = x.Length() Console.WriteLine("Length is {0} ", len) For i = 0 To len - 1 'Familiar? x(i) = Console.ReadLine() Next For i = 0 To len - 2 'why - 2? x(i) = x(i) + x(i + 1) Next For i = 0 To len - 1 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub End Module

19 פונקציות קיימות... Module Module1 Sub Main() Dim x() As Integer = {1, 7, 5, 50, -1} Console.WriteLine("Length is {0} ", x.Length()) Console.WriteLine("Position 0 is {0} ", x(0)) Array.Resize(x, 10) Console.WriteLine("Length is {0} ", x.Length()) Console.WriteLine("Position 0 is {0} ", x(0)) Console.WriteLine("But position 9 is {0} ", x(9)) Array.Sort(x) Console.WriteLine("Position 0 is {0} ", x(0)) End Sub End Module

20 פלט Length is 5 Position 0 is 1 Length is 10 Position 0 is 1 But position 9 is 0 Position 0 is -1

21 מבוא לתכנות לתו"נ- שבוע מספר 11- אבי רוזנפלד - סמסטר ב' – תש"ע והנה בעיה כתוב תוכנית אשר תקלוט מספר לא ידוע של מספרים ותדפיס...

22 מבוא לתכנות לתו"נ- שבוע מספר 11- אבי רוזנפלד - סמסטר ב' – תש"ע בעיה ?

23 מערך דינמי Module Module1 Sub Main() Dim x() As Integer = {} Dim answer As String = "yes" While (answer = "yes") Console.WriteLine("Do you want another number?") answer = Console.ReadLine() If (answer = "yes") Then Array.Resize(x, x.Length + 1) Console.WriteLine("Size is now " & x.Length) Console.WriteLine("Now Enter a value") x(x.Length - 1) = Console.ReadLine() End If End While Dim i As Integer For i = 0 To x.Length - 1 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub End Module

24 מערך דינמי - פלט Do you want another number? yes Size is now 1 Now Enter a value 33 Do you want another number? yes Size is now 2 Now Enter a value 45 Do you want another number? no In position 0 I have 33 In position 1 I have 45

25 פונקציות – דוגמא 1 Module Module1 Function Max(ByVal x() As Integer) As Integer Dim temp As Integer = x(0) Dim i As Integer For i = 1 To x.Length - 1 If x(i) > temp Then temp = x(i) End If Next Return temp End Function Sub Main() Dim x() As Integer = {1, 7, 5, 50, -1, 0, 100, -2} Console.WriteLine("The max is " & Max(x)) End Sub End Module The max is 100 פלט:

26 פונקציות – דוגמא 2 Module Module1 Sub Print(ByVal x() As Integer) Dim len As Integer = x.Length - 1 Dim i As Integer Console.WriteLine("Begin the Print Array Sub") For i = 0 To len Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next Console.WriteLine("End of the Print Array Sub") End Sub Sub Main() Dim x() As Integer = {1, 7, 5, 50, -1} Print(x) Array.Resize(x, 10) Print(x) Array.Sort(x) Print(x) Array.Reverse(x) Print(x) End Sub End Module

27 המשך דוגמא 2 - פלט Begin the Print Array Sub In position 0 I have 1 In position 1 I have 7 In position 2 I have 5 In position 3 I have 50 In position 4 I have -1 End of the Print Array Sub Begin the Print Array Sub In position 0 I have 1 In position 1 I have 7 In position 2 I have 5 In position 3 I have 50 In position 4 I have -1 In position 5 I have 0 In position 6 I have 0 In position 7 I have 0 In position 8 I have 0 In position 9 I have 0 End of the Print Array Sub Begin the Print Array Sub In position 0 I have -1 In position 1 I have 0 In position 2 I have 0 In position 3 I have 0 In position 4 I have 0 In position 5 I have 0 In position 6 I have 1 In position 7 I have 5 In position 8 I have 7 In position 9 I have 50 End of the Print Array Sub Begin the Print Array Sub In position 0 I have 50 In position 1 I have 7 In position 2 I have 5 In position 3 I have 1 In position 4 I have 0 In position 5 I have 0 In position 6 I have 0 In position 7 I have 0 In position 8 I have 0 In position 9 I have -1 End of the Print Array Sub

28 פונקציות – דוגמא 3 Sub Print(ByVal x() As Integer) Dim i As Integer Console.WriteLine() Console.WriteLine("Now printing the array") For i = 0 To x.Length() - 1 'why -1 ??? Console.Write(x(i) & " ") If (i + 1) Mod 15 = 0 Then Console.WriteLine("") Next End Sub

29 המשך דוגמא 3 - שימוש בפונקציה Sub Main() Dim i As Integer Dim targetArray(100) As Integer Dim rand As New Random For i = 0 To 100 targetArray(i) = rand.Next(-1000, 1000) Next ' Sort the entire targetArray. Array.Sort(targetArray) Print(targetArray) Array.Reverse(targetArray) Print(targetArray) Array.Resize(targetArray, 10) Array.Sort(targetArray) Print(targetArray) Console.WriteLine(vbNewLine) End Sub

30 המשך דוגמא 3 - פלט Now printing the array -996 -934 -917 -881 -870 -851 -848 -824 -818 -807 -791 -786 -778 -709 -704 -666 -642 -618 -617 -597 -580 -509 -477 -426 -418 -403 -394 -354 -346 -337 -317 -299 -289 -276 -253 -232 -231 -200 -193 -157 -124 -120 -74 -73 -72 -69 -59 -1 20 23 24 113 140 198 228 262 264 272 315 322 324 404 408 408 453 467 479 495 498 513 519 544 554 570 572 584 597 619 633 642 684 703 704 720 731 737 739 776 778 786 798 842 864 876 884 904 971 974 974 997 998 Now printing the array 998 997 974 974 971 904 884 876 864 842 798 786 778 776 739 737 731 720 704 703 684 642 633 619 597 584 572 570 554 544 519 513 498 495 479 467 453 408 408 404 324 322 315 272 264 262 228 198 140 113 24 23 20 -1 -59 -69 -72 -73 -74 -120 -124 -157 -193 -200 -231 -232 -253 -276 -289 -299 -317 -337 -346 -354 -394 -403 -418 -426 -477 -509 -580 -597 -617 -618 -642 -666 -704 -709 -778 -786 -791 -807 -818 -824 -848 -851 -870 -881 -917 -934 -996 Now printing the array 842 864 876 884 904 971 974 974 997 998

31 פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length() - 1 If word1(i) <> word1(word1.Length() - 1 - i) Then Return False End If Next Return True End Function Sub Main() Dim a, b As String a = Console.ReadLine If (Flip(a)) Then Console.WriteLine("It is a palindrome") Else Console.WriteLine("It isn't") End If End Sub End Module

32 עוד דרך לשנות את גודל המערך Module Module1 Sub Main() Dim x() As Integer = {1, 2, 53, 3, 1, 23} Print(x) ReDim Preserve x(10) Print(x) ReDim x(15) Print(x) End Sub End Module פלט: Now printing the array 1 2 53 3 1 23 Now printing the array 1 2 53 3 1 23 0 0 0 0 0 Now printing the array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


Download ppt "מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון."

Similar presentations


Ads by Google