X
تبلیغات
گروه رایانه آموزش و پرورش ناحیه 1 قزوین - پاسخ تمرینهای فصل 12 کتاب مبانی علم رایانه

گروه رایانه آموزش و پرورش ناحیه 1 قزوین

اخبار و رویدادهای آموزشی کامپیوتر

پاسخ تمرینهای فصل 12 کتاب مبانی علم رایانه

پاسخ سوالات فصل 12

 

 

سوال3 ص 135:

الف:

Private Sub cmdrun_Click()
Rem part12-Exercise1
If Val(txtsecond) <> 0 Then
txtresult = Val(txtfirst) / Val(txtsecond)
Else
txtresult = "Not Defined"
End If
End Sub
Private Sub Form_Load()
cmdrun.Caption = "Run"
lblA.Caption = "First Num"
LblB.Caption = "Second Num"
lblc.Caption = "Result"
txtfirst = ""
txtsecond = ""
txtresult = ""
End Sub

ب)

Private Sub Cmdrun_Click()
Rem part12-Exercise8
Dim intr, intn As Integer
intn = Val(Txtnum)
While Val(Txtnum) <> 0
intr = Val(Txtnum) Mod 10
txtreverse = txtreverse & Str(intr)
Txtnum = Val(Txtnum) \ 10
Wend
Txtnum = intn
End Sub

Private Sub Form_Load()
Label1.Caption = "Number"
Label2.Caption = "Reverse"
Txtnum = ""
txtreverse = ""
End Sub

ج)

 

Private Sub Cmdrun_Click()
Rem part12-Exercise8
Dim intnum, intr As Integer
intnum = InputBox("Please enter a Integer Number with 4 digits", "Get Number")
While intnum <> 0
intr = intnum Mod 10
Print intr;
intnum = intnum \ 10
Wend
End Sub

د)

Private Sub Cmdrun_Click()
Rem part12-Exercise8
Dim n, n1, n2, n3, n4, r1, r2 As Integer
n = InputBox("Plz a number")
r1 = n Mod 10
n1 = n \ 10
r2 = n1 Mod 10
n2 = n1 \ 10
r3 = n2 Mod 10
n3 = n2 \ 10
Print r1; r2; r3; n3
End Sub

 

 

سوال 3 ص 135:

Private Sub Command1_Click()
   Dim a As Integer, b As Integer
   a = Val(InputBox("Enter number a :"))
   b = Val(InputBox("Enter number b :"))
   If b <> 0 Then Form1.Print a \ b Else Form1.Print "not defined"
End Sub

 

 

سوال 4 ص 135:

Dim yy0 As Integer, mm0 As Integer, dd0 As Integer
Dim yy As Integer, mm As Integer, dd As Integer
Dim y As Integer, m As Integer, d As Integer
Private Sub Command1_Click()
   yy0 = Val(Text1.Text)
   mm0 = Val(Text2.Text)
   dd0 = Val(Text3.Text)
   dd = Day(Date)
   mm = Month(Date)
   yy = Year(Date)
   Print yy, mm, dd
   If dd < dd0 Then
      mm = mm - 1
      dd = dd + 30
   End If
   d = dd - dd0
   If mm < mm0 Then
      yy = yy - 1
      mm = mm + 12
   End If
m = mm - mm0
   If yy >= yy0 Then
      y = yy - yy0
   Else
      MsgBox "not valid"
      Exit Sub
   End If
   Print yy0, mm0, dd0
   Print "sal="; y, "mah="; m, "rooz"; d
End Sub

 

يا

 

Private Sub Command1_Click()
Dim day, month, year, nday, nmonth, nyear As Integer
nday = Val(txtnday)
nmonth = Val(txtnmonth)
nyear = Val(txtnyear)
day = Val(txtday)
month = Val(txtmonth)
year = Val(txtyear)
If nday < day Then
nmonth = nmonth - 1
If nmonth < 6 Then
nday = nday + 31
Else
nday = nday + 30
End If

End If
d = nday - day
If nmonth < month Then
nyear = nyear - 1
nmonth = nmonth + 12

End If
m = nmonth - month
y = nyear - year
Print y; " years", m; " months", d; " days past from your birth date"
End Sub

Private Sub Form_Load()
Label1.Caption = "birth_day"
Label2.Caption = "birth_month"
Label3.Caption = "birth_year"
txtday = ""
txtmonth = ""
txtyear = ""
Label4.Caption = "now day"
Label5.Caption = "nowmonth"
Label6.Caption = "now year"
txtnday = ""
txtnmonth = ""
txtnyear = ""
End Sub

 

سوال 5 ص 135:

Dim a As Integer, b As Integer, c As Integer, delta As Integer
Dim x1 As Single, x2 As Single
Private Sub Command1_Click()
   a = Val(Text1.Text)
   b = Val(Text2.Text)
   c = Val(Text3.Text)
   delta = b ^ 2 - 4 * a * c
   If delta >= 0 Then
      x1 = (-b + Sqr(delta)) / (2 * a)
      x2 = (-b - Sqr(delta)) / (2 * a)
      MsgBox "x1=" + Str(x1) + "   " + "x2=" + Str(x2)
    Else
       MsgBox "Not Root"
    End If
End Sub

 

 

سوال 6 ص 135

Dim citynam As String, cnam1 As String, cnam2 As String
Dim max As Integer, min As Integer, dama As Integer
Private Sub Command1_Click()
   citynam = InputBox("Enter a city name : ")
   dama = Val(InputBox("enter dama : "))
   cnam1 = citynam
   cnam2 = citynam
   max = dama
   min = dama
   For i = 2 To 10
      citynam = InputBox("Enter a city name : ")
      dama = Val(InputBox("enter dama : "))
      If min > dama Then
         cnam1 = citynam
         min = dama
      End If
      If max < dama Then
           cnam2 = citynam
           max = dama
      End If
    Next
    Form1.Print "shahr="; cnam1, "minimum dama="; min
    Form1.Print "shahr="; cnam2, "maximum dama="; max
End Sub

يا

Private Sub cmdrun_Click()
'exercise 6-part12
Dim max, min, temp, count As Integer
Dim nam, nmax, nmin, ntemp As String * 15
count = 1
temp = InputBox("Plz enter temp of city")
nam = InputBox("plz name of city")
max = temp: nmax = nam
min = temp: nmin = temp
For count = 2 To 10
temp = InputBox("Plz enter temp of city")
nam = InputBox("plz name of city")
If temp > max Then
max = temp
nmax = nam
End If
If temp < min Then
min = temp
nmin = nam
End If
Next count
Print "the coldest city is "; nmin; " with "; min; " C degree"
Print
Print "the warmest city is "; nmax; " with "; max; " C degree"
End Sub

Private Sub Form_Load()
cmdrun.Caption = "Run"
End Sub

 

سوال 7 ص 135:

Dim salary As Long
Private Sub Command1_Click()
   salary = Val(InputBox("Enter hoghogh : "))
   If salary <= 200000 Then
      MsgBox salary
      Exit Sub
   End If
   If salary <= 800000 Then
      MsgBox salary - (salary - 200000) * 0.1
      Exit Sub
   Else
      MsgBox salary - (salary - 800000) * 0.12
      Exit Sub
   End If
End Sub

 

 

سوال 8 ص 135

Dim n As Integer
Private Sub Command1_Click()
   n = Val(InputBox("Enter number n : "))
   Y1 = n Mod 10
   n = n \ 10
   Y2 = n Mod 10
   n = n \ 10
   y3 = n Mod 10
   y4 = n \ 10
   Form1.Print Y1 * 1000 + Y2 * 100 + y3 * 10 + y4
End Sub

 

يا

Private Sub Comdrun_Click()
Dim intr, intn As Integer
intn = Val(txtnum)
While Val(txtnum) <> 0
intr = Val(txtnum) Mod 10
TxtReverse = TxtReverse + Str(intr)
txtnum = Val(txtnum) \ 10
Wend
txtnum = intn
End Sub

Private Sub Form_Load()
lbl1.Caption = "Number"
lbl2.Caption = "Display"
txtnum = ""
TxtReverse = ""
End Sub

 

سوال 9 ص 135

 

Dim k As Integer, c As Integer
Private Sub Command1_Click()
   k = 12
   c = 0
   Do While k < 100
      c = c + 1
      Form1.Print k
      k = k + 3
    Loop
    Print "tedad="; c
End Sub

 

يا

Private Sub cmdmazrab_Click()
    Dim inti As Integer
    For inti = 102 To 999 Step 3
        txta.Text = txta.Text + Str(inti) & MultiLine
Next inti
End Sub

 

 

 

سوال 10 ص 135

Dim no As Byte
Private Sub Command1_Click()
   no = Val(InputBox("Enter a day of week : "))
   Select Case no
      Case 1
         MsgBox "Shanba"
      Case 2
         MsgBox "yek Shanba"
      Case 3
         MsgBox "dow Shanba"
      Case 4
         MsgBox "seh Shanba"
      Case 5
         MsgBox "chohar Shanba"
      Case 6
         MsgBox "panj Shanba"
      Case 7
         MsgBox "jomah"
      Case Else
         MsgBox "not valid"
   End Select
End Sub

يا

Private Sub CmdRun_Click()
'exercise 10part12
Dim n As Integer
n = Val(txtdata)
Select Case n
Case 1:
Print "saturday"
Case 2:
Print "sunday"
Case 3:
Print "monday"
Case 4:
Print "tuesday"
Case 5:
Print "wednesday"
Case 6:
Print "thursday"
Case 7:
Print "friday"
Case Else
Print "not Defined"
End Select

End Sub

Private Sub Form_Load()
CmdRun.Caption = "Recognize"
txtdata = ""
End Sub

+ نوشته شده در  88/02/27ساعت 1:2  توسط عطاران  |