This presentation is the property of its rightful owner.
Sponsored Links
1 / 50

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע ( PowerPoint PPT Presentation


  • 63 Views
  • Uploaded on
  • Presentation posted in: General

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע (. ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון. שלום!. המייל של אבי: [email protected] המייל של אריאלה: [email protected] כתובת האתר: www.jct.ac.il /~richards/mivne-algo.htm. מה לומדים?. מבנה נתונים אלגוריתמים תכנות WINDOWS. דרישות הקורס.

Download Presentation

מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע (

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


5367717

) - (

"

"


5367717

!

  • : [email protected]

  • : [email protected]

  • :

    www.jct.ac.il/~richards/mivne-algo.htm


5367717

?

  • WINDOWS


5367717

  • !

  • !

  • ( !)

  • 12%

  • 88%


Strings

Strings


Strings1

hellokita

hello

: - Strings

Dim s As String

s = hello

s = s & kita

s = s + kita


5367717

! ( !)

Dim s,tAs String

s = hello

t = s(2)

t = s.chars(2)

:

t(0) = s(2)

t.chars(0) = s.chars(2)

:


5367717

?

  • Length

  • Remove(start, count ) count start

  • Insert(start, str) str start

  • Replace(str1, str2) str1 str2

  • IndexOf(str), IndexOf(str, start) ( ) str

    • 0 start, -1

  • LastIndexOf(str), LastIndexOf(str, end) ( ) str

    • end, -1

  • SubString(start, count ) count start

  • Chars(start) !


5367717

!

  • :

    s = "hello"

    s.Replace("h", "y")

  • s "hello"

  • s, :

    s = "hello"

    s = s.Replace("h", "y")

  • s "yello"


5367717

ModuleModule1

SubMain()

Dim x AsString

x = Console.ReadLine

Console.WriteLine("The Length is " & x.Length())

Console.WriteLine("The first letter is " & x(0))

Console.WriteLine("The second letter is " & x(1))

Console.WriteLine("The third letter is " & x(2))

Console.WriteLine("What will this do??? " & x(2000))

EndSub

EndModule


5367717

ModuleModule1

Sub Main()

Dim x AsString

x = Console.ReadLine

Console.WriteLine("The first letter is " & x(0))

If (x(0) = "A") Then

Console.WriteLine("Yeah!")

EndIf

If (x(1) = " ") Then

Console.WriteLine("Space in second position")

EndIf

EndSub

EndModule


5367717

ModuleModule1

Sub Main()

Dim word AsString

word = Console.ReadLine

'word(0) = "B" ' Won't work!

word = word.Replace("a", "b")

'word.Replace("a", "b") also won't work

Console.WriteLine("The word now is " & word)

word = word.Remove(0, 2) 'takes out first 2 letters

Console.WriteLine("The word now is " & word)

word = word.Insert(0, "B2") 'add string at position

Console.WriteLine("The word now is " & word)

EndSub

EndModule


5367717

ModuleModule1

Sub Main()

Dim x AsString

Dimi, j AsInteger

x = Console.ReadLine

Console.WriteLine("The Length is " & x.Length())

Fori = 0 Tox.Length() - 1

For j = 0 Toi

Console.Write(x(j))

Next

Console.WriteLine()

Next

EndSub

EndModule


5367717

ModuleModule1

Function Change(ByVal x AsString) AsString

DimiAsInteger

Fori = 0 Tox.Length() - 1

If x(i) = "a"Or x(i) = "e"Or x(i) = "i"Then

x = x.Remove(i, 1) 'Takes out that letter

Console.WriteLine("The word is now " & x)

x = x.Insert(i, "Z") 'Puts something else there

EndIf

Next

Return x

EndFunction

Sub Main()

Dim word AsString

word = Console.ReadLine

Console.WriteLine("The Word is " & Change(word))

EndSub

EndModule


5367717

REF

ModuleModule1

Sub Change(ByRef x AsString)

DimiAsInteger

Fori = 0 Tox.Length() - 1

Ifx(i) = "a"Or x(i) = "e"Or x(i) = "i"Then

x = x.Remove(i, 1) 'Takes out that letter

Console.WriteLine("The word is now " & x)

x = x.Insert(i, "Z") 'Puts something else there

EndIf

Next

EndSub

Sub Main()

Dim word AsString

word = Console.ReadLine

Change(word)

Console.WriteLine("The Word is " & word)

EndSub

EndModule


5367717

VB

  • Len

  • Left

  • Right

  • Mid

  • :

    • 1 0

    • ( )


5367717

Len

ModuleModule1

Sub Main()

Dim word AsString

word = Console.ReadLine

Console.WriteLine(Len(word))

Console.WriteLine(word.Length())

EndSub

EndModule


5367717

he

-

Left

a = hello kita

x = Left (a,2)


5367717

o kita

-

Right

a = hello kita

x = Right (a,6)


5367717

ell

-

Mid

a = hello kita

x = Mid (a,2,3)

-


5367717

s = "arurhamanbaruchmordechai"

Left (s,10) = Mid (s,1,11)?

27

Len (s)

arur h

Left (s,6)

rdechai

Right (s,7)

haman ba

Mid (s,6,8)

ord

Mid (Right(s,9),2,3)

mordechaibaruch

Right (s,9) & Mid (s,11,7)


5367717


5367717

10 . . . .

ModuleModule1

Sub Main()

Dim x(10) AsInteger

DimiAsInteger

DimlenAsInteger = x.Length()

Console.WriteLine("Length is {0} ", len)

Fori = 0 Tolen - 1 'Familiar?

x(i) = Console.ReadLine()

Next

Fori = 0 Tolen - 2 'why - 2?

x(i) = x(i) + x(i + 1)

Next

Fori = 0 Tolen - 1

Console.WriteLine("In pos{0} I have {1} ", i, x(i))

Next

EndSub

EndModule


5367717

...

:

x.Length()

Array.Resize(x, i)

Array.Sort(x)

Array.Reverse(x)

:

x.Length()

x.GetLength(0)

x.GetLength(1)


5367717

Sub Print(ByVal x() AsInteger)

DimiAsInteger

Console.WriteLine()

Console.WriteLine("Now printing the array")

Fori = 0 Tox.Length() - 1 'why -1 ???

Console.Write(x(i) & " ")

If (i + 1) Mod 15 = 0 ThenConsole.WriteLine("")

Next

EndSub


5367717

-

SubMain()

DimiAsInteger

DimtargetArray(100) AsInteger

Dim rand AsNewRandom

Fori = 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)

EndSub


5367717

-

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


Redim

ReDim

ModuleModule1

Sub Main()

Dim x() AsInteger = {1, 2, 53, 3, 1, 23}

Print(x)

ReDimPreserve x(10)

Print(x)

ReDim x(15)

Print(x)

EndSub

EndModule

:

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


Structure

Structure


5367717

    • Structure

      • ""

  • :

    • : , ,

    • : , ",

    • : , ,

    • : ,


Structure1

Structure

:

Structure

1

2

...

End Structure

:

StructureOved

Dim name AsString

DimmaskoretAsInteger

EndStructure


Structs structures

Structs (Structures)

ModuleModule1

StructureOved

Dim name AsString

DimmaskoretAsInteger

EndStructure

Sub Main()

Dim x AsOved

x.name = "Avi"

x.maskoret = 1234

Dim People(10) AsOved

People(0).name = "Yossi"

People(1).name = "Moshe"

People(2).name = "Lea"

Console.WriteLine("People's Size is " & People.Length())

Console.WriteLine("The first name is " & People(0).name)

Console.Write("The length of the first name is ")

Console.WriteLine(People(0).name.Length())

EndSub

EndModule


Structure2

Structure

C++ Programming: From Problem Analysis to Program Design, Fifth Edition


5367717

ModuleModule1

StructureOved

Dim name AsString

DimmaskoretAsInteger

EndStructure

Sub Main()

Dim People(10) AsOved

DimiAsInteger

Fori = 0 To 2

Console.WriteLine("Please enter person number " & i)

People(i).name = Console.ReadLine

People(i).maskoret = Console.ReadLine()

Next

Dim min AsInteger = People(0).maskoret

Dim temp AsString = People(0).name

Fori = 1 To 2

If (People(i).maskoret < min) Then

min = People(i).maskoret

temp = People(i).name

EndIf

Next

Console.WriteLine("The min is " & min & " his name is " & temp)

EndSub

EndModule


5367717

?

ModuleModule1

StructureOved

Dim name AsString

DimmaskoretAsInteger

EndStructure

Sub Main()

Dim People(10) AsOved

DimiAsInteger

Fori = 0 To 2

Console.WriteLine("Please enter person number " & i)

People(i).name = Console.ReadLine

People(i).maskoret = Console.ReadLine()

Next

Dim min AsInteger = 0

Dim temp AsString = People(0).name

Fori = 1 To 2

If (People(i).maskoret < People(min).maskoret) Then

min = i

EndIf

Next

Console.WriteLine("The min is " & People(min).maskoret & " his name is " & People(min).name)

EndSub

EndModule


5367717

...

StructureOved

Public name AsString

PublicmaskoretAsInteger

EndStructure

Sub Main()

Dim People(5) AsOved

DimiAsInteger

Fori = 0 ToPeople.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))

EndSub


5367717

FunctionPrintHighest(ByVal x() AsOved) AsInteger

DimiAsInteger

Dim high AsInteger = x(0).maskoret

Fori = 0 Tox.Length - 1

If x(i).maskoret > high Then

high = x(i).maskoret

EndIf

Next

Return high

EndFunction


5367717

ModuleModule1

Sub Main()

Dim x AsOved

x.name = "Avi"

x.maskoret = 1234

Dim People(10) AsOved

People(0).name = "Yossi"

People(1).name = "Moshe"

People(2).name = "Lea"

Dim value AsInteger = PrintHighest(People)

Console.WriteLine("Highest is " & value)

EndSub

StructureOved

Public name AsString

PublicmaskoretAsInteger

EndStructure

FunctionPrintHighest(ByVal x() AsOved) AsInteger

DimiAsInteger

Dim high AsInteger = x(0).maskoret

Fori = 0 Tox.Length - 1

If x(i).maskoret > high Then

high = x(i).maskoret

EndIf

Next

Return high

EndFunction

EndModule

?


5367717

  • .

    • :

StructureShop

Dim name AsString

Dim code AsInteger

Dim price AsDouble

EndStructure


5367717

ModuleModule1

StructureShop

Dim name AsString

Dim code AsInteger

Dim price AsDouble

EndStructure

Sub Main()

Dimmakolet(10) AsShop

makolet(0).name = "Cheese"

makolet(0).code = 111

makolet(0).price = 8.75

makolet(1).name = "Shnitzel"

makolet(1).code = 222

makolet(1).price = 21.45

makolet(2).name = "Shoko"

makolet(2).code = 122

makolet(2).price = 4.25

DimiAsInteger

Fori = 0 Tomakolet.Length() - 1

Console.WriteLine("Product {0} is: {1}, its price is: {2}", i, makolet(i).name, makolet(i).price)

Next

EndSub

EndModule

Product 0 is: Cheese, its price is: 8.75

Product 1 is: Shnitzel, its price is: 21.45

Product 2 is: Shoko, its price is: 4.25

Product 3 is: , its price is: 0

Product 4 is: , its price is: 0

Product 5 is: , its price is: 0

Product 6 is: , its price is: 0

Product 7 is: , its price is: 0

Product 8 is: , its price is: 0

Product 9 is: , its price is: 0

Product 10 is: , its price is: 0


5367717

ModuleModule1

StructureShop

Dim name AsString

Dim code AsInteger

Dim price AsDouble

EndStructure

Sub Main()

Dimmakolet(10) AsShop

makolet(0).name = "Cheese"

makolet(0).code = 111

makolet(0).price = 8.75

makolet(1).name = "Shnitzel"

makolet(1).code = 222

makolet(1).price = 21.45

makolet(2).name = "Shoko"

makolet(2).code = 122

makolet(2).price = 4.25

DimiAsInteger

Fori = 0 Tomakolet.Length() - 1

Ifmakolet(i).name <> NothingThen

Console.WriteLine("Product {0} is: {1}, its price is: {2}", i, makolet(i).name, makolet(i).price)

EndIf

Next

EndSub

EndModule

Product 0 is: Cheese, its price is: 8.75

Product 1 is: Shnitzel, its price is: 21.45

Product 2 is: Shoko, its price is: 4.25


5367717

ModuleModule1

StructureShop

Dim name AsString

Dim code AsInteger

Dim price AsDouble

EndStructure

Sub Main()

Dimmakolet(10) AsShop

makolet(0).name = "Cheese"

makolet(0).code = 111

makolet(0).price = 8.75

makolet(1).name = "Shnitzel"

makolet(1).code = 222

makolet(1).price = 21.45

makolet(2).name = "Shoko"

makolet(2).code = 122

makolet(2).price = 4.25

PrintPrice(makolet)

EndSub

SubPrintPrice(ByVal s() AsShop)

DimiAsInteger

Fori = 0 Tos.Length() - 1

If s(i).name <> NothingThen

Console.WriteLine("Product {0} is: {1}, its price is: {2}", i, s(i).name, s(i).price)

EndIf

Next

EndSub

EndModule

Product 0 is: Cheese, its price is: 8.75

Product 1 is: Shnitzel, its price is: 21.45

Product 2 is: Shoko, its price is: 4.25


5367717

    • !!!

FunctionGetZol(ByVal s() AsShop) AsString

DimiAsInteger

Dim idx AsInteger = 0

Dim min AsDouble = s(0).price

Fori = 1 Tos.Length() - 1

If s(i).name <> NothingAnd s(i).price < min Then

min = s(i).price

idx = i

EndIf

Next

Return s(idx).name

EndFunction


5367717

  • ( )

  • Sub PrintPrice(ByVal s() As Shop)

  • Function GetZol(ByVal s() As Shop) As String

    • ,


5367717

:

Sub Main()

Dimmakolet(10) AsShop

makolet(0).name = "Cheese"

makolet(0).code = 111

makolet(0).price = 8.75

makolet(1).name = "Shnitzel"

makolet(1).code = 222

makolet(1).price = 21.45

PrintPrice(makolet)

DimzolAsString

zol = GetZol(makolet)

Console.WriteLine("The cheapest thing in makolet is " & zol)

EndSub

Product 0 is: Cheese, its price is: 8.75

Product 1 is: Shnitzel, its price is: 21.45

The cheapest thing in makolet is Cheese


5367717

Sub Main()

Dimmakolet(10) AsShop

makolet(0).name = "Cheese"

makolet(0).code = 111

makolet(0).price = 8.75

makolet(1).name = "Shnitzel"

makolet(1).code = 222

makolet(1).price = 21.45

Dim bakery(10) AsShop

bakery(0).name = "roll"

bakery(0).code = 333

bakery(0).price = 6.32

bakery(1).name = "pita"

bakery(1).code = 777

bakery(1).price = 3.6

PrintPrice(makolet)

DimzolAsString

zol = GetZol(makolet)

Console.WriteLine("The cheapest thing in makolet is " & zol)

PrintPrice(bakery)

zol = GetZol(bakery)

Console.WriteLine("The cheapest thing in bakery is " & zol)

EndSub

? ... ,

Product 0 is: Cheese, its price is: 8.75

Product 1 is: Shnitzel, its price is: 21.45

The cheapest thing in makolet is Cheese

Product 0 is: roll, its price is: 6.32

Product 1 is: pita, its price is: 3.6

The cheapest thing in bakery is pita


5367717

Sub Main()

Dimmakolet(10) AsShop

makolet(0).name = "Cheese"

makolet(0).code = 111

makolet(0).price = 8.75

makolet(1).name = "Shnitzel"

makolet(1).code = 222

makolet(1).price = 21.45

Dimbakery(10) AsShop

bakery(0).name = "roll"

bakery(0).code = 333

bakery(0).price = 6.32

bakery(1).name = "pita"

bakery(1).code = 777

bakery(1).price = 3.6

PrintPrice(makolet)

DimzolAsString

Console.WriteLine("The cheapest thing in makolet is " & GetZol(makolet))

PrintPrice(bakery)

Console.WriteLine("The cheapest thing in makolet is " & GetZol(bakery))

EndSub

Product 0 is: Cheese, its price is: 8.75

Product 1 is: Shnitzel, its price is: 21.45

The cheapest thing in makolet is Cheese

Product 0 is: roll, its price is: 6.32

Product 1 is: pita, its price is: 3.6

The cheapest thing in bakery is pita


5367717

FunctionKupa(ByVal cart() AsString, ByVal s() AsShop) AsSingle

Dim total AsSingle = 0

Fori = 0 Tocart.Length - 1

For j = 0 Tos.Length() - 1

If cart(i) = s(j).name Then

total += s(j).price

EndIf

Next

Next

Return total

EndFunction


5367717

Sub Main()

Dim super(10) AsShop

super(0).name = "Shoko"

super(0).code = 111

super(0).price = 4.75

super(1).name = "Apple"

super(1).code = 222

super(1).price = 2.45

super(2).name = "Bread"

super(2).code = 333

super(2).price = 5.05

super(3).name = "Bag"

super(3).code = 444

super(3).price = 1.2

Dim lunch() AsString = {"Bread", "Shoko"}

Console.WriteLine("Lunch costs " & Kupa(lunch, super) & " shekel.")

EndSub

Lunch costs 9.8 shekel.


5367717

  • ?

    • ?

    • ?

    • ?


  • Login