0% found this document useful (0 votes)
50 views4 pages

Standardni Modul Sa Potprogramskom Procedurom

The document describes a program that takes an integer array as input, checks if it contains both even and odd numbers, and if so, creates two new arrays containing the even and odd elements respectively. It provides the code for a subroutine to perform this task, and an event procedure that gets values for m and n from textboxes, reads an array from a text file, calls the subroutine, and displays the output arrays.

Uploaded by

An2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Standardni Modul Sa Potprogramskom Procedurom

The document describes a program that takes an integer array as input, checks if it contains both even and odd numbers, and if so, creates two new arrays containing the even and odd elements respectively. It provides the code for a subroutine to perform this task, and an event procedure that gets values for m and n from textboxes, reads an array from a text file, calls the subroutine, and displays the output arrays.

Uploaded by

An2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Pismeni ispit iz Osnova programiranja (Statut ’06), Programiranja (Statut ’00) i

Baza podataka (Statut ’06), 8. 9. 2007.


Napisati potprogramsku proceduru koja od datog celobrojnog nenegativnog niza X od n elemenata formira dva
niza: niz XP od različitih parnih članova niza X i niz XN od različitih neparnih članova niza X.
Datoteka ulaz.txt ima bar 20 redova, a svaki red počev od prve pozicije sadrži bar 20 celih nenegativnih
brojeva, pri čemu svaki broj zauzima 3 mesta. Kreirati proceduru događaja koja odgovara komandnom dugmetu
"RADI" sa ekranskog obrasca "ISPIT" koja učitava iz TextBox-ova prirodne brojeve m i n, m, n  20 , a zatim
iz m-tog reda datoteke celobrojni nenegativni niz X od n elemenata – prvih n brojeva u tom redu. Niz X se
smatra ispravnim ako sadrži i parne i neparne brojeve. Ispitati ispravnost niza, pa ako je ispravan, pozivajući
gornji potprogram formirati nizove XP i XN. Prikazati na ekranskom obrascu nizove X, XP i XN, kao i
najmanje članove nizova XP i XN. Ako niz X nije ispravan, predvideti odgovarajuću poruku.

REŠENJE ZADATKA
Standardni modul sa potprogramskom procedurom:
Module Module1

Public Sub parni_neparni(ByVal n As Byte, ByRef X() As Short, ByRef XP() As Short,
ByRef pb As Byte, ByRef XN() As Short, ByRef nb As Byte)

Dim i, j, k As Byte
Dim s As Short

For i = 1 To n
If X(i) Mod 2 = 0 Then
XP(1) = X(i)
Exit For
End If
Next i

For i = 1 To n
If X(i) Mod 2 <> 0 Then
XN(1) = X(i)
Exit For
End If
Next i

pb = 1
nb = 1

For i = 1 To n
If X(i) Mod 2 = 0 Then
s = 0
For j = 1 To pb
If X(i) <> XP(j) Then s = s + 1
Next j
If s = pb Then
pb = pb + 1 : XP(pb) = X(i)
End If
Else
s = 0
For k = 1 To nb
If X(i) <> XN(k) Then s = s + 1
Next k
If s = nb Then
nb = nb + 1 : XN(nb) = X(i)
End If
End If

Next i

End Sub
End Module

Procedura događaja za komandno dugme “START”:


Public Class Form1

Private Sub RADI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles RADI.Click
Dim m, n, i, j, suma, pb, nb As Byte
Dim X(), XP(), XN(), min1, min2 As Short
Dim linija, S(), S1(), S2() As String
'ucitavanje brojeva m i n iz text box-ova
m = TextBox1.Text
n = TextBox2.Text

'provera ispravnosti ucitanih brojeva


If m <= 20 And n <= 20 And m > 0 And n > 0 Then

ReDim X(n), S(n), XP(n), XN(n), S1(n), S2(n)


'otvaranje tekstualne datoteke za citanje
FileOpen(1, "C:\ulaz.txt", OpenMode.Input)
For i = 1 To m
linija = LineInput(1)
Next i
For j = 1 To n
X(j) = Val(Trim(Mid(linija, 3 * j - 2, 3)))
Next j

suma = 0
For i = 1 To n
suma = suma + X(i) Mod 2
Next i
If suma = 0 Or suma = n Then
MsgBox(" Niz je neispravan", , "Poruka o ispravnostu niza")
Else
parni_neparni(n, X, XP, pb, XN, nb)
For i = 1 To n
S(i) = S(i) + Space(5 - Len(Str(X(i)))) + Str(X(i))
Next i
TextBox5.Lines = S
For i = 1 To pb
S1(i) = S1(i) + Space(5 - Len(Str(XP(i)))) + Str(XP(i))
Next i
TextBox3.Lines = S1
For i = 1 To nb
S2(i) = S2(i) + Space(5 - Len(Str(XN(i)))) + Str(XN(i))
Next i
TextBox4.Lines = S2
min1 = XP(1)
min2 = XN(1)
For i = 2 To pb
If XP(i) < min1 Then min1 = XP(i)
Next i
For i = 2 To nb
If XN(i) < min2 Then min2 = XN(i)
Next i
TextBox6.Text = min1
TextBox7.Text = min2

End If

Else
'upozorenje na pogresne unete vrednosti brojeva m i n
MsgBox(" Brojevi m i n moraju niti manji od 20,unesite ih ponovo!", ,
"Pogresan unos")
End If
End Sub
End Class
Jedan realizovani test primer:

You might also like