מבוא למדעי המחשב לתעשייה וניהול

Slides:



Advertisements
Similar presentations
מבוא למדעי המחשב לתעשייה וניהול
Advertisements

Chapter 10 Review. Write a method that returns true is s1 and s2 end with the same character; otherwise return false. Sample Answer: public boolean lastChar(String.
Java Strings in 10 minutes
מבוא למדעי המחשב לתעשייה וניהול דוגמאות ותרגול נוסף במערך חד ממדי הרצאה 12.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
מחרוזות של תווים. מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו מחרוזות - Strings Dim s As String s = “hello” s = s & “kita” או s =
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב'
רשימה מקושרת Linked Lists. דוגמא STRING איך עושים Dim x as String בלי לדעת מראש את הגודל !
תכנות תרגול 9 שבוע : הקשר בין מערכים למצביעים נרצה לעמוד על הקשר בין מערך למצביע מאחר ומערכים הם הכללה של משתנים הרי שברור שלמערך ולכל אחד מאיבריו.
סוגי מידע / משתנים ד " ר אבי רוזנפלד. סוגאורךטווח Boolean1 Bit0,1 Byte1 byte0-255 Char 2 bytes תו Decimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335.
מבוא לשפת C חידות ונקודות חשובות נכתב על-ידי יורי פקלני. © כל הזכויות שמורות לטכניון – מכון טכנולוגי לישראל.
מבוא למדעי המחשב תרגול 8 - מחרוזות שעת קבלה : יום שני 11:00-12:00 דוא " ל :
תרגילים. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader.
11 Introduction to Programming in C - Fall 2010 – Erez Sharvit, Amir Menczel 1 Introduction to Programming in C תרגול
אלגוריתמים, WINDOWS והחיים. מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 מיוןsort.
מבני בקרה מבוא לתכנות למנע " ס - שבוע מספר 3 - מאיר קומר - סמסטר ב ' - תשס " ו הסתעפות “ אם השמאל ואימנה ואם הימין ואשמאילה ”
#include void main() { int i; char c; char st1[]="abcd"; for (i=-128;i
פתרון תרגיל 10. שאלה #1 Module Module1 Sub Main() Dim maarach(9), zoogy(4), ezoogy(5) As Integer Dim i, counter, j As Integer For i = 0 To 9 Console.WriteLine("please.
תכנות תרגול 10 שבוע : הקשר בין מערכים למצביעים נרצה לעמוד על הקשר בין מערך למצביע מאחר ומערכים הם הכללה של משתנים הרי שברור שלמערך ולכל אחד מאיבריו.
פתרון בוחן הכיתה. שאלה #1 Module Module1 Sub Main() Dim x, z As Integer x = Console.ReadLine() z = Console.ReadLine() If (x = 0) Then Console.WriteLine("Error")
1 Introduction to Programming in C - Fall 2010 – Erez Sharvit, Amir Menczel 1 Introduction to Programming in C תרגול
פתרון תרגיל 11. שאלה #1 Module Module1 Sub Main() Dim x(10, 10) As Integer Dim i, j As Integer For i = 1 To 10 For j = 1 To 10 x(i, j) = i * j Console.Write("
מערכים מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע.
מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.
תכנות תרגול 5 שבוע : הגדרת פונקציות return-value-type function-name(parameter1, parameter2, …) הגדרת סוג הערכים שהפונקציה מחזירה שם הפונקציהרשימת.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Templates תבניות.
מבוא למדעי המחשב תרגול 3 שעת קבלה : יום שני 11:00-12:00 דוא " ל :
פתרון תרגילים #9. דוגמה פשוטה #1 Module Module1 Sub Main() Dim x As String x = Console.ReadLine For i = 1 To x.Length() - 1 Step 2 Console.WriteLine(x(i))
מערכים דו ממדי ו STRUCTS פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length()
מבוא למדעי המחשב תרגול 9 – מערכים ומחרוזות, תרגילי חזרה שעת קבלה : יום שני 11:00-12:00 דוא " ל :
פונקציות. פונקציות מוכרות Imports System.Math Module Module1 Sub Main() Dim x As Decimal = Math.Abs(-10.4) Dim y As Decimal Console.WriteLine("I will.
Structure. מה לומדים היום ? דרך לבנות מבנה נתונים בסיסי – Structure מייצר " טיפוס " חדש מתאים כאשר רוצים לאגד כמה משתנים יחד דוגמאות : עובד : שם, טלפון,
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
26/10/ Selection Nested If structures & Complex Multiple Conditions.
String Manipulation. Strings have their own properties and methods, just like a textbox or label or form does.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
מבוא למדעי המחשב לתעשייה וניהול הרצאה 7. סברוטינות subroutines.
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
הרצאה 3 מבוא למדעי המחשב לתעשייה וניהול הודעות : הודעות : או דרך moodle – ושם לפנות ל : אתר מכון טל החומר.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 12. ספריות.
String Manipulation 10/21/2015 Lect#6 GC Strings have their own properties and methods, just like a textbox or label or form does. 10/21/2015 Lect#6.
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
מבוא למדעי המחשב לתעשייה וניהול הרצאה 6. מפעל השעווה – לולאות  עד עכשיו  טיפלנו בייצור נרות מסוג אחד, במחיר אחיד  למדנו להתמודד עם טיפול במקרים שונים.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
1 נתבונן בפונקציה הבאה public static int min(int[] a,int n) { int min = a[0]; for (int i = 1; (i < n ) && (i < a.length) ; i++) if (min > a[i]) min = a[i];
Python Strings. String  A String is a sequence of characters  Access characters one at a time with a bracket operator and an offset index >>> fruit.
1 Comparing Strings zLcase(string) --- converts a string to lower case Mystring = lcase(yourstring) zUcase(string) --- converts a string to upper case.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
String Manipulation Reference:
מחרוזות – הטיפוס String
Strings A String is a sequence of letters
Java String Methods - Codehs
Objective 7.04 Apply Built-in String Functions (3%)
String Manipulation Reference:
Compiler Design First Lecture.
מחלקות classes.
מחרוזות קרן כליף.
MSIS 655 Advanced Business Applications Programming
נושאים מחרוזות מיון (מיון בועות)
String Manipulation Reference:
מחרוזות קרן כליף.
מחסנית ותור Stacks and Queues.
String Manipulation Reference:
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

מבוא למדעי המחשב לתעשייה וניהול הרצאה 9

שרשור (חיבור) של מחרוזות (& או +) Module Module1 Sub Main() Dim s As String s = "Hello to you" s = s & " and you too" Console.WriteLine(s) s = s + " and you three ;)" End Sub End Module

פונקציות על מחרוזות Length Remove Insert Replace IndexOf LastIndexOf SubString Chars

אורך של מחרוזות Length Length מחזירה אורך של מחרוזת Module Module1 Sub Main() Dim x As Integer Dim str As String str = Console.ReadLine() x = str.Length() Console.WriteLine("The length of the string is: " & x) Console.WriteLine("and also " & str.Length()) End Sub End Module

הסרה ממחרוזות Remove Remove(start, count ) מסירה count תווים החל מהמקום start ומחזירה את המחרוזת החדשה Module Module1 Sub Main() Dim str As String = "This is my string" Dim str2 As String str2 = str.Remove(0, 8) Console.WriteLine(str2) End Sub End Module

הוספה למחרוזות Insert Insert(start, str) מוסיפה את המחרוזת str החל מהמקום start ומחזירה את המחרוזת החדשה Module Module1 Sub Main() Dim str As String = "This is my string" Dim str2 As String str2 = str.Insert(11, "nice ") Console.WriteLine(str2) Dim str3 As String = "very " str2 = str2.Insert(11, str3) End Sub End Module

החלפה במחרוזות Replace Replace(str1, str2) מחליפה את המחרוזת str1 במחרוזת str2 Replace(ch1, ch2) מחליפה את התו ch1 בתו ch2 בכל מקרה מחזירה את המחרוזת החדשה Module Module1 Sub Main() Dim str As String = "This is my string" Dim str2 As String str2 = str.Replace("my", "your") Console.WriteLine(str2) str2 = str.Replace("s", "X") End Sub End Module

החלפה במחרוזות IndexOf IndexOf(str) מחזירה מיקום של המחרוזת (או התו) str במחרוזת מיקום מתחיל מ 0, אם לא נמצא מחזיר -1 IndexOf(str, start) מחזירה מיקום של המחרוזת (או התו) str במחרוזת מיקום מתחיל מ start, אם לא נמצא מחזיר -1 Module Module1 Sub Main() Dim s As String s = "This is a nice string" Dim place As Integer = 0 place = s.IndexOf("i") While place <> -1 Console.WriteLine("i is at place " & place) place = s.IndexOf("i", place + 1) End While End Sub End Module

החלפה במחרוזות LastIndexOf LastIndexOf(str) מחזירה מיקום מסוף המחרוזת (או התו) str מיקום מתחיל מסוף המחרוזת, אם לא נמצא מחזיר -1 LastIndexOf(str, end) מחזירה מיקום מסוף המחרוזת (או תו) str מיקום מתחיל מ end, אם לא נמצא מחזיר -1 Module Module1 Sub Main() Dim s As String s = "This is a nice string" Dim place As Integer = 0 place = s.LastIndexOf("i") While place <> -1 Console.WriteLine("i is at place " & place) place = s.LastIndexOf("i", place - 1) End While End Sub End Module

חלק ממחרוזת SubString SubString(start, count ) מייצרת מחרוזת של count תווים החל מהמקום start ומחזירה את המחרוזת החדשה Module Module1 Sub Main() Dim str As String Console.WriteLine("Please enter a string") str = Console.ReadLine() Dim p1 As Integer = str.IndexOf("a") str = str.Substring(p1 + 1, 5) Console.WriteLine("the five letters after a are:" & str) End Sub End Module

שליפת תו ממחרוזת Chars Module Module1 Sub Main() Dim myString As String = "ABCDE" Dim myChar As Char myChar = myString.Chars(3) 'value of myChar is D. myChar = myString(2) 'גם זה עובד , value is C End Sub End Module

דוגמא Module Module1 Sub Main() Dim x As String x = Console.ReadLine Console.WriteLine("The first letter is " & x(0)) If (x(0) = "A") Then Console.WriteLine("Yeah!") End If If (x(1) = " ") Then Console.WriteLine("Space in second position") End Sub End Module

השוואת מחרוזות למחרוזות יש סדר הסדר הוא כמו סדר במילון apple < banana Abc < Aef אותיות גדולות (כולן) לפני האותיות הקטנות לכן Banana < apple ולכן ניתן להשוות בין מחרוזות...

השוואת מחרוזות Module Module1 Sub Main() Dim firstStr As String = Console.ReadLine() Dim secondStr As String = Console.ReadLine() If firstStr < secondStr Then Console.WriteLine("{0} is before {1} ", firstStr, secondStr) ElseIf firstStr > secondStr Then Console.WriteLine("{1} is before {0} ", firstStr, secondStr) Else Console.WriteLine("{0} is same as {1} ", firstStr, secondStr) End If End Sub End Module

דוגמא Module Module1 Sub Main() Dim name As String = "Amit Yoav Cohen" Console.WriteLine("The entire name is '{0}'", name) Dim p1 As Integer = name.IndexOf(" ") Dim p2 As Integer = name.IndexOf(" ", p1 + 1) If p1 <> p2 And p1 >= 0 Then ' remove the middle name name = name.Remove(p1 + 1, p2 - p1) Console.WriteLine("After removing middle: " & name) End If End Sub 'Main End Module

דוגמא נוספת Module Module1 Sub Main() Dim x As String Dim i, j As Integer x = Console.ReadLine Console.WriteLine("The Length is " & x.Length()) For i = 0 To x.Length() - 1 For j = 0 To i Console.Write(x(j)) Next Console.WriteLine() End Sub End Module

דוגמא לשימוש בפונקציה עם מחרוזת Module Module1 Function mult(ByVal x As String, ByVal n As Integer) Dim str As String = "" For i = 1 To n str += x + " " Next Return str End Function Sub Main() Dim x As String x = Console.ReadLine Dim y As String = mult(x, 3) Console.WriteLine("The multiplied string is " & y) End Sub End Module

עוד פונקציה עם מחרוזת Module Module1 Function Change(ByVal x As String) As String Dim i As Integer For i = 0 To x.Length() - 1 If x(i) = " " Or x(i) = "," Then x = x.Remove(i, 1) 'Takes out sign x = x.Insert(i, ";") 'Puts something else there End If Next Return x End Function Sub Main() Dim str As String str = Console.ReadLine Console.WriteLine("after change: " & Change(str)) End Sub End Module

שימוש ב ByRef Module Module1 Sub Change(ByRef x As String) Dim i As Integer For i = 0 To x.Length() - 1 If x(i) = " " Or x(i) = "," Then x = x.Remove(i, 1) 'Takes out sign x = x.Insert(i, ";") 'Puts something else there End If Next End Sub Sub Main() Dim str As String str = Console.ReadLine Change(str) Console.WriteLine("after change: " & str) End Module

פונקציה בוליאנית ומחרוזת – חלק 1 – מהעושה הפונקציה? Module Module1 Function MyC (ByVal str1 As String, ByVal str2 As String) As Boolean Dim i As Integer If (str1.Length <> str2.Length) Then Return False Else For i = 0 To str1.Length() - 1 If str1(i) <> str2(i) Then End If Next Return True End Function המשך בשקף הבא...

פונקציה בוליאנית ומחרוזת – חלק 2 המשך... Sub Main() Dim a, b As String a = Console.ReadLine b = Console.ReadLine If (a = b) Then Console.WriteLine("They are the same") End If If (MyC (a, b)) Then Console.WriteLine("They are still the same") End Sub End Module

עוד דוגמא – חלק 1 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 המשך בשקף הבא...

עוד דוגמא – חלק 2 המשך... 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