תרגילים. גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader.

Slides:



Advertisements
Similar presentations
Standard Algorithms Find the highest number. ! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer.
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
מחרוזות של תווים. מבוא לתכנות למנע"ס - שבוע מספר 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.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4: Control Structures: Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
מבני בקרה מבוא לתכנות למנע " ס - שבוע מספר 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("
מערכים מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע.
מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.
Chapter seven review. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For.
תרגיל #3 פתרונות. חלק א ' ה STRUCT Structure COURSES Dim semkors, semmarza As String Dim kodkors, mispartalmidim, zionminimali As Integer End Structure.
פתרון תרגילים #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))
Chapter 7 & 8- Arrays and Strings
מערכים דו ממדי ו STRUCTS פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length()
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
פונקציות. פונקציות מוכרות Imports System.Math Module Module1 Sub Main() Dim x As Decimal = Math.Abs(-10.4) Dim y As Decimal Console.WriteLine("I will.
الحلقات for For i =1 To x step -2 …………. Next DO while (شرط) …………. Loop DO …………. Loop while (شرط) الحلقة Do while.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
1. 2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Decisions { class.
File Handling. Data Files Programs that can only get data from the user interface are limited. –data must be entered each time. –only small amounts of.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4: Control Structures: Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
26/10/ Selection Nested If structures & Complex Multiple Conditions.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
4.1 Introduction Structured programming –Control structures Helpful in building and manipulating objects BZUPAGES.COM.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
1 Chapter 10 Additional Control Structures and Exceptions.
Count and add list of numbers From user input and from file.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 7. סברוטינות subroutines.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
הרצאה 3 מבוא למדעי המחשב לתעשייה וניהול הודעות : הודעות : או דרך moodle – ושם לפנות ל : אתר מכון טל החומר.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
مسألة أكتب برنامجاً يقوم بقراءة عددين و إظهار رسالة تفيد بأن أحد العددين هو المضاعف النوني للعدد الآخر و في حال عدم كون أي من العددين مضاعفاً للآخر يظهر.
VB6.0 دىن VB.NET گىچە دەسلەپكى ئۈگەنگۈچىلەر ئۈچۈن ئاپتورى:چاشق ان رەتلىگۈچى:چا شقان لايىھەلىگۈچى: چاشقان.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
05/02/ Records. 205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Introduction to VB programming Dr. John P. Abraham UTPA Chapters 2 & 3.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
情報基礎 A Lecture 12 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Visual BASIC Programming For CCS 301 course Dr. Ahmad ABDELHAY.
מבוא למדעי המחשב לתעשייה וניהול
Objective 7.03 Apply Built-in Math Class Functions
VB.Net Programming Console Application
Method.
Compiler Design First Lecture.
Files and Streams.
للمزيد زورونا على موقعنا الإلكتروني:
Variables, Loops, Decision Statements, etc
ניתוח מערכות מידע תכנות ב C#
VB.Net Programming Console Application
VB.Net Programming Console Application
Procedures: Functions and Subroutines
Methods and Data Passing
BO65: PROGRAMMING WRITING TO TEXT FILES.
Reading from File & Picture Boxes
Files and Streams.
Functions Divide and Conquer
Name of Pupil: Your Name Here
Repetition - Counting and Accumulating
Presentation transcript:

תרגילים

גדול, קטן, וממוצע מקובץ Imports System.IO Module Module1 Sub Main() Dim readnum As StreamReader readnum = _ My.Computer.FileSystem.OpenTextFileReader _ (“z:\numbers.txt") Dim input As String Dim t, i, big, num, small, avrage As Decimal i = 0 big = small = Do input = readnum.ReadLine() num = input If num > big Then big = num End If If num Nothing Then small = num End If If num <> 0 Then i += 1 t = t + num End If Loop Until input Is Nothing Dim writenum As StreamWriter = New StreamWriter _ (“z:\answersb.txt") avrage = t / (i) writenum.WriteLine("the largest number is " & big & "the smallest number is " & small & "the avrage of the numbers is " & avrage) writenum.Close() End Sub End Module

גדול, קטן, וממוצע מקובץ יותר טוב Imports System.IO Module Module1 Sub Main() Dim fileReader As StreamReader fileReader = File.OpenText("z:\numbers.txt") Dim Input As String = "" Dim x, sum, big, small, c As Decimal Dim temp As Integer x = fileReader.ReadLine() sum = x big = x small = x c = 1 Do Until Input Is Nothing Input = fileReader.ReadLine() x = Input temp = Input sum += x If (x > big) Then big = x ElseIf ((x 0)) Then small = x End If c += 1 Loop Dim writer As StreamWriter = _ New StreamWriter("z:\answer.txt") writer.WriteLine("The small number is " & small & ".") writer.WriteLine("The big number is " & big & ".") writer.WriteLine("The average is " & sum / (c - 1) & ".") writer.Close() Console.ReadKey() End Sub End Module

עצרת Module Module1 Sub Main() Dim i, x, mona As Integer Console.WriteLine("enter number") x = Console.ReadLine If x < 0 Then Console.WriteLine("en azeret lemispar shlili") Else mona = 1 For i = 1 To x mona *= i Next End If Console.WriteLine("the azeret is: " & mona) Console.ReadKey() End Sub End Module

עצרת אחרת Module Module1 Sub Main() Dim x, input, atzeret As Decimal Console.WriteLine("please enter a number") input = Console.ReadLine() atzeret = 1 For x = 1 To input atzeret = atzeret * x Next Console.WriteLine("the atzeret is " & atzeret) Console.ReadKey() End Sub End Module

עצרת שקשה לי להבין Module Module1 Sub Main() Dim x, i As Integer x = Console.ReadLine For i = 1 To x - 1 x = x * i Next Console.WriteLine(i & " aseret = " & x) Console.ReadKey() End Sub End Module

Function Max Module Module1 Function Max(ByVal first As Integer, ByVal second As Integer, ByVal third As Integer) As Integer If first > second And first > third Then Return first ElseIf second > first And second > third Then Return second ElseIf third > first And third > second Then Return third End If End Function Sub Main() Dim x, y, z As Integer Console.WriteLine("please enter 3 numberes") x = Console.ReadLine y = Console.ReadLine z = Console.ReadLine Console.WriteLine("the max num is " & Max(x, y, z)) Console.ReadKey() End Sub End Module

Function Max Module Module1 Function Max(ByVal first As Integer, ByVal second As Integer, ByVal third As Integer) As Integer Dim a, b As Integer a = (first + second) b = (third + second) If first > third Then If first > second Then Return first Else Return second End If Else If second > third Then Return second Else Return third End If End Function Sub Main() Dim x As Integer x = Max(6, 9, 1) Console.WriteLine(" the big number is: " & x) Console.ReadKey() End Sub End Module

Function Max Module Module1 Function Max(ByVal first As Integer, ByVal second As Integer, ByVal third As Integer) As Integer Dim temp As Integer = first If second >= temp Then temp = second End If If third >= temp Then temp = third End If Return temp End Function Sub Main() Dim x, y, z As Integer Console.WriteLine("Please enter 3 numbers ") x = Console.ReadLine y = Console.ReadLine z = Console.ReadLine Console.WriteLine("Max:" & Max(x, y, z)) Console.ReadKey() End Sub End Module

ציונים Module Module1 Function Grade(ByVal first As Decimal) As Char If first >= 90 Then Return “A" ElseIf first >= 80 Then Return “B" ElseIf first >= 70 Then Return “C" ElseIf first >= 60 Then Return “D" Else Return “F" End If End Function Sub Main() Dim x As Decimal Console.WriteLine("na lirsom ziyon") x = Console.ReadLine Console.WriteLine("aziyon beotiyot: " & Grade(x)) Console.ReadKey() End Sub End Module

למה ה MAIN פה בסדר ? Module Module1 Function Grade(ByVal first As Decimal) As Char Dim ot As Char If (first >= 60) And (first <= 69) Then ot = “D" ElseIf (first >= 90) And (first <= 100) Then ot = “A" ElseIf (first >= 80) And (first <= 89) Then ot = “B" ElseIf (first >= 70) And (first <= 79) Then ot = “C" ElseIf (first >= 0) And (first <= 59) Then ot = “F" End If Return ot End Function Sub Main() Console.WriteLine("the grade is :" & Grade(69)) Console.ReadKey() End Sub End Module

משוואה הריבועית Module Module1 Sub Mishva() Dim a, b, c As Integer Console.WriteLine("na lirsom 3 misparim") a = Console.ReadLine b = Console.ReadLine c = Console.ReadLine If ((b * b) - (4 * (a * c))) > 0 Then Console.WriteLine("tsuba 1: " & (-b + ((b * b) - (4 * (a * c)))) / (2 * a)) Console.WriteLine("tsuba 2: " & (-b - ((b * b) - (4 * (a * c)))) / (2 * a)) Else Console.WriteLine("lo mugdar") End If End Sub Sub Main() Mishva() Console.ReadKey() End Sub End Module

משוואה הריבועית - פתרון יותר טוב Imports System.Math Module Module1 Sub Mishva() Dim a, b, c As Decimal Dim y, x1, x2 As Single Console.WriteLine("enter 3 number:") a = Console.ReadLine() b = Console.ReadLine() c = Console.ReadLine() y = ((b * b) - 4 * a * c) If (y >= 0) Then x1 = ((-b + Math.Sqrt(y)) / (2 * a)) x2 = ((-b - Math.Sqrt(y)) / (2 * a)) If (a <> 0) Then Console.WriteLine("the answer of x1 is: " & x1) Console.WriteLine("the answer of x2 is: " & x2) Else Console.WriteLine("eror") End If Else Console.WriteLine("eror") End If End Sub Sub Main() Mishva() Console.ReadKey() End Sub End Module