Search This Blog

Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Sunday, 19 May 2013

MS Small Basic: overview of stack and matrix (code of Flight Reservation program)

reservavuelos

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:
  1. TextWindow.WriteLine(“Reservas de vuelos”)
  2. TotalAsientos = 10
  3. For i = 1 To TotalAsientos
  4. TextWindow.Write(“Introduzca el nombre del pasajero: “)
  5. nombre[i] = TextWindow.Read()
  6. TextWindow.WriteLine(“El número de asiento ” + i + ” está reservado para ” + nombre[i])
  7. ObtenerDetalles()
  8. EndFor
  9. Sub ObtenerDetalles
  10. If Array.GetItemCount(nombre) = TotalAsientos Then
  11. TextWindow.WriteLine(“¡No hay más asientos disponibles!”)
  12. Else
  13. Array.GetItemCount(nombre)
  14. AsientosDisponibles = TotalAsientos - Array.GetItemCount(nombre)
  15. TextWindow.WriteLine(“Número de asientos disponibles: “+ AsientosDisponibles)
  16. TextWindow.WriteLine(“”)
  17. EndIf
  18. EndSub

Deja un comentario








    Friday, 17 May 2013

    Small Basic: Challenge of the Month – May 2013 (code)

    numeros

    Excellent program!.  Animation and sound
    High level programming Nonki. congratulations
    Program Listing VXK727 -  http://smallbasic.com/program/?VXK727
    ……………………………………………………………………………….
    ‘ 30-second Animation  Edited  ‘Nonki Takahashi
    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    dx = gw / 6
    dy = gh / 3
    fs = 60
    x0 = dx - fs / 2
    y0 = dy - fs
    GraphicsWindow.FontSize = fs
    GraphicsWindow.BrushColor = ”Orange”
    t0 = Clock.ElapsedMilliseconds
    For i = 1 To 10
    obj[i] = Shapes.AddText(i)
    x[i] = x0 + dx * Math.Remainder(i - 1, 5)
    y[i] = y0 + dy * Math.Floor((i - 1) / 5)
    Shapes.Move(obj[i], gw + fs, y[i])
    EndFor
    song1 = ”O4C4C8C8C4C8C8E4G8G8E4C4D4D8D8D4D8D8O3B4O4D8D8O3B4G4″
    song2 = ”O4C4C8C8C4C8C8E4G8G8E4C4G4F4E4D4C1″
    int = 770
    Timer.Interval = int
    f = 0
    Timer.Tick = OnTick
    Sound.PlayMusic(song1)
    Sound.PlayMusic(song2)
    Sound.PlayMusic(song1)
    Sound.PlayMusic(song2)
    Sub OnTick
    t1 = Clock.ElapsedMilliseconds
    f = f + 1
    sec = Math.Floor((t1 - t0) / 1000)
    GraphicsWindow.Title = sec + ”[sec]“
    MoveObj()
    EndSub
    Sub MoveObj
    If f <= 3 Then ‘ 1, 2, 3
    Shapes.Animate(obj[f], x[f], y[f], int)
    ElseIf f = 4 Then
    ElseIf f <= 7 Then ‘ 4, 5, 6
    Shapes.Animate(obj[f - 1], x[f - 1], y[f - 1], int)
    ElseIf f = 8 Then
    ElseIf f <= 11 Then ‘ 7, 8, 9
    Shapes.Animate(obj[f - 2], x[f - 2], y[f - 2], int)
    ElseIf f = 12 Then
    ElseIf f = 13 Then ‘ 10
    Shapes.Animate(obj[f - 3], x[f - 3], y[f - 3], int)
    ElseIf f <= 17 Then
    ElseIf f <= 19 Then ‘ 10, 9
    Shapes.Animate(obj[28 - f], -fs * 2, y[27 - f], int)
    ElseIf f = 20 Then
    ElseIf f <= 23 Then ‘ 8, 7, 6
    Shapes.Animate(obj[29 - f], -fs * 2, y[29 - f], int)
    ElseIf f = 24 Then
    ElseIf f <= 27 Then ‘ 5, 4, 3
    Shapes.Animate(obj[30 - f], -fs * 2, y[30 - f], int)
    ElseIf f = 28 Then
    ElseIf f = 29 Then ‘ 2
    Shapes.Animate(obj[2], -fs * 2, y[2], int)
    ElseIf f <= 37 Then
    ElseIf f = 38 Then ‘ 1
    Shapes.Animate(obj[1], -fs * 2, y[1], int)
    Else
    Timer.Pause()
    GraphicsWindow.BrushColor = ”DimGray”
    GraphicsWindow.DrawText(gw / 2 - fs ,gh / 2 - fs, ”End”)
    EndIf
    EndSub
    ‘ Copyright (c) Microsoft Corporation. All rights reserved.


    http;//www.empiezoinformatica.wordpress.com


    Deja un comentario