Capacitación básica en Computación
Of the Tutorial Small Basic Curriculum (3.2) , we take that :
An array (Array) can be multidimensional, but a stack (Stack object) has only one dimension. You can directly access any element of an array, but can only access the top element of the stack. That is, if you want to access the last element of the stack, you have to go through all the elements from the beginning.
An array is a variable type that can store multiple values at once. If you want to store the names of five users, rather than to create 5 variables, you can use only one variable to store the five names
And remember that in Small Basic the Stack object is used to store data as if it will stack plates. This object follows the principle: first in, first out
Let’s use the Array object, to write a program “Flight Reservation” (excellent example) that executes the following steps:
Reserve seating for 10 passengers.
Display the name of each passenger and seat number
Display the total number of seats available.
code:
- TextWindow.WriteLine(“Reservas de vuelos”)
- TotalAsientos = 10
- For i = 1 To TotalAsientos
- TextWindow.Write(“Introduzca el nombre del pasajero: “)
- nombre[i] = TextWindow.Read()
- TextWindow.WriteLine(“El número de asiento ” + i + ” está reservado para ” + nombre[i])
- ObtenerDetalles()
- EndFor
- Sub ObtenerDetalles
- If Array.GetItemCount(nombre) = TotalAsientos Then
- TextWindow.WriteLine(“¡No hay más asientos disponibles!”)
- Else
- Array.GetItemCount(nombre)
- AsientosDisponibles = TotalAsientos - Array.GetItemCount(nombre)
- TextWindow.WriteLine(“Número de asientos disponibles: “+ AsientosDisponibles)
- TextWindow.WriteLine(“”)
- EndIf
- EndSub
%d bloggers like this:
No comments:
Post a Comment