Смекни!
smekni.com

Билеты по информатике 10 класс: Visual Basic

Билет№2

1

DoWhile L } S выполняется

S }если L-истина

Loop }


Do }S выполняется

S }пока L-истина

LoopWhile L }


Do }Sвыполняется

S }вечно, покане

[exitdo] } будет перехода

Loop } к exit do


WhileL }тоже, что и

S }Do while...Loop

Wend }


DoUntil L }S выполняется

S }если L-ложь

Loop }


Do }Sвыполняется

S }пока L-ложь

LoopUntil L}


fori=i0to iкstep h}S выполняется

S }пока i0не дос-

[Exitfor] }тигнетзначения

Nexti }ik.Шаг– h

2

SubЗнаки()

DimS As String, En As String

DimnEn As Integer, i As Long

S= InputBox("Введитетекст")

En= "abcdefghijklmnopqrstuvwxyz"

nEn= 0

Fori = 1 To Len(S)

If(InStr(En, Mid(S, i, 1), 1)) > 0 Then

nEn= nEn + 1

EndIf

Nexti

MsgBox("Кол-во =" + Str(nEn))

EndSub

3

SubSwap(S As String, i As Long, j As Long)

Dimc As String

c= Mid(S, i, 1)

Mid(S,i, 1) = Mid(S, j, 1)

Mid(S,j, 1) = c

EndSub

Subшифр()

DimS As String, Sogl As String

DimS1 As String, c As String

DimGl As String, K As Long

Dimi As Long

Sogl= "аеиоуыэюяё"

S= InputBox("Ввод строки")

Gl= "бвгджзклмнпрстфхцчшщъь"

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

IfInStr(Gl, c) > 0 Then


K= K + 1

IfK > Len(Sogl) Then K = 1

S1= S1 + Mid(Sogl, K, 1)

EndIf

Nexti

Fori = 1 To Len(S1) - 5 Step 6

CallSwap(S1, i, i + 5)

CallSwap(S1, i + 2, i + 3)

CallSwap(S1, i + 1, i + 4)

Nexti

S= S1

MsgBox(S)

EndSub

4

SubРаскодировщик()

DimS As String, i As Long

DimS1 As String, c As String

DimGl As String, K As Long

S= InputBox("Ввод шифра")

Gl= "бвгджзклмнпрстфхцчшщъь"

Fori = 1 To Len(S) - 5 Step 6

CallSwap(S, i, i + 5)

CallSwap(S, i + 2, i + 3)

CallSwap(S, i + 1, i + 4)

Nexti

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

IfInStr(Gl, c) > 0 Then i = i + 1

Nexti

MsgBox(S1)

EndSub

5

SubЗамена()

DimS As String, S1 As String

Dimn As Long, C As String

DimName As String

S= InputBox("Ввод строки")

Name= InputBox("Ввод Имени")

n= 0

Fori = 1 To Len(S)

C= Mid(S, i, 1)

IfMid(S, i, 3) = "Имя" Then

S1= S1 + Name

n= n + 1

i= i + 2

ElseIfMid(S, i, 7) = "Фамилия"Then

S1= S1 + Name

i= i + 6

n= n + 1

Else

S1= S1 + C

EndIf

Nexti

MsgBox(S1)

MsgBox(n)

EndSub



Билет№3

1

IfL then }S выполняется

S }еслиL-истина

EndIf }


IfL1then }S1 выполняется

S1 }еслиL1–истина.

ElseifL2then }если нет, топро-

S2 }веряетсяL2 и.т.д

-- - - - - - - }если Ln-неистина

ElseifLnthen }то выполняется

Sn }Sn+1

Else }

Sn+1 }

Endif }

2

SubЗнаки( )

DimS As String, Rus As String

DimnRus As Integer, i As Long

S= InputBox("Введитетекст")

Rus= "абвгдежзиклмнопрстуфхцчшщъыьэюяё"

nRus= 0

Fori = 1 To Len(S)

If(InStr(Rus, Mid(S, i, 1))) > 0 Then

nRus= nRus + 1

EndIf

Nexti

MsgBox("Кол-во =" + Str(nRus))

EndSub

3

Subшифр()

DimS As String, Sogl As String

DimS1 As String, c As String

DimGl As String, K As Long

Dimi As Long

S= InputBox("Ввод строки")

Gl= "аеиоуыэюяё"

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

K= K + 1

IfK > Len(Gl) Then K = 1

S1= S1 + Mid(Gl, K, 1)

Nexti

Fori = 1 To (Len(S1)) / 2

CallSwap(S1, i, Len(S1) - (i - 1))

Nexti

S= S1

MsgBox(S)

EndSub


4

Subшифр()

DimS As String, Sogl As String

DimS1 As String, c As String

DimGl As String, K As Long

Dimi As Long

S= InputBox("Ввод шифра")

Fori = 1 To (Len(S)) / 2

CallSwap(S, i, Len(S) - (i - 1))

Nexti

Fori = 1 To Len(S) Step 2

c= Mid(S, i, 1)

S1= S1 + c

Nexti

S= S1

MsgBox(S)

EndSub

5

SubЗамена()

DimS As String, S1 As String

Dimn As Long, C As String

S= InputBox("Ввод строки")

n= 0

Fori = 1 To Len(S)

C= Mid(S, i, 1)

IfMid(S, i, 1) = "&" Then

S1= S1 + "имя"

n= n + 1

ElseIfMid(S, i, 1) = "#" Then

S1= S1 + "имя"

n= n + 1

Else

S1= S1 + C

EndIf

Nexti

MsgBox(S1)

MsgBox(n)

End Sub


Билет№4

1

SelectCase УСЛ} ЕслиУСЛ равно

CaseЗН1 }ЗН1 то выполня-

S1 }ется S1,если ЗН2

CaseЗН2 }то S2 ит. д.Если

S2 }УСЛ не равнони

- - - - - - - - }одномуиз ЗН, то

CaseЗНn }выполняетсяSn+1

Sn }

CaseElse }

Sn+1 }

EndSelect }

2

SubЗнаки( )

DimS As String, Rus As String

DimnRus As Integer, i As Long

S= InputBox("Введитетекст")

Rus= "абвгдежзиклмнопрстуфхцчшщъыьэюяё"

nRus= 0

Fori = 1 To Len(S)

If(InStr(Rus, Mid(S, i, 1))) > 0 Then

nRus= nRus + 1

EndIf

Nexti

MsgBox("Кол-во =" + Str(nRus))

EndSub

3

Sub Swap(S As String, i AsLong, j As Long)

Dim c As String

c = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = c

End Sub


Sub шифр()

Dim S As String, Sh As String

Dim S1 As String, c As String

Dim Gl As String, K As Long

Dim i As Long

Sh = "Шаблон"

S = InputBox("Вводстроки")

Gl = "аеиоуыэюяё"

For i = 1 To Len(S)

c = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sh) Then K = 1

S1 = S1 + Mid(Sh, K, 1)

End If

Next i

Fori = 1 To (Len(S1)) / 2

CallSwap(S1, i, Len(S1) - (i - 1))

Nexti

S= S1

MsgBox(S)

End Sub

4

Subшифр()

DimS As String, Sh As String

DimS1 As String, c As String

DimGl As String, K As Long

Dimi As Long

Sh= "Шаблон"

S= InputBox("Ввод строки")

Gl= "аеиоуыэюяё"

Fori = 1 To (Len(S1)) / 2

CallSwap(S1, i, Len(S1) - (i - 1))

Nexti

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

IfInStr(Gl, c) > 0 Then

i= i + 1

EndIf

Nexti

S= S1

MsgBox(S)

EndSub

5

SubЗамена()

DimS As String, S1 As String

Dimn As Long, C As String

S= InputBox("Ввод строки")

n= 0

Fori = 1 To Len(S)

C= Mid(S, i, 1)

IfMid(S, i, 1) = "#" Then

S1= S1 + "Имя"

i= i + 2

n= n + 1

ElseIfMid(S, i, 3) = "Имя" Then

S1= S1 + "#"

i= i + 2

n= n + 1

Else

S1= S1 + C

EndIf

Nexti

MsgBox(S1)

MsgBox(n)

EndSub



Билет№5

1

Операторыописания типовпеременных


DIM-описываетпеременныеи выделяет дляних память.

Dim StringasType

String - имяпеременной

Type -описание переменной

Описание Размер Типданных Диапазон
Byte Целоечисло 0-255
Integer Целоечисло

+32768

Long Целоечисло

+2 млрд.

Double Веществ.

+10+304

String Len(String) Символы 0-~64000
Boolean True/False 1;0
Variant 16б Произвольн Произв.

2

Sub Знаки()

Dim S As String, Pr As String

Dim nPr As Integer, i As Long

S = InputBox("Введитетекст")

Pr = ",.?!:;"

nPr = 0

For i = 1 To Len(S)

If (InStr(Pr, Mid(S, i, 1))) >0 Then

nPr = nPr + 1

End If

Next i

MsgBox ("Кол-во=" + Str(nPr))

End Sub

3

Sub Swap(SAs String, i As Long, j As Long)

Dim c As String

c = Mid(S, i, 1)

Mid(S, i, 1) = Mid(S, j, 1)

Mid(S, j, 1) = c

End Sub


Sub шифр()

Dim S As String, Sh As String

Dim S1 As String, c As String

Dim Gl AsString, K As Long

Dim i As Long

Sh = "Шаблон"

S = InputBox("Вводстроки")

Gl = "аеиоуыэюяё"

For i = 1 To Len(S)

c = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then

K = K + 1

If K > Len(Sh) Then K = 1

S1 = S1 + Mid(Sh, K, 1)

End If

Next i

For i = 1To Len(S1) - 1 Step 2

Call Swap(S1, i, i + 1)

Next i

For i = 1 To Len(S1) - 2 Step3

Call Swap(S1, i, i + 2)

Next i

S = S1

MsgBox (S)

End Sub


4

Sub Раскодировщик()

Dim S As String, i As Long

Dim S1 As String, c As String

Dim Gl As String, K As Long

S = InputBox("Вводшифра")

Gl = "аеиоуыэюяё"

For i = 1 To Len(S) - 2 Step 3

Call Swap(S, i, i + 2)

Next i

For i = 1 To Len(S) - 1 Step 2

Call Swap(S, i, i + 1)

Next i

For i = 1 To Len(S)

c = Mid(S, i, 1)

S1 = S1 + c

If InStr(Gl, c) > 0 Then i= i + 1

Next i

MsgBox (S1)

End Sub

5

Sub Замена()

Dim S As String, S1 As String

Dim n As Long, C As String

S = InputBox("Вводстроки")

n = 0

For i = 1 To Len(S)

C = Mid(S, i, 1)

If Mid(S, i, 1) = "&"Then

S1 = S1 + "Фамилия"

n = n + 1

ElseIf Mid(S, i, 3) = "Имя"Then

S1 = S1 + "Фамилия"

i = i + 2

n = n + 1

Else

S1 = S1 + C

End If

Next i

MsgBox (S1)

MsgBox (n)

End Sub



Билет№6

1

Array(Список)

Возвращаетзначение типаVariant,

содержащеемассив

Пример:

Dimm as Variant

m=Array(1,7,-1,2,3)

m(0)=1

m(1)=7

m(2)=-1

m(3)=2

m(4)=3

2

Sub Знаки()

Dim S As String, Pr As String

Dim nPr As Integer, i As Long

S = InputBox("Введитетекст")

Pr = ",.?!:;"

nPr = 0

For i = 1 To Len(S)

If (InStr(Pr, Mid(S, i, 1))) >0 Then

nPr = nPr + 1

End If

Next i

MsgBox ("Кол-во=" + Str(nPr))

End Sub

3

SubSwap(S As String, i As Long, j As Long)

DimC As String

C= Mid(S, i, 1)

Mid(S,i, 1) = Mid(S, j, 1)

Mid(S,j, 1) = C

EndSub


Subшифр()

DimS As String, Sh As String

DimS1 As String, c As String

DimGl As String, K As Long

Dimi As Long

Sh= "Шаблон"

S= InputBox("Ввод строки")

Gl= "бвгджзклмнпрстфхцчшщъь"

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

IfInStr(Gl, c) > 0 Then

K= K + 1

IfK > Len(Sh) Then K = 1

S1= S1 + Mid(Sh, K, 1)

EndIf

Nexti

Fori = 1 To Len(S1) - 3 Step 4

CallSwap(S1, i, i + 3)

CallSwap(S1, i + 1, i + 2)

Nexti

S= S1

MsgBox(S)

EndSub


4

SubРаскодировщик()

DimS As String, i As Long

DimS1 As String, c As String

DimGl As String, K As Long

S= InputBox("Ввод шифра")

Gl= "бвгджзклмнпрстфхцчшщъь"

Fori = 1 To Len(S) - 3 Step 4

CallSwap(S, i, i + 3)

CallSwap(S, i + 1, i + 2)

Nexti

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

IfInStr(Gl, c) > 0 Then i = i + 1

Nexti

MsgBox(S1)

EndSub



Билет№1

1

Len(String)-Возвращаетдлину

строкиString

Left(String,Length)-Возвращаетлевые

Lengthсимволов строкиString

Right(String,Length)-Возвращаетправые

Lengthсимволов строкиString

Mid(String, Start[,Length] )-Возвращает

Lengthсимволовиз строк String,

начинаяс символа сномером Start

Trim(String)-Убираетначальные иконеч-

ныепробелы в строкеString

Ltrim(String)-Убираетначальные

пробелыв строке String

Rtrim(String)-Убираетконечные

пробелыв строке String

InStr([Start,] String, String1[,Comp] )-Возв-

ращаетпозицию первоговхождения

String1в строкуString

2

SubЗнаки( )

DimS As String, Num As String

DimnNum As Integer, i As Long

S= InputBox("Введитетекст")

Num= "0123456789"

nNum= 0

Fori = 1 To Len(S)

If(InStr(Num, Mid(S, i, 1))) > 0 Then

nNum= nNum + 1

EndIf

Nexti

MsgBox("Кол-во =" + Str(nNum))

EndSub

3

SubSwap(S As String, i As Long, j As Long)

DimC As String

C= Mid(S, i, 1)

Mid(S,i, 1) = Mid(S, j, 1)

Mid(S,j, 1) = C

EndSub


Subшифр( )

DimS As String, Sogl As String

DimS1 As String, c As String

DimGl As String, K As Long

Dimi As Long

Sogl= "бвгджзклмнпрстфхцчшщъь"

S= InputBox("Ввод строки")

Gl= "аеиоуыэюяё"

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c



IfInStr(Gl, c) > 0 Then

K= K + 1

IfK > Len(Sogl) Then K = 1

S1= S1 + Mid(Sogl, K, 1)

EndIf

Nexti

Fori = 1 To Len(S1) - 4 Step 5

CallSwap(S1, i, i + 4)

CallSwap(S1, i + 1, i + 3)

Nexti

S= S1

MsgBox(S)

EndSub

4

SubРаскодировщик()

DimS As String, i As Long

DimS1 As String, c As String

DimGl As String, K As Long

S= InputBox("Ввод шифра")

Gl= "аеиоуыэюяё"

Fori = 1 To Len(S) - 4 Step 5

CallSwap(S, i, i + 4)

CallSwap(S, i + 1, i + 3)

Nexti

Fori = 1 To Len(S)

c= Mid(S, i, 1)

S1= S1 + c

IfInStr(Gl, c) > 0 Then i = i + 1

Nexti

MsgBox(S1)

EndSub

5

SubЗамена( )

DimS As String, S1 As String

Dimn As Long, C As String

S= InputBox("Ввод строки")

n= 0

Fori = 1 To Len(S)

C= Mid(S, i, 1)

IfMid(S, i, 3) = "Имя" Then

S1= S1 + "Фамилия ИмяОтчество"

n= n + 1

i= i + 2

ElseIfMid(S, i, 7) = "Фамилия"Then

S1= S1 + "Фамилия ИмяОтчество"

i= i + 6

n= n + 1

Else

S1= S1 + C

EndIf

Nexti

MsgBox(S1)

MsgBox(n)

EndSub