Download presentation
Presentation is loading. Please wait.
1
תרגיל #3 פתרונות
2
חלק א ' ה STRUCT Structure COURSES Dim semkors, semmarza As String Dim kodkors, mispartalmidim, zionminimali As Integer End Structure
3
פתרון #1 Sub Main() Dim kors() As COURSES Dim endofdata As Boolean Dim ans As String Dim i As Decimal i = -1 Do Until endofdata i += 1 ReDim Preserve kors(i) Console.WriteLine("insert name courses") kors(i).semkors = Console.ReadLine() Console.WriteLine("insert marze name") kors(i).semmarza = Console.ReadLine() Console.WriteLine("insert courses kod") kors(i).kodkors = Console.ReadLine() Console.WriteLine("insert number of student") kors(i).mispartalmidim = Console.ReadLine() Console.WriteLine("insert zion minimali") kors(i).zionminimali = Console.ReadLine() Console.WriteLine("do yo finish? y/n ") ans = Console.ReadLine() If ans.ToUpper = "Y" Then endofdata = True End If Loop End Sub End Module
4
פתרון #2 Sub Main() Dim Course() As COURSES Dim TF As String = "" Dim I As Integer I = -1 Do While TF = "" I += 1 ReDim Preserve Course(I) Console.Write("Enter Course Name: ") Course(I).Name = Console.ReadLine() Console.Write("Enter Course Code: ") Course(I).Cod = Console.ReadLine() Console.Write("Lecturer Name: ") Course(I).Lecturer = Console.ReadLine() Console.Write("Number of students: ") Course(I).NumberOfStudents = Console.ReadLine() Console.Write("Passing grade: ") Course(I).MinGrade = Console.ReadLine() Console.WriteLine(vbTab) Console.Write("Continue - Press ENTER, End - Press ANY KEY : ") TF = Console.ReadLine() Loop Console.WriteLine("Number of courses: {0}", Size(Course)) Console.WriteLine("Course with most students: {0}", BiggestCourse(Course)) End Sub
5
ועכשיו הפונקציות : Function Size(ByVal x() As COURSES) As Integer Return x.Length() End Function Function BiggestCourse(ByVal x() As COURSES) As String Dim i As Integer Dim Max As Integer = x(0).NumberOfStudents Dim Pointer As Integer = 0 For i = 1 To x.Length - 1 If x(i).NumberOfStudents > Max Then Max = x(i).NumberOfStudents Pointer = i End If Next Return x(Pointer).Name End Function
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.