TALLER ARREGLOS N-DIMENSIONALES ALGORITMO NOTAS

Anuncio
TALLER
ARREGLOS N-DIMENSIONALES
------------------------------------------------------------------------------------------------------Un docente que tiene a cargo M asignaturas necesita ordenar las calificaciones definitivas en orden
ascendente e imprimirlas por asignaturas.
------------------------------------------------------------------------------------------------------1. Dominio del Problema.
Ordenar e imprimir las notas de manera ascendente por asignaturas.
2. Análisis.
2.1. Datos de Entrada:
ENTERO:m= Cantidad de asignaturas
CADENA:M[1..m]= Arreglo que contiene los nombres de las m asignaturas
ENTERO:n= Cantidad de notas
ENTERO:N[1..n]= Arreglo que contiene cantidad de notas por asignatura
REAL:NA[1..N[i]]= Arreglo que contiene todas las notas por asignatura
2.2. Datos de Salida:
REAL:NOTAS[1..N[i],1..m] = Arreglo que contiene N[i] cantidad de notas por m asignaturas
2.3. Datos auxiliares:
REAL:T= Variable que contiene el valor de la nota temporalmente
ENTERO:i,j,k= iteradores
2.4. Procesos
1. Leer m
2. Iniciar i hasta m, leer M[i]. Finalizar i.
3. Iniciar i hasta m, leer N[i].
4. Iniciar j hasta N[i], leer NA[j]. Finalizar j.
5. Iniciar j hasta N[i], ordenar ascendente NA[j]. NOTAS[j,i]  NA[j]. Finalizar j. Finalizar i.
6. Iniciar i hasta m, Iniciar j hasta N[i], escribir NOTAS[j,i]. Finalizar j. Finalizar i.
3. Representación de la alternativa de solución en un estándar.
ALGORITMO NOTAS
VARIABLES
ENTERO: m, n, A[1..n], i, j, k
REAL: NA[1..N[i]], NOTAS[1..N[i],1..m],T
CADENA: M[1..m];
FIN_VARIABLES
INICIO
ESCRIBIR (“Cantidad de asignaturas?”)
LEER (m)
DESDE (i  1, m, INCREMENTO 1)
ESCRIBIR (“Nombre de la asignatura”,i,”?”)
LEER (M[i])
FIN_DESDE
DESDE (i  1, m, INCREMENTO 1)
ESCRIBIR (“Cantidad de notas para la asignatura”,M[i],”?”)
LEER (N[i])
DESDE (j  1, N[i], INCREMENTO 1)
ESCRIBIR (“Digite la nota”,j,”de la asig”M[i])
LEER (NA[j])
FIN_DESDE
DESDE (k  1, N[i]-1, INCREMENTO 1)
DESDE (j  k+1, N[k], INCREMENTO 1)
SI (NA[j] > NA[k]) ENTONCES
TNA[j]
NA[j] NA[k]
NA[k]T
FIN_SI
FIN_DESDE
FIN_DESDE
DESDE (j  1, N[i], INCREMENTO 1)
NOTAS[j,i]NA[j]
FIN_DESDE
FIN_DESDE
DESDE (i  1, m, INCREMENTO 1)
DESDE (j  1, N[i], INCREMENTO 1)
ESCRIBIR(“Nota”,j,”:”,NOTAS[j,i])
FIN_DESDE
FIN_DESDE
FIN_INICIO
FIN_ALGORITMO
4. Prueba de escritorio.
SOLUCIÓN QUIZ 2
ARREGLOS UNIDIMENSIONALES
------------------------------------------------------------------------------------------------------01. Dado dos arreglos Arreglo1 y Arreglo2 unidimensionales de N elementos cada uno, obtener un arreglo
Arreglo3 unidimensional diferente donde su posición i almacene la suma de Arreglo1[i]+Arreglo2[i] y
mostrar el mayor elemento del Arreglo3[i] y su posición.
------------------------------------------------------------------------------------------------------1. Dominio del Problema
A partir de 2 arreglos unidimensionales obtener un tercero sumando los elementos en la misma
posición de los 2 arreglos iniciales y del tercero seleccionar el mayor y su posición.
2. Análisis
2.1. Datos de Entrada:
ENTERO: N
REAL : Arreglo1[1..N], Arreglo2[1..N]
2.2. Datos de Salida:
REAL : mayor
ENTERO: mayor_indice
2.3. Datos auxiliares:
ENTERO: índice
REAL : Arreglo3, suma
2.4. Procesos
1. Leer el tamaño (N) de los arreglos 1 y 2.
2. Leer los datos de los arreglos 1 y 2.
3. Desde i=1 hasta N, sumaarreglo1[i]+arreglo2[i]
4. Arreglo3[i]  suma
3. Representación de la alternativa de solución en un estándar.
ALGORITMO Arreglos
VARIABLE
REAL Arreglo1[1..N], Arreglo2[1..N], Arreglo3[1..N]
ENTERO índice, mayor_indice, N
REAL suma, mayor
FIN_VARIABLE
INICIO
LEER (N)
DESDE (indice  1, N, INCREMENTO 1)
ESCRIBIR (“Introduce un número para el vector Arreglo1”)
LEER (Arreglo1[indice])
ESCRIBIR (“Introduce un número para el vector Arreglo2”)
LEER (Arreglo2[indice])
Suma  (Arreglo1[indice] + Arreglo2[indice])
Arreglo3[indice]  suma
FIN_DESDE
mayor  Arreglo3[1]
mayor_indice  1
DESDE (indice  1, N, INCREMENTO 1)
SI (Arreglo3[indice] > mayor) ENTONCES
mayor_indice  indice
mayor  Arreglo3[indice]
FIN_SI
FIN_DESDE
ESCRIBIR (mayor)
ESCRIBIR (mayor_indice)
FIN_INICIO
FIN_ALGORITMO
4. Prueba de escritorio.
i
1
2
3
4
5
Arreglo1 Arreglo2 Arreglo3
60
50
40
20
60
60
50
60
30
80
120
100
100
50
140
suma
mayor
mayor_indice
120
100
100
50
140
120
120
120
120
140
1
1
1
1
5
Descargar