View
59
Download
4
Category
Preview:
DESCRIPTION
עיבוד מידע. ד"ר אבי רוזנפלד. שלום!. כתובת המייל שלי: rosenfa@gmail.com כתובת האתר: www.jct.ac.il/~rosenfa/ibud סילאבוס הקורס: www.jct.ac.il/~rosenfa/ibud/syllabus.htm. מה לומדים?. מבנה נתונים אלגוריתמים תכנות WINDOWS. דרישות הקורס. חשיבה! דרך ארץ! (אין חובת נוכחות!) תרגילים – 15% - PowerPoint PPT Presentation
Citation preview
עיבוד מידע
ד"ר אבי רוזנפלד
שלום!
rosenfa@gmail.comכתובת המייל שלי: •www.jct.ac.il/~rosenfa/ibud כתובת האתר: •סילאבוס הקורס: •
www.jct.ac.il/~rosenfa/ibud/syllabus.htm
מה לומדים?
מבנה נתונים•אלגוריתמים•WINDOWSתכנות •
דרישות הקורס
חשיבה!•דרך ארץ!•)אין חובת נוכחות!(•15%תרגילים – •10%פרויקט אחד – •75%מבחן – •
מערכים
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
והנה בעיה
כתוב תוכנית אשר תקלוט מספרים ותדפיס כמה 36
מתוכם גדולים יותר מהממוצע.
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
בעיה ?
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
הגדרת מערך
Dim (גודל )שם As Dim A )9( As Integerסוג
הגדרתאבל יש כאן לדוגמאמערך
תאים!10
Arraysמערכים
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
9 -4 0 3 6 7 1 7 5 -2
A[5]?
Dim A )9( As Integer
7
Arraysמערכים
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
מספר כללים
מספור התאים - החל •מאפס
האינדקס חייב להיות •בתחום
Arraysמערכים
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
I
A)I(
אינדקס
תוכן
Arraysמערכים
שים לב להבדל
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
מערך של מחרוזותDim A )5( As String
moshe david gad yossi yair avi
Arraysמערכים
מבוא לתכנות למנע"ס - שבוע מספר - מאיר קומר - סמסטר ב' - תשס"ו8
moshe david gad yossi yair avi
Arraysמערכים
Len)a)2(( 3
Mid)a)1(,2,3( avi
a)2( + a)4( gadyair
דוגמא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
תרגיל כיתה: מספרים למערך ולהדפיס את הממוצע 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 also is {0} ", max( End SubEnd Module
תרגיל כיתה: לקלוט עשרים מספרים למערך. להוסיף לכל מספר את המספר שבא אחריו
במערך. למספר האחרון במערך לא להוסיף דבר כלום. יש להדפיס את המערך.
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 SubEnd Module
שיפורים...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 SubEnd Module
פונקציות קיימות...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 SubEnd Module
מבוא לתכנות לתו"נ- שבוע מספר - אבי רוזנפלד - סמסטר ב' – 11
תש"ע
והנה בעיה
כתוב תוכנית אשר תקלוט מספר לא ידוע של מספרים ותדפיס ...
מבוא לתכנות לתו"נ- שבוע מספר - אבי רוזנפלד - סמסטר ב' – 11
תש"ע
בעיה ?
מערך דינאמי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 SubEnd Module
פונקציות!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
פונקציות!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 SubEnd Module
פונקציות נוספות 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
End Module
ניצול של הפונקציות
Module Module1 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
פונקציות בוליאנית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 SubEnd Module
עוד דרך לשנות את גודל המערך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 SubEnd Module
Recommended