פונקציות. פונקציות מוכרות Imports System.Math Module Module1 Sub Main() Dim x As Decimal = Math.Abs(-10.4) Dim y As Decimal Console.WriteLine("I will.

Slides:



Advertisements
Similar presentations
מבוא למדעי המחשב לתעשייה וניהול דוגמאות ותרגול נוסף במערך חד ממדי הרצאה 12.
Advertisements

מחרוזות של תווים. מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו מחרוזות - Strings Dim s As String s = “hello” s = s & “kita” או s =
If – Case Programs CSC Arwa © 2008.
סוגי מידע / משתנים ד " ר אבי רוזנפלד. סוגאורךטווח Boolean1 Bit0,1 Byte1 byte0-255 Char 2 bytes תו Decimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335.
תכנות ב C#. דוגמא לפלט using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void.
תרגילים. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader.
אלגוריתמים, WINDOWS והחיים. מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 מיוןsort.
מבני בקרה מבוא לתכנות למנע " ס - שבוע מספר 3 - מאיר קומר - סמסטר ב ' - תשס " ו הסתעפות “ אם השמאל ואימנה ואם הימין ואשמאילה ”
פתרון תרגיל 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.
פתרון בוחן הכיתה. שאלה #1 Module Module1 Sub Main() Dim x, z As Integer x = Console.ReadLine() z = Console.ReadLine() If (x = 0) Then Console.WriteLine("Error")
פתרון תרגיל 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("
PSU CS 106 Computing Fundamentals II VB Statements HM 5/19/2008.
מערכים מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע.
מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
פתרון תרגילים #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()
VB – Core III Functions Sub-routines Parameter passing Modules Scope Lifetime.
= 9 = 8 = 12 = 19 = 2 = 3 = 17 = 5 = 11 = 5.
الحلقات for For i =1 To x step -2 …………. Next DO while (شرط) …………. Loop DO …………. Loop while (شرط) الحلقة Do while.
Structure. מה לומדים היום ? דרך לבנות מבנה נתונים בסיסי – Structure מייצר " טיפוס " חדש מתאים כאשר רוצים לאגד כמה משתנים יחד דוגמאות : עובד : שם, טלפון,
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
Subroutines and Functions Chapter 6. Introduction So far, most of the code has been inside a single method for an event –Fine for small programs, but.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
1.3 Console Input And Output academy.zariba.com 1.
Subroutines and Functions. Introduction So far, most of the code has been inside a single method for an event –Fine for small programs, but inconvenient.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
Type your question here. Type Answer Type your question here. Type Answer.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 7. סברוטינות subroutines.
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
مسألة أكتب برنامجاً يقوم بقراءة عددين و إظهار رسالة تفيد بأن أحد العددين هو المضاعف النوني للعدد الآخر و في حال عدم كون أي من العددين مضاعفاً للآخر يظهر.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 12. ספריות.
Bubble Sort Notes David Beard CIS220. Bubble Sort for Strings Double pass algorithm to sort a single dimensional array. Inner loop “bubbles” largest element.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
מחסנית ותור Stacks and Queues. מחסנית Stack מחסנית - Stack ADT סוג של מערך מוגבל מהיר מאוד ותופס מעט זיכרון שימוש ב LIFO – LIFO (Last In, First Out)
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
מבוא למדעי המחשב לתעשייה וניהול הרצאה 6. מפעל השעווה – לולאות  עד עכשיו  טיפלנו בייצור נרות מסוג אחד, במחיר אחיד  למדנו להתמודד עם טיפול במקרים שונים.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
1 מבוא למדעי המחשב הרצאה 5: פונקציות. 2 מבוא לפונקציות חלוקה של אלגוריתם לתת משימות: משימה - פונקציה: דוגמאות מציאת המקסימלי מבין שני איברים האינדקס של.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
1 Computer Programming Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
Subroutines and Functions Chapter 6. Introduction So far, all of the code you have written has been inside a single procedure. –Fine for small programs,
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
Lecture 7 Methods (functions and subroutines) Parameter Passing
Java String Methods - Codehs
COM148X1 Interactive Programming Lecture 4. Topics Today DateTime Functions Using Module Using Procedure Using Function Pass by Value and Pass by Reference.
מבוא למדעי המחשב לתעשייה וניהול
Objective 7.03 Apply Built-in Math Class Functions
Basics programming concepts-2
Algorithms and programming
Data Types, Arithmetic Operations
Functions and Procedures
Compiler Design First Lecture.
ניתוח מערכות מידע תכנות ב C#
מחסנית ותור Stacks and Queues.
Sub Procedures and Functions
VB.Net Programming Console Application
VB.Net Programming Console Application
Procedures: Functions and Subroutines
CSE Module 1 A Programming Primer
Chapter 8 - Functions and Functionality
Var Name =Console . ReadLine();
CS1S467 GUI Programming LECTURE 14 Methods (1 of 2)
Programming with Visual Basic .NET
Presentation transcript:

פונקציות

פונקציות מוכרות Imports System.Math Module Module1 Sub Main() Dim x As Decimal = Math.Abs(-10.4) Dim y As Decimal Console.WriteLine("I will find the square root of a number") y = Console.ReadLine() Console.WriteLine("The absolute value is " & x) Console.WriteLine("The value of PI is " & Math.PI) Console.WriteLine("The square root of " & y & " is " & Math.Sqrt(y)) Console.WriteLine("2 to the 4.5 power is " & Math.Pow(2, 4.5)) Console.ReadKey() End Sub End Module

פונקציות במחרוזות Module Module1 Sub Main() Dim word As String = "Hello world!" Dim find As String Console.WriteLine("The word is " & word) Console.WriteLine("The length is " & word.Length()) Console.WriteLine("Part of the word " & word.Substring(3, 5)) find = Console.ReadLine() Console.WriteLine("Was it there? " & word.Contains(find)) word = word.Insert(3, find) Console.WriteLine("The word is now " & word) Console.ReadKey() End Sub End Module

דוגמא של Subroutine Module Module1 Sub TestSub() Console.WriteLine("This is the function") Console.WriteLine("This is another line of text") End Sub Sub Main() Dim i As Integer For i = 1 To 10 TestSub() Next Console.ReadKey() End Sub End Module

עוד דוגמא Module Module1 Sub AddNumbers() Dim first As Integer Dim second As Integer Dim answer As Integer Console.WriteLine("Please type a number") first = Console.ReadLine() Console.WriteLine("Please type another number") second = Console.ReadLine() answer = first + second Console.WriteLine("The total is " & answer) End Sub Sub Main() AddNumbers() Console.ReadKey() End Sub End Module

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 5 למה זה חשוב מודולאריות פונקציות מודולאריות

עם פרמטרים Module Module1 Sub AddNumbers(ByVal first As Integer, ByVal second As Integer) Dim answer As Integer answer = first + second Console.WriteLine("The total is " & answer) End Sub Sub Main() AddNumbers(4, 5) Console.ReadKey() End Sub End Module

SWAP! Module Module1 Sub Swap(ByVal first As Integer, ByVal second As Integer) Dim temp As Integer temp = first first = second second = temp Console.WriteLine("The first variable is now " & first) Console.WriteLine("The second variable is now " & second) End Sub Sub Main() Dim x As Integer = 4 Dim y As Integer = 5 Swap(x, y) Console.WriteLine("X is now " & x) Console.WriteLine("y is now " & y) Console.ReadKey() End Sub End Module

SWAP! – The Fix (#1) Module Module1 Sub Swap(ByRef first As Integer, ByRef second As Integer) Dim temp As Integer temp = first first = second second = temp Console.WriteLine("The first variable is now " & first) Console.WriteLine("The second variable is now " & second) End Sub Sub Main() Dim x As Integer = 4 Dim y As Integer = 5 Swap(x, y) Console.WriteLine("X is now " & x) Console.WriteLine("y is now " & y) Console.ReadKey() End Sub End Module

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 5 תחום הקיום של משתנה - scope פונקציות משתנה מקומי Local variable משתנה גלובלי Global variable

SWAP! – The Fix (#2) Module Module1 Dim x As Integer = 4 Dim y As Integer = 5 Sub Swap() Dim temp As Integer temp = x x = y y = temp Console.WriteLine("The first variable is now " & x) Console.WriteLine("The second variable is now " & y) End Sub Sub Main() Swap() Console.WriteLine("X is now " & x) Console.WriteLine("y is now " & y) Console.ReadKey() End Sub End Module

Return Home! Module Module1 Function One() As Integer Dim x As Integer x = Console.ReadLine() Return x + 2 End Function Sub Main() Dim x As Integer x = One() Console.WriteLine("X is now " & x) Console.ReadKey() End Sub End Module

עם פרמטרים ! Module Module1 Function One(ByVal first As Integer) As Integer Return first + 2 End Function Sub Main() Dim x As Integer x = One(5) Console.WriteLine("X is now " & x) Console.ReadKey() End Sub End Module

איזה כף !!! Module Module1 Function One(ByVal first As Integer, ByVal second As Integer, ByVal third As Integer) As Integer Return first * second + third * first End Function Sub Main() Dim x, y, z As Integer z = 3 x = 4 y = 5 Console.WriteLine("What??? " & One(z, x, y)) Console.WriteLine("What??? " & One(x, y, z)) Console.ReadKey() End Sub End Module

בניית פונקציות Module Module1 Function Atzeret(ByVal first As Integer) As Integer Dim product As Integer = 1 Dim i As Integer For i = 2 To first product *= i Next Return product End Function Sub Main() Console.WriteLine("What??? " & Atzeret(6)) Console.ReadKey() End Sub End Module

עם שני פרמטרים Module Module1 Function Chezkat(ByVal first As Integer, ByVal second As Integer) As Integer Dim product As Integer = 1 Dim i As Integer For i = 1 To second product *= first Next Return product End Function Sub Main() Console.WriteLine("What??? " & Chezkat(2, 3)) Console.WriteLine("What??? " & Chezkat(4, 2)) Console.WriteLine("What??? " & Chezkat(10, 3)) Console.ReadKey() End Sub End Module

שימו לב לתיאום בין הפונקציה וה MAIN Module Module1 Function Grade(ByVal first As Decimal) As Char Dim answer As Char = "F" If (first 90) Then Return "A" End If If (first = 80) Then Return "B" End If Return answer End Function Sub Main() Dim x As Char x = Grade(5) Console.WriteLine("X is now " & x) Console.ReadKey() End Sub End Module

התחלה לתרגיל האחרון Module Module1 Sub Mishva() Console.WriteLine("Answer here!") End Sub Sub Main() Mishva() Console.ReadKey() End Sub End Module