0% found this document useful (0 votes)
43 views13 pages

Programacion Matrices y Vectores

This document contains code and notes for various vector and matrix tasks in Visual Basic, including: - Reading in student codes and grades - Displaying, searching for, and finding the highest/lowest grades - Calculating number of passing/failing students - Finding the frequency and mode of grades - Ranking students by grade - A menu to select different options It also contains code for generating random numbers without repetition, numerical integration, linear interpolation, and sorting algorithms like quicksort and bubble sort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views13 pages

Programacion Matrices y Vectores

This document contains code and notes for various vector and matrix tasks in Visual Basic, including: - Reading in student codes and grades - Displaying, searching for, and finding the highest/lowest grades - Calculating number of passing/failing students - Finding the frequency and mode of grades - Ranking students by grade - A menu to select different options It also contains code for generating random numbers without repetition, numerical integration, linear interpolation, and sorting algorithms like quicksort and bubble sort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Tarea de vectores y

matrices
2016

CDIGO Y NOTAS:
Module Module1
Sub ingresar(ByRef n As Integer)
Console.Write("Ingresar el nmero de alumnos: ")

2016

Arequipa Per

n = Console.ReadLine()
Console.WriteLine()
End Sub
Sub leer_notas(ByRef cod() As Integer, ByRef nota() As Single, ByVal n As Integer)
Dim x As Integer
For x = 0 To n - 1
Console.ForegroundColor = ConsoleColor.Magenta
Console.Write("cod({0}): ", x)
cod(x) = Console.ReadLine()
Console.Write("nota({0}): ", x)
nota(x) = Console.ReadLine()
Console.WriteLine(" ")
Next
End Sub
Sub Mostrar_nota(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Console.Clear()
Dim x As Integer
For x = 0 To n - 1
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Cod({0})= {1}", x, cod(x))
Console.WriteLine("Nota({0})= {1}", x, nota(x))
Console.WriteLine(" ")
Next
Console.WriteLine(" ")
End Sub
Sub Busqueda(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim codigo As Integer
Console.ForegroundColor = ConsoleColor.Cyan
Console.Write("Ingresar cdigo: ")
codigo = Console.ReadLine()
For ind = 0 To n - 1
If codigo <> cod(ind) Then
Else
Console.ForegroundColor = ConsoleColor.Yellow
Console.Write(" Codigo = {0}", codigo)
Console.Write(" Nota = {0} ", nota(ind))
Console.WriteLine(" ")
End If
Next
End Sub
Sub nota_mayor(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim mayornota As Integer = 0
Dim posicion As Integer
For ind = 0 To n - 1
If nota(ind) > mayornota Then
mayornota = nota(ind)
posicion = ind
End If
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine(" La Mayor Nota es: {0} y su cdigo es: {1}", mayornota,
cod(posicion))

Grupo: APPLE

Console.WriteLine(" ")
End Sub
Sub nota_menor(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim menornota As Integer = 0
Dim posicion As Integer
For ind = 0 To n - 1
If nota(ind) < menornota Then
menornota = nota(ind)
posicion = ind
End If
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine(" La Menor Nota es: {0} y su cdigo es: {1}", menornota,
cod(posicion))
Console.WriteLine(" ")
End Sub
Sub adp(ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim AP As Integer = 0
Dim DAP As Integer = 0
For ind = 0 To n - 1
If nota(ind) > 10.5 Then
AP = AP + 1
Else
DAP = DAP + 1
End If
Next
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine(" El nmero de aprobados es: {0}", AP)
Console.WriteLine(" El nmero de desaprobados es: {0}", DAP)
Console.WriteLine(" ")
End Sub
Sub frecuencia(ByRef nota() As Single, ByRef frec() As Integer, ByRef n As Integer)
Dim i, j, c As Integer
For i = 0 To n - 1
c=0
For j = 0 To n - 1
If (nota(i) = nota(j)) Then
c=c+1
End If
frec(i) = c
Next
Console.WriteLine("Frecuencia[NOTA {0}]={1}", nota(i), c)
Console.WriteLine(" ")
Next
End Sub
Sub moda(ByRef nota() As Single, ByRef frec() As Integer, ByRef n As Integer)
Dim m As Integer = 0
Dim mayorfrecuencia As Integer = 0
Dim pos As Integer
For m = 0 To n - 1
If (frec(m) > mayorfrecuencia) Then
mayorfrecuencia = frec(m)

Grupo: APPLE

pos = m
End If
Next
Console.WriteLine("La nota que ms repite es: {0}", nota(pos))
End Sub
Sub ranking(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim I, J, TE, T As Integer
For I = 0 To n - 2
For J = I + 1 To n - 1
If nota(I) < nota(J) Then
T = nota(I)
nota(I) = nota(J)
nota(J) = T
TE = cod(I)
cod(I) = cod(J)
cod(J) = TE
End If
Next
Next
Console.ForegroundColor = ConsoleColor.Magenta
Console.SetCursorPosition(1, 14)
Console.WriteLine("RANKING DE NOTAS")
J = 20
For I = 0 To n - 1
Console.SetCursorPosition(1, I + J - 4)
Console.WriteLine("Codigo: {0}", cod(I))
Console.SetCursorPosition(12, I + J - 4)
Console.WriteLine("Nota: {0}", nota(I))
J=J+1
Next
End Sub
Sub MENU(ByRef cod() As Integer, ByRef nota() As Single, ByRef frec() As Integer,
ByRef n As Integer)
Dim OPC As Integer
While (OPC <> 9)
Console.Clear()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("BASE DE DATOS")
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine("1. CODIGOS Y NOTAS
")
Console.WriteLine("2. BUSCAR POR CODIGO
")
Console.WriteLine("3. RANKING DE NOTAS
")
Console.WriteLine("4. FRECUENCIA DE NOTAS
")
Console.WriteLine("5. MODA DE NOTAS
")

Grupo: APPLE

Console.WriteLine("6. NOTA MAYOR


")
Console.WriteLine("7. NOTA MENOR
")
Console.WriteLine("8. APROBADOS Y DESAPROBADOS
Console.WriteLine("9. SALIR
")
Console.Write("Ingrese Opcin: ")
OPC = Console.ReadLine
Console.ForegroundColor = ConsoleColor.Red
Select Case (OPC)
Case 1
Mostrar_nota(cod, nota, n)
Case 2
Busqueda(cod, nota, n)
Case 3
ranking(cod, nota, n)
Case 4
frecuencia(nota, frec, n)
Case 5
moda(nota, frec, n)
Case 6
nota_mayor(cod, nota, n)
Case 7
nota_menor(cod, nota, n)
Case 8
adp(nota, n)
Case 9
Console.WriteLine("FIN DEL PROGRAMA")
End Select
Console.ReadLine()
Console.Clear()
End While
End Sub
Sub Main()
Dim n As Integer
ingresar(n)
Dim cod(n) As Integer
Dim nota(n) As Single
Dim frec(n) As Integer
leer_notas(cod, nota, n)
MENU(cod, nota, frec, n)
Console.ReadLine()
End Sub

")

End Module

NMEROS ALEATORIOS,
INTERPOLACIN:

INTEGRACIN E

Grupo: APPLE

Module Module1
Sub Mostrar_vector(ByVal V() As Integer)
Randomize()
Dim x, y, num As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("NUMEROS ALEATORIOS SIN
REPETICION")
Console.WriteLine(" ")
For x = 0 To 10
num = Rnd() * 9 + 1
If x > 0 Then
For y = 0 To 10
If num = V(y) Then
num = Rnd() * 9 + 1
y = -1
End If
Next
End If
V(x) = num
Console.WriteLine("V({0})= {1}", x, V(x))
Next
End Sub
Sub Leer_vector(ByRef V() As Integer, ByVal n As Integer)
Randomize()
Dim x As Integer
For x = 0 To n
V(x) = Rnd() * 10 + 1
Next
End Sub
Sub mostrar_vector(ByVal v() As Integer, ByVal n As Integer)
Dim x As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
For x = 0 To n - 1
Console.WriteLine("v({0})= {1}", x, v(x))
Next
End Sub
Sub Integral(ByVal V() As Integer, ByVal P() As Integer, ByVal n
As Integer)
Dim A As Single
Dim x As Integer
Dim I As Single = 0
For x = 0 To n - 1
A = ((P(x) + P(x + 1)) * (V(x + 1) - V(x))) / 2
I=I+A
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("La integral es {0}", I)
Console.WriteLine(" ")
Console.ReadLine()

Grupo: APPLE

End Sub
Sub interpolacion(ByVal v() As Integer, ByVal Z() As Integer, ByVal n As Integer)
Dim ind As Integer = 0
Dim xn, yn, i As Single
Console.Write("Ingrese el valor de XN: ")
xn = Console.ReadLine
For i = 0 To n
If xn > v(ind) Then
ind = ind + 1
Else
yn = ((Z(ind) - Z(ind - 1)) * (xn - v(ind - 1))) / (v(ind) - v(ind - 1)) + Z(ind - 1)
End If
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("EL VALOR DE YN ES DE: {0}", yn)
Console.WriteLine(" ")
Console.ReadLine()
End Sub
Sub menu()
Dim op As Integer
Dim v(10) As Integer
Do
Console.Clear()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("MENU DE APLICACION DE VECTORES")
Console.WriteLine(" ")
Console.WriteLine("1.NUMEROS ALEATORIOS SIN REPETICION")
Console.WriteLine("2.INTERPOLACION LINEAL")
Console.WriteLine("3.INTEGRALES")
Console.WriteLine("4.SALIR")
Console.Write("Escoger Opcin: ")
op = Console.ReadLine
Console.WriteLine(" ")
Select Case (op)
Case 1
Mostrar_vector(v)
Case 2
Dim n As Integer = 5
Dim Z(n) As Integer
Dim B(n) As Integer
Leer_vector(B, n)
Mostrar_vector(B, n)
Leer_vector(Z, n)
Mostrar_vector(Z, n)
interpolacion(B, Z, n)
Case 3
Dim n As Integer = 10
Dim s(n) As Integer
Dim P(n) As Integer
Leer_vector(P, n)
Mostrar_vector(P, n)
Leer_vector(s, n)
Mostrar_vector(s, n)
Integral(P, s, n)

Grupo: APPLE

Case 4
End
End Select
Loop While (op < 5)
End Sub
Sub Main()
Dim V(10) As Integer
menu()
Console.ReadLine()
End Sub
End Module

MTODOS DE ORDENAMIENTO:
Module Module1
Function menu()
Dim op As Integer
Console.SetCursorPosition(10, 0)
Console.WriteLine("ORDENAMIENTO DE DATOS")
Console.WriteLine("1. Quicksort")
Console.WriteLine("2. Mtodo Burbuja")
Console.Write("Escoger Opcin: ")
Op = Console.ReadLine
Return Op
End Function
Sub orden1(ByRef n As Integer)
Console.Clear()
Console.WriteLine("Ordenamiento por Quicksort")
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("Ingrese el nmero de datos: ")
n = Console.ReadLine()
Console.WriteLine(" ")
Dim vector(n) As Integer
Dim i As Integer
If 0 < n And n < 10000000000 Then
For i = 1 To n
Console.ForegroundColor = ConsoleColor.Cyan
Console.Write("Ingrese el elemento {0}: ", i)
vector(i) = Console.ReadLine()
Next
Else
Console.Write("Ingrese Nmeros: ")
End If
quicksort(vector, 0, n)
mostrar1(vector, n)
End Sub
Sub quicksort(ByRef vector() As Integer, ByVal inicio
As Integer, ByVal fin As Integer)
Dim izq, der, pos, aux As Integer
Dim band As Integer
izq = inicio
der = fin
pos = inicio
band = 1

Grupo: APPLE

While (band = 1)
band = 0
While (vector(pos) <= vector(der) And pos <> der)
der = der - 1
End While
If pos <> der Then
aux = vector(pos)
vector(pos) = vector(der)
vector(der) = aux
pos = der
While (vector(pos) >= vector(izq) And pos <> izq)
izq = izq + 1
End While
If (pos <> izq) Then
band = 1
aux = vector(pos)
vector(pos) = vector(izq)
vector(izq) = aux
pos = izq
End If
End If
End While
If (pos - 1) > inicio Then
quicksort(vector, inicio, (pos - 1))
End If
If (fin > (pos + 1)) Then
quicksort(vector, (pos + 1), fin)
End If
End Sub
Sub mostrar1(ByRef vect() As Integer, ByVal n As Integer)
Dim i As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
For i = 1 To n
Console.WriteLine("Posiciones: {0} - Nmero: {1}", i, vect(i))
Next
Console.ReadLine()
End Sub
Sub orden2(ByVal n As Integer)
Console.Clear()
Console.WriteLine("Ordenamiento por Mtodo Burbuja")
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("Ingrese el nmero de datos:")
n = Console.ReadLine()
Console.WriteLine(" ")
Dim vector(n) As Integer
Dim i As Integer
If 0 < n And n < 10000000000 Then
For i = 1 To n
Console.ForegroundColor = ConsoleColor.Cyan
Console.Write("Ingrese el elemento {0}: ", i)
vector(i) = Console.ReadLine()
Next
Else

Grupo: APPLE

Console.Write("Ingrese Nmeros: ")


End If
metodoburbuja(vector, n)
mostrar2(vector, n)
End Sub
Sub metodoburbuja(ByRef VECT() As Integer, ByVal n As Integer)
Dim Auxiliar As Integer = 0
For i = 0 To n - 2 Step 1
For j = i + 1 To n - 1 Step 1
If VECT(i) < VECT(j) Then
Auxiliar = VECT(i)
VECT(i) = VECT(j)
VECT(j) = Auxiliar
End If
Next
Next
End Sub
Sub mostrar2(ByRef vect() As Integer, ByVal n As Integer)
Dim i As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
For i = 1 To n
Console.WriteLine("Posiciones: {0} - Nmero: {1}", i, vect(i))
Next
Console.ReadLine()
End Sub
Sub main()
Dim opcion, n As Integer
opcion = menu()
Select Case opcion
Case 1
orden1(n)
Case 2
orden2(n)
End Select
End Sub
End Module

PILAS:
Module Module1

Grupo: APPLE

Sub Crear(ByRef Pila() As Integer, ByRef ni As


Single)
Dim x As Integer
For x = 0 To ni - 1
Console.Write("Ingresar Nmero: ")
Pila(x) = Console.ReadLine()
Next
End Sub
Sub Mostrar(ByVal Pila() As Integer, ByRef ni As
Single)
Dim x As Integer
For x = 0 To ni - 1
Console.WriteLine(" {0} ocupa el espacio {1}
", Pila(x), x + 1)
Next
End Sub
Sub Quitar(ByVal Pila() As Integer, ByRef ni As
Single, ByRef nf As Single)
Dim x As Integer
nf = ni - 1
For x = 0 To nf - 1
Pila(x) = Pila(x + 1)
Console.WriteLine(" {0} ocupa el espacio {1} ", Pila(x), x + 1)
Next
End Sub
Sub Ingresar(ByVal Pila() As Integer, ByRef ni As Single, ByVal nf As Single)
nf = ni + 1
Console.WriteLine("Ingresar nmero: ")
Pila(ni + 1) = Console.ReadLine()
For x = 0 To nf - 1
Console.WriteLine(" {0} ocupa el espacio {1} ", Pila(x), x + 1)
Next
End Sub
Sub Menu(ByVal Pila() As Integer, ByRef ni As Single, ByVal nf As Single)
Dim op As Integer
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(" 1. CREAR ")
Console.WriteLine(" 2. QUITAR ")
Console.WriteLine(" 3. MOSTRAR ")
Console.WriteLine(" 4. INGRESAR ")
Console.WriteLine(" 5. FIN ")
Console.Write("Ingresar Opcin: ")
op = Console.ReadLine()
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Magenta
Select Case (op)
Case 1
Crear(Pila, ni)
Menu(Pila, ni, nf)
Case 2
Quitar(Pila, ni, nf)
Menu(Pila, ni, nf)
Case 3
Mostrar(Pila, ni)

Grupo: APPLE

10

Menu(Pila, ni, nf)


Case 4
Ingresar(Pila, ni, nf)
Menu(Pila, ni, nf)
Case 5
End
End Select
End Sub
Sub Main()
Dim ni As Integer = 5
Dim nf As Integer = 0
Dim Pila(ni) As Integer
Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("Men de Pilas")
Console.WriteLine(" ")
Menu(Pila, ni, nf)
Console.ReadLine()
End Sub
End Module

COLAS:
Module Module1
Sub Crear(ByRef Nombre() As String, ByRef ni As Single)
Dim x As Integer
For x = 0 To ni - 1
Console.Write("Ingresar nombre: ")
Nombre(x) = Console.ReadLine()
Next
End Sub
Sub Mostrar(ByVal Nombre() As String, ByVal ni As Single)
Dim x As Integer
For x = 0 To ni - 1
Console.WriteLine(" {0} ocupa el espacio {1} ", Nombre(x), x + 1)
Next
End Sub
Sub Ingresar(ByVal Nombre() As String, ByVal ni As Single, ByVal nf As Single)
nf = ni + 1
Console.WriteLine("Ingresar nombre: ")
Nombre(nf - 1) = Console.ReadLine()
Mostrar(Nombre, nf - 1)
End Sub
Sub Menu(ByVal Nombre() As String, ByVal ni As Single, ByVal nf As Single)
Dim op As Integer
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine(" 1. CREAR ")
Console.WriteLine(" 2. MOSTRAR ")
Console.WriteLine(" 3. INGRESAR ")
Console.WriteLine(" 4. FIN ")
Console.Write("Ingrese Opcin: ")
op = Console.ReadLine()
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Cyan

Grupo: APPLE

11

Select Case (op)


Case 1
Crear(Nombre, ni)
Menu(Nombre, ni, nf)
Case 2
Mostrar(Nombre, ni)
Menu(Nombre, ni, nf)
Case 3
Ingresar(Nombre, ni, nf)
Menu(Nombre, ni, nf)
Case 4
End
End Select
End Sub
Sub Main()
Dim ni As Integer = 5
Dim nf As Integer = 0
Dim Nombre(ni) As String
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Men de Colas")
Console.WriteLine(" ")
Menu(Nombre, ni, nf)
Console.ReadLine()
End Sub
End Module

Grupo: APPLE

12

You might also like