Class Grade Book
Records three grades per student and builds a class report.
- Level
- Advanced
- Topic:
- Projects
- Concepts:
- Input & output
- Matrices
- Arrays
- Functions
- Para
- Si
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
A matrix stores the grades and an array stores the names. The PromedioAlumno Funcion receives the whole matrix, and the report counts passing students and finds the best average.
Code
Funcion promedio <- PromedioAlumno(notas, alumno) Definir promedio Como Real Definir k Como Entero promedio <- 0 Para k <- 1 Hasta 3 Hacer promedio <- promedio + notas[alumno, k] FinPara promedio <- promedio / 3FinFuncionAlgoritmo GestorNotas Definir nombres Como Caracter Definir notas, mejorPromedio, p Como Real Definir a, k, mejor, aprobados Como Entero Dimension nombres[4], notas[4, 3] Para a <- 1 Hasta 4 Hacer Escribir "Nombre del alumno ", a, ":" Leer nombres[a] Para k <- 1 Hasta 3 Hacer Escribir " Nota ", k, " de ", nombres[a], ":" Leer notas[a, k] FinPara FinPara Escribir "" Escribir "Alumno Promedio Estado" mejor <- 1 mejorPromedio <- -1 aprobados <- 0 Para a <- 1 Hasta 4 Hacer p <- PromedioAlumno(notas, a) Escribir Sin Saltar nombres[a], " ", Redon(p * 10) / 10, " " Si p >= 6 Entonces Escribir "Aprobado" aprobados <- aprobados + 1 SiNo Escribir "Recursa" FinSi Si p > mejorPromedio Entonces mejorPromedio <- p mejor <- a FinSi FinPara Escribir "" Escribir "Aprobaron ", aprobados, " de 4 alumnos." Escribir "Mejor promedio: ", nombres[mejor], " (", Redon(mejorPromedio * 10) / 10, ")"FinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Nombre del alumno 1:User answer: Ana Nota 1 de Ana:User answer: 9 Nota 2 de Ana:User answer: 8 Nota 3 de Ana:User answer: 10Nombre del alumno 2:User answer: Bruno Nota 1 de Bruno:User answer: 5 Nota 2 de Bruno:User answer: 6 Nota 3 de Bruno:User answer: 4Nombre del alumno 3:User answer: Carla Nota 1 de Carla:User answer: 7 Nota 2 de Carla:User answer: 7 Nota 3 de Carla:User answer: 8Nombre del alumno 4:User answer: Diego Nota 1 de Diego:User answer: 6 Nota 2 de Diego:User answer: 5 Nota 3 de Diego:User answer: 7 Alumno Promedio EstadoAna 9 AprobadoBruno 5 RecursaCarla 7.3 AprobadoDiego 6 Aprobado Aprobaron 3 de 4 alumnos.Mejor promedio: Ana (9)
Challenge
Also show the overall class average.
Show hint
Add each p to an accumulator and divide by 4 at the end.
Related examples
Linear vs. Binary Search
Counts the comparisons each search needs on the same sorted list.
IntermediateShell Sort
Insertion sort between far-apart elements, with a gap that shrinks every pass.
AdvancedMerge Sort
Splits the array in halves, sorts each one recursively and merges them.
Advanced