Download presentation
Presentation is loading. Please wait.
2
מערכים דו ממדי ו STRUCTS
3
פונקציות בוליאנית 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
4
שינוי בגודל המערך Module Module1 Sub Print(ByVal x() As Integer) 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 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
5
מבוא לתכנות לתו " נ - שבוע מספר 11- אבי רוזנפלד - סמסטר ב ' – תש " ע והנה בעיה כתוב תוכנית אשר תקלוט מספר לא ידוע של מספרים ותדפיס...
6
מבוא לתכנות לתו " נ - שבוע מספר 11- אבי רוזנפלד - סמסטר ב ' – תש " ע בעיה ?
7
מערך דינאמי 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
8
מבוא לתכנות למנע " ס - שבוע מספר 9- מאיר קומר - סמסטר ב ' - תשס " ו הפנייה לתא במערך a (1,3) 879216 011239 105411 892340 4 מי זה ? מערך דו - ממדי
9
דוגמה של קוד Module Module1 Sub Main() Dim a(2, 3) As Integer Dim i, j As Integer For i = 0 To 2 For j = 0 To 3 Console.WriteLine("Enter value for row {0} value {1} ", i, j) a(i, j) = Console.ReadLine() Next Console.WriteLine("Value 1,3 is " & a(1, 3)) End Sub End Module
10
דוגמה נוספת Module Module1 Sub Main() Dim x(9, 9) As Integer Dim i, j As Integer Dim num As New Random() For i = 0 To 9 For j = 0 To 9 x(i, j) = num.Next(1, 10) Next For i = 0 To 9 Console.Write("Now in Row " & i & ":") For j = 0 To 9 Console.Write(" " & x(i, j) & " ") Next Console.WriteLine() Next End Sub End Module
11
חישוב הסכום של עמודה Module Module1 Sub Main() Dim x(9, 9) As Integer Dim i, j As Integer Dim num As New Random() Dim sum As Integer = 0 For i = 0 To 9 For j = 0 To 9 x(i, j) = num.Next(1, 10) Next j = Console.ReadLine() For i = 0 To 9 sum += x(i, j) 'j column set means row changes Next Console.WriteLine("The sum is " & sum) End Sub End Module
12
חישוב הסכום של שורה Module Module1 Sub Main() Dim x(9, 9) As Integer Dim i, j As Integer Dim num As New Random() Dim sum As Integer = 0 For i = 0 To 9 For j = 0 To 9 x(i, j) = num.Next(1, 10) Next i = Console.ReadLine() For j = 0 To 9 sum += x(i, j) 'i row set means column changes Next Console.WriteLine("The sum is " & sum) End Sub End Module
13
מבוא לתכנות למנע " ס - שבוע מספר 9- מאיר קומר - סמסטר ב ' - תשס " ו תרגיל קטן 7216 1239 0411 9340 מערך דו - ממדי
14
פתרון התרגיל Module Module1 Sub Main() Dim x(9, 9) As Integer Dim i, j As Integer Dim num As New Random() Dim sum As Integer = 0 For i = 0 To 9 For j = 0 To 9 x(i, j) = num.Next(1, 10) Next For i = 0 To 9 sum += x(i, i) 'One diagonal sum += x(i, 9 - i) 'Second diagonal Next Console.WriteLine("The sum is " & sum) End Sub End Module
15
Structs (Structures) Module Module1 Structure Oved Public name As String Public maskoret As Integer End Structure Sub Main() Dim x As Oved x.name = "Avi" x.maskoret = 1234 Dim People(10) As Oved People(0).name = "Yossi" People(1).name = "Moshe" People(2).name = "Lea" End Sub End Module
16
עם לולאה... Structure Oved Public name As String Public maskoret As Integer End Structure Sub Main() Dim People(5) As Oved Dim i As Integer For i = 0 To People.Length() - 1 Console.WriteLine("Please enter the person's name") People(i).name = Console.ReadLine Console.WriteLine("Please enter their maskoret") People(i).maskoret = Console.ReadLine Next Console.WriteLine("High " & PrintHighest(People, People.Length())) End Sub
17
ואם פונקציה Function PrintHighest(ByVal x() As Oved, ByVal length As Integer) As Integer Dim i As Integer Dim high As Integer = x(0).maskoret For i = 0 To length - 1 If x(i).maskoret > high Then high = x(i).maskoret End If Next Return high End Function
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.