Смекни!
smekni.com

Использование языка программирования Visual Basic для решения математических задач (стр. 3 из 3)

LOCATE 6, 4: PRINT “1000”

LINE (48, 245)-(52, 245), 11

LINE (48, 190)-(52, 190), 11

LINE (48, 135)-(52, 135), 11

LINE (48, 80)-(52, 80), 11

REM координата X

LINE (x0, y0)-(x1, y0), 12

LOCATE 23, 19: PRINT “1000”

LOCATE 23, 31: PRINT “2000”

LOCATE 23, 44: PRINT “3000”

LOCATE 23, 56: PRINT “4000”

LOCATE 23, 69: PRINT “5000”

LINE (150, 302)-(150, 298), 11

LINE (250, 302)-(250, 298), 11

LINE (350, 302)-(350, 298), 11

LINE (450, 302)-(450, 298), 11

LINE (550, 302)-(550, 298), 11

REM ЦЕЛЬ

LINE (x0 + l / 10, 299)-(x0 + l / 10 + 5, 299), 10

LINE (x0 + l / 10, 298)-(x0 + l / 10 + 5, 298), 10

REM показания

LOCATE 1, 6: PRINT “V m/s”

LOCATE 2, 6: PRINT “H m”

LOCATE 2, 24: PRINT “S m”

LOCATE 1, 24: PRINT “T s”

80 KEY(1) ON

ON KEY(1) GOSUB 90

GOTO 80

REM полет

90 v = 200

g = 9.8

f = a * 3.14 / 180

100 q = .01

t = t + q

REM k коэффициент сопротивления воздуха

k = .016

vs = v * COS(f) – (k – k / (k + v * COS(f)))

vh = v * SIN(f) – (k – k / (k + v * SIN(f)))

s = vs * t * 2

h = (vh * t – (g * t ^ 2) / 2) * 5.5

v = SQR(vs ^ 2 + vh ^ 2)

LINE (x2, y2)-(x0 + s / 20, y0 – h / 25), 14

x2 = x0 + s / 20

y2 = y0 – h / 25

LOCATE 1, 12: PRINT v

LOCATE 2, 12: PRINT h / 5.5

LOCATE 2, 28: PRINT s / 2

LOCATE 1, 28: PRINT t

IF h < 0 THEN 200

GOTO 100

200 REM взрыв

r = 30

n = 500

REM: a угол разлета

REM: r радиус разлета, n количество осколков

REM: коэффициенты 0.5 и 1 определяют ширину и высоту разлета

DIM x(n), y(n)

RANDOMIZE (TIMER)

FOR I = 1 TO n

a = -6.28 * RND / 2

rn = r * RND

xc = x2 + rn * .5 * COS(a)

yc = y2 + rn * 1 * SIN(a)

PSET (xc, yc), 9 + 9 * RND

PRESET (x(i), y(i))

NEXT

END

Приложение 2

VERSION 5.00

Begin VB.Form Form1

BackColor = &H8000000D&

BorderStyle = 1 ‘Fixed Single

Caption = “Form1”

ClientHeight = 7770

ClientLeft = 45

ClientTop = 435

ClientWidth = 8670

FillColor = &H00C0FFFF&

LinkTopic = “Form1”

MaxButton = 0 ‘False

MinButton = 0 ‘False

ScaleHeight = 7770

ScaleWidth = 8670

StartUpPosition = 3 ‘Windows Default

Begin VB.CommandButton Command1

Caption = “Пуск”

Height = 495

Left = 720

TabIndex = 2

Top = 5280

Width = 1215

End

Begin VB.VscrollBar Vscroll1

Height = 1935

Left = 240

Max = 80

MousePointer = 9 ‘Size W E

TabIndex = 1

TabStop = 0 ‘False

Top = 2400

Value = 80

Width = 255

End

Begin VB.HscrollBar Hscroll1

Height = 255

Left = 240

Max = 15000

Min = 10

MousePointer = 7 ‘Size N S

TabIndex = 0

Top = 4800

Value = 100

Width = 8295

End

Begin VB.Label Label9

Caption = “Ошибка”

Height = 375

Left = 2160

TabIndex = 11

Top = 5400

Width = 975

End

Begin VB.Line Line1

X1 = 600

X2 = 600

Y1 = 4680

Y2 = 480

End

Begin VB.Label Label8

Caption = “0”

Height = 375

Left = 3120

TabIndex = 10

Top = 5400

Width = 1095

End

Begin VB.Label Label7

Caption = “Дальность”

Height = 375

Left = 2160

TabIndex = 9

Top = 5880

Width = 975

End

Begin VB.Label Label6

Caption = “угол(градус)”

Height = 375

Left = 4800

TabIndex = 8

Top = 5880

Width = 975

End

Begin VB.Label Label5

Caption = “дист(м)”

Height = 375

Left = 4800

TabIndex = 7

Top = 5400

Width = 975

End

Begin VB.Label Label4

Caption = “Label4”

Height = 15

Left = 5040

TabIndex = 6

Top = 6000

Width = 135

End

Begin VB.Label Label3

BackColor = &H80000018&

Caption = «0»

Height = 375

Left = 3120

TabIndex = 5

Top = 5880

Width = 1095

End

Begin VB.Label Label2

BackColor = &H80000018&

Caption = «0»

Height = 375

Left = 5760

TabIndex = 4

Top = 5880

Width = 1095

End

Begin VB.Label Label1

BackColor = &H80000018&

Caption = «0»

Height = 375

Left = 5760

TabIndex = 3

Top = 5400

Width = 1095

End

Begin VB.Line Line2

X1 = 600

X2 = 8400

Y1 = 4680

Y2 = 4680

End

End

Attribute VB_Name = “Form1”

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Private Sub Hscroll1_Change()

Cls

Label1 = Hscroll1

X1 = Hscroll1 * 0.507

Line (X1 + 550, 4500)-(X1 + 600, 4650), &HC0FFFF, BF

End Sub

Private Sub Vscroll1_Change()

Label2 =80 – Vscroll1

End Sub

Private Sub Command1_Click()

X0 = 600

Y0 = 4680

X2 = X0

Y2 = Y0

v = 300

g = 9.8

a = Label2

f = a * 3.14 / 180

100 q = 0.00005

t = t + q

Rem k – коэффициент сопротивления воздуха

k = 0.0001

vs = v * Cos(f) – (k – k / (k + v * Cos(f)))

vh = v * Sin(f) – (k – k / (k + v * Sin(f)))

s = vs * t

h = (vh * t – (g * t ^ 2) / 2)

s = v * t * Cos(f)

h = v * t * Sin(f) – (g * t ^ 2) / 2

v = Sqr(vs ^ 2 + vh ^ 2)

Line (X2, Y2)-(X0 + s, Y0 – h), &HFF&

X2 = X0 + s

Y2 = Y0 – h

If h < 0 Then GoTo 200

GoTo 100

200 Label3 = s * 4.32 &bsol; 1

v = X1 &bsol; 2 * 2

Label8 = Hscroll1 – s * 4.32 &bsol; 1

End Sub

Приложение 3

Private Sub Form_Load()

Label1.Caption = 0

Label2.Caption = 0

Label3.Caption = 0

Label4.Caption = 0

Label5.Caption = 0

Label6.Caption = 0

Label13.Caption = 0

Label15.Caption = 0

Label17.Caption = 0

End Sub

Private Sub Timer1_Timer()

Label1.Caption = Label1.Caption + Timer1.Interval

Label2.Caption = Label2.Caption + Timer2.Interval

Label13.Caption = Label13.Caption + Timer3.Interval

Label15.Caption = Label15.Caption + Timer4.Interval

Label17.Caption = Label17.Caption + Timer5.Interval

a = Label1.Caption

T = Timer3.Interval

k = 1.2

V = 30

Label3.Caption = (250 - VScroll1) &bsol; 10

q = Label3.Caption

f = q * 3.14 / 180

Rem Поверхность

Line (14850, 5640)-(350, 5820), &H80000002, BF

Rem Танк

Line (12000 - a * k, 5620)-(12850 - a * k, 5520), &HFFFF&, BF

Line (11920 - a * k, 5540)-(12000 - a * k, 5530), &HFFFF&, BF

Line (11900 - a * k, 5550)-(12000 - a * k, 5540), &HFFFF&, BF

Line (11920 - a * k, 5560)-(12000 - a * k, 5550), &HFFFF&, BF

Line (11940 - a * k, 5570)-(12000 - a * k, 5560), &HFFFF&, BF

Line (11950 - a * k, 5590)-(12000 - a * k, 5570), &HFFFF&, BF

Line (11970 - a * k, 5600)-(12000 - a * k, 5590), &HFFFF&, BF

Line (12825 - a * k, 5600)-(12900 - a * k, 5580), &H8000000F, BF

Line (12800 - a * k, 5620)-(12900 - a * k, 5600), &H8000000F, BF

Line (12850 - a * k, 5620)-(13950 - a * k, 5520), &H8000000F, BF

Rem башня танка

Line (12200 - a * k, 5440)-(12650 - a * k, 5500), &HFFFF&, BF

Line (11900 - a * k, 5460)-(12200 - a * k, 5460), &HFFFF&

Line (12650 - a * k, 5440)-(12750 - a * k, 5500), &H8000000F, BF

Rem Полет ПТУРС

X1 = V * T * Cos(f - Rnd * 0.1)

Y1 = V * T * Sin(f + Rnd * 0.1)

Label5.Caption = (Label5.Caption + X1)

Label4.Caption = (Label4.Caption + Y1)

Label6.Caption = 12000 - a * k

X0 = Label5.Caption

Y0 = -Label4.Caption

Rem ПТУРС

Line (X0 + 300, 5550 + Y0)-(X0 + 400, 5500 + Y0), &H8000000F, BF

Line (X0 + 300, 5550 + Y0)-(X0 + 500, 5600 + Y0), &H8000000F, BF

Line (X0 + 300, 5450 + Y0)-(X0 + 550, 5500 + Y0), &H8000000F, BF

Line (400 + X0, 5500 + Y0)-(420 + X0, 5550 + Y0), &HFF&, BF

Line (400 + X0, 5525 + Y0)-(550 + X0, 5525 + Y0), &HFF&

Rem дым

X2 = 12820 - a * k

Y2 = 5620

r = 30

n = 1

Dim x(10), y(10)

Randomize (Label1.Caption)

For i = 1 To 50

a = -6.28 * Rnd / 6

rn = r * Rnd

xc = X2 + rn * 9 * Cos(a)

yc = Y2 + rn * 3 * Sin(a)

PSet (xc, yc), &HFFFF80 * Rnd + &HC0C0FF * Rnd

Next

If X0 > 13000 Then Timer1.Interval = 0

If Y0 > 50 Then Timer2.Interval = 1

If Y0 > 100 Then Timer3.Interval = 0

If Label5.Caption > 11500 - (Label1.Caption) Then Timer4.Interval = 1

End Sub

Private Sub Command1_Click()

Rem старт ПТУРС

Timer3.Interval = 1

End Sub

Private Sub Timer2_Timer()

Rem: фейерверк

Rem: a угол разлета

Rem: r радиус разлета, n количество осколков

Rem: коэффициенты 1 и 4 определяют ширину и высоту разлета

X1 = Label5.Caption

Y1 = -Label4.Caption

r = 200

n = 500

Dim x(10), y(10)

Randomize (Label2.Caption)

For i = 1 To 2

a = -6.28 * Rnd / 2

rn = r * Rnd

xc = X1 + 400 + rn * 1.5 * Cos(a)

yc = Y1 + 5600 + rn * 5 * Sin(a)

PSet (xc, yc), &HFFFF80 * Rnd + &HC0C0FF * Rnd

Next

If Label1.Caption > 200 Then Timer2.Interval = 0

End Sub

Private Sub Timer4_Timer()

If Label4.Caption < 200 Then Timer5.Interval = 1

End Sub

Private Sub Timer5_Timer()

X0 = Label5.Caption

Y0 = -Label4.Caption

r = 100

n = 100

Dim x(100), y(100)

Randomize (Label2.Caption)

For i = 1 To 5

a = -6.28 * Rnd / 2

rn = r * Rnd

xc = X0 + 400 + rn * 3 * Cos(a)

yc = Y0 + 5600 + rn * 5 * Sin(a)

PSet (xc, yc), &HFFFF80 * Rnd + &HC0C0FF * Rnd

If Label17.Caption < 150 Then Timer1.Interval = 0

Next

End Sub