⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 algo rithm sdsa d adsa dsdsa dsad sad sadsdsad sadsa
💻 FRM
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   7665
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   11670
   LinkTopic       =   "Form1"
   ScaleHeight     =   7665
   ScaleWidth      =   11670
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "Computations:"
      Height          =   975
      Left            =   3960
      TabIndex        =   6
      Top             =   5160
      Width           =   7335
      Begin VB.TextBox Text3 
         Height          =   375
         Left            =   5520
         Locked          =   -1  'True
         TabIndex        =   13
         Top             =   360
         Width           =   735
      End
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   3120
         Locked          =   -1  'True
         TabIndex        =   12
         Top             =   360
         Width           =   735
      End
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   960
         Locked          =   -1  'True
         TabIndex        =   11
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "CPU utilization:"
         Height          =   375
         Left            =   4440
         TabIndex        =   10
         Top             =   480
         Width           =   1215
      End
      Begin VB.Label Label4 
         Caption         =   "AVE WT:"
         Height          =   255
         Left            =   2400
         TabIndex        =   9
         Top             =   480
         Width           =   855
      End
      Begin VB.Label Label1 
         Caption         =   "Ave TAT:"
         Height          =   255
         Left            =   240
         TabIndex        =   7
         Top             =   480
         Width           =   975
      End
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid3 
      Height          =   765
      Left            =   360
      TabIndex        =   5
      Top             =   6240
      Width           =   10995
      _ExtentX        =   19394
      _ExtentY        =   1349
      _Version        =   393216
      Cols            =   1
      FixedCols       =   0
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid2 
      Height          =   4515
      Left            =   4200
      TabIndex        =   4
      Top             =   480
      Width           =   7095
      _ExtentX        =   12515
      _ExtentY        =   7964
      _Version        =   393216
      Cols            =   5
      FixedCols       =   0
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   4515
      Left            =   360
      TabIndex        =   3
      Top             =   480
      Width           =   3495
      _ExtentX        =   6165
      _ExtentY        =   7964
      _Version        =   393216
      Cols            =   3
      FixedCols       =   0
   End
   Begin VB.CommandButton Simulate 
      Caption         =   "Simulate"
      Height          =   375
      Left            =   4560
      TabIndex        =   2
      Top             =   7080
      Width           =   1455
   End
   Begin VB.CommandButton AddProcess 
      Caption         =   "Add Process"
      Height          =   375
      Left            =   360
      TabIndex        =   1
      Top             =   5280
      Width           =   1455
   End
   Begin VB.CommandButton Reset 
      Caption         =   "Reset"
      Height          =   375
      Left            =   2160
      TabIndex        =   0
      Top             =   5280
      Width           =   1335
   End
   Begin VB.Label Label2 
      Caption         =   "Label1"
      Height          =   255
      Left            =   4800
      TabIndex        =   8
      Top             =   6600
      Width           =   615
   End
   Begin VB.Menu File 
      Caption         =   "&File"
      Begin VB.Menu Credit 
         Caption         =   "&Credit"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub initq()

For i = 0 To 50
queue(i) = -1
Next i

End Sub
Private Sub PrintM4()
Dim compute As Double
Dim sumtat As Double
Dim sumwt As Double
Dim sumbt As Double
For i = 0 To 50
If Proc(i).ProcessID <> "" Then

With MSFlexGrid2
    .Rows = i + 2
    .Row = i + 1
    .Col = 0
    .Text = Proc(i).ProcessID
    .Col = 1
    .Text = Proc(i).EndTime
    .Col = 2
    .Text = Proc(i).StartTime
    .Col = 3
    .Text = Proc(i).EndTime - Proc(i).ArrivalTime
     .Col = 4
    .Text = (Proc(i).EndTime - Proc(i).ArrivalTime) - Proc(i).BurstTime
    sumtat = sumtat + (Proc(i).EndTime - Proc(i).ArrivalTime)
    sumwt = sumwt + ((Proc(i).EndTime - Proc(i).ArrivalTime) - Proc(i).BurstTime)
   sumbt = Proc(i).BurstTime + sumbt
End With





End If

Next
compute = sumtat / TotalProcess
Text1.Text = compute ' Average Turnaround time
compute = sumwt / TotalProcess
Text2.Text = compute ' Average waiting time

compute = Round((sumbt / CurrentTime) * 100) ' CPU utilization
Text3.Text = compute & "%"

End Sub



Private Sub InitToZero()

For i = 0 To 50
Proc(i).ProcessID = ""
Proc(i).BurstTime = 0
Proc(i).StartTime = 0
Proc(i).RemainTime = 0
Proc(i).ArrivalTime = 0
Proc(i).EndTime = 0
Next


End Sub



Private Sub Initialize()

Call InitToZero
Call initq


With MSFlexGrid1
        .Rows = 1
        .Rows = 2
        .Col = 0
        .Row = 0
        .Text = "Process ID"
        .Col = 1
        .Row = 0
        .Text = "Burst Time"
        .Col = 2
        .Row = 0
        .Text = "Arrival Time"

       
    For i = 0 To 2
        .ColWidth(i) = 1132.5
   Next i
 

End With

With MSFlexGrid2
        .Rows = 1
        .Rows = 2
        .Col = 0
        .Row = 0
        .Text = "Process ID"
        .Col = 1
        .Row = 0
        .Text = "Time Completed"
        .Col = 2
        .Row = 0
        .Text = "Time Started"
        .Col = 3
        .Row = 0
      
        .Text = "Turn Around time"
        .Col = 4
        .Row = 0
        .Text = "Wait time"
        
    For i = 0 To 4
        .ColWidth(i) = 1400
   Next i

End With
 
With MSFlexGrid3
.Cols = 0
.Cols = 1

.ColWidth(0) = 500
        .Col = 0
        .Row = 0
        .Text = ""
        .Col = 0
        .Row = 1
        .Text = ""


End With
TotalProcess = 0
CurrentTime = 0


End Sub

Private Sub AddProcess_Click()
Dialog.Show 1

If Not TotalProcess = 0 Then
With MSFlexGrid1
    
        .Rows = TotalProcess + 1
        .Row = TotalProcess
        .Col = 0
        .Text = Proc(TotalProcess - 1).ProcessID
        .Col = 1
        .Text = Proc(TotalProcess - 1).BurstTime
        .Col = 2
        .Text = Proc(TotalProcess - 1).ArrivalTime
        
End With
End If



End Sub

Private Sub Credit_Click()
frmAbout.Show 1

End Sub

Private Sub Form_Load()


Call Initialize




End Sub

Private Sub Reset_Click()
Call Initialize
TotalProcess = 0

Simulate.Enabled = True
AddProcess.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""


End Sub
Private Sub smallestr()    ' Algorithm for choosing the
Dim smallest As Integer  ' process with smallest remaining time
smallest = -1

                                                 ' Note: if remaining time is equal
For i = 0 To 50                        ' it chooses smallest process ID
    For j = i To 50
        If queue(i) <> -1 And queue(j) <> -1 Then
                            
             If Proc(queue(i)).RemainTime <= Proc(queue(j)).RemainTime Then
                   If smallest <> -1 Then
                         If Proc(smallest).RemainTime > Proc(queue(i)).RemainTime Then
                         smallest = queue(i)
               
  
                        End If
                     Else
                  smallest = queue(i)
                  End If

                      
                  Else
                    If Proc(smallest).RemainTime > Proc(queue(j)).RemainTime Then
                             smallest = queue(j)
               
                    End If
            
             End If
         End If

    Next j
Next i

chosen = smallest

End Sub

Private Sub CheckFinish()

For i = 0 To 50
If Proc(i).RemainTime > 0 Then
finish = False
i = 50

End If
If Proc(i).RemainTime = 0 And Proc(i).ProcessID <> "" Then
finish = True

End If

Next i


End Sub


Private Sub Simulate_Click()
qcount = 0
chosen = -1
finish = False


Do While Not finish


For i = 0 To 50
If Proc(i).ArrivalTime <= CurrentTime And Proc(i).RemainTime <> 0 Then
queue(qcount) = i
qcount = qcount + 1
End If
Next i


Call smallestr 'process with smallest remaining time


If chosen <> -1 Then
If (Proc(chosen).BurstTime = Proc(chosen).RemainTime) Then
Proc(chosen).StartTime = CurrentTime
End If

Proc(chosen).RemainTime = Proc(chosen).RemainTime - 1

If (Proc(chosen).RemainTime = 0) Then
Proc(chosen).EndTime = CurrentTime + 1
End If

End If
With MSFlexGrid3

.Cols = CurrentTime + 1
.Col = CurrentTime
.ColWidth(CurrentTime) = 500
.Row = 0
If chosen <> -1 Then
.Text = Proc(chosen).ProcessID
Else
.Text = ""
End If
.Row = 1
.Text = CurrentTime & "-" & CurrentTime + 1


End With

CurrentTime = CurrentTime + 1


Call CheckFinish

Call initq
qcount = 0
chosen = -1
Loop




Call PrintM4
Simulate.Enabled = False
AddProcess.Enabled = False
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -