martes, 12 de abril de 2016

Algoritmo de Busqueda Secuencial - Linear search- en Lenguaje de Programacion Ruby







def login()
   system('cls')

    puts "Ingrese clave para Iniciar el Sistema TicketMaster Version 1.2 2016"
    puts
    clave = gets.to_i
    puts
    if (clave == 12345 )   # la clave es un numero int                                                              
        puts "Clave Correcta"
        menuInicial()
     
    else login()

    end

 
end

def menuInicial ()
   system('cls')
   puts
   puts
   puts "  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
   puts "  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
   puts "  $$$$$!-------------------------------------------------------------------- !$$$$$$"
   puts "  $$$$$!          SISTEMA TICKETMASTER SAC.                       !$$$$$$"
   puts "  $$$$$!                                                                                            !$$$$$$"
   puts "  $$$$$!      TU ENTRADA AL MUNDO DEL ESPECTACULO!$$$$$$"
   puts "  $$$$$!---------------------------------------------------------------------!$$$$$$"
   puts "  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
   puts "  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
 
   puts
   fechaHora()
 
 
 
   puts  "1) Buscar Evento por Fecha  "
   puts


   puts  "2) Buscar Evento por Precio"
   puts

   puts  "3) Salir   "
   puts
   puts


   opcionMenuInicial = gets.to_i

   puts

        case opcionMenuInicial

        when  1  then  SubRutinaBusquedaporFecha()


        when  2  then SubRutinaBusquedaporPrecio()

        when  3  then SubRutinaFinalizar()    
 
        #else menuInicial()
     

        end

 
end


def SubRutinaBusquedaporFecha()
   #system('cls')

   puts "Sistema de Venta de Boletos  TicketMaster SAC. "
   puts
   puts
   fechaHora()
   puts
 
 
   puts "Introducir fecha a buscar XX-04-2016"
 
   puts
   puts
   puts
   puts
   puts "Introducir el dia : "
   $fecha = gets.to_i

   buscarPorFecha($a, $fecha)
   puts

   

 end


def SubRutinaBusquedaporPrecio()


puts "Busqueda por Precio"
puts "Sistema de Venta de Boletos  TicketMaster SAC. "
   puts
   puts
   fechaHora()
   puts
 
 
   puts "Introducir Precio a buscar"
   puts
   puts "Introducir el precio : "
   $precio = gets.to_i

   buscarPorPrecio($a2, $precio)
   puts



end

def buscarPorPrecio(arreglo, precio)
system('cls')
puts "Busqueda por Precio"
puts
puts "Sistema de Venta de Boletos  TicketMaster SAC. "
puts
fechaHora()
puts

ind = -1
indmaximo = arreglo.size-1
i = 0

while(  i <indmaximo and precio != arreglo[i]     )
i = i + 1

end

if ( precio == arreglo[i] )

ind = i

end

if( (ind + 1) == 0  ) then

puts "No hay ningun evento con ese precio : " + precio.to_s  + " Soles. "

else

puts "Con ese precio tenemos los siguientes eventos : " + precio.to_s + " Soles. "

case precio

        when  100  then  puts "Concierto Pantera "
when  250  then  puts "Maraton Blue Race 5K"
when  300  then  puts "Opera Temporada 2016 "
when  500  then  puts "Concierto de Gala de Filarmonia"
when  666 then  puts "Concierto Metallica"
when  700  then  puts "Concierto Ed Sheeran Live 1 Año Despues"
when  850 then  puts "Exibicion Monster Trucks "
        when  900  then  puts "Evento Dev Days  Microsoft"
when  990  then  puts "Concierto Velvet Revolver"
when  1000  then  puts "Concierto Rolling Stones"
     
 
        #else menuInicial()
else menuInicial()
     

        end


end

ind + 1

system('pause')
menuInicial()
end

def SubRutinaFinalizar()
system('cls')
puts "Gracias por Usar el Sistema de TicketMaster 2016  v 1.2 - www.ticketmaster.com"


end


def buscarPorFecha(arreglo, dia)
system('cls')
puts "Busqueda por Fecha "
puts
puts "Sistema de Venta de Boletos  TicketMaster SAC. "
puts
fechaHora()
puts

ind = -1
indmaximo = arreglo.size-1
i = 0

while(  i <indmaximo and dia != arreglo[i]     )
i = i + 1

end

if ( dia == arreglo[i] )

ind = i

end

if( (ind + 1) == 0  ) then

puts "El dia : " + dia.to_s   + " no hay ningun evento"

else

puts "El dia : " + dia.to_s   + " se realizara el evento de : "

case dia

        when  1  then  puts "Concierto Rolling Stones"
when  2  then  puts "Concierto Metallica"
when  3  then  puts "Opera Temporada 2016 "
when  7  then  puts "Concierto de Gala de Filarmonia"
when  14  then  puts "Concierto Ed Sheeran Live 1 Año Despues"
when  20 then  puts "Exibicion Monster Trucks"
        when  27  then  puts "Maraton Blue Race 5K"
when  28  then  puts "Evento Dev Days Microsoft"
when  29  then  puts "Concierto Velvet Revolver"
when  30  then  puts "Concierto Pantera"
     
 
        #else menuInicial()
else menuInicial()
     

        end

end

 ind + 1

system('pause')
menuInicial()
end


def fechaHora()


puts   Time.now.strftime("%H:%M") + " - " +  Time.now.strftime("%d/%m/%Y")

puts
puts

end

#dias que hay eventos
$a = [1,2,3,7,14,20,27,28,29,30]

#precios de entradas
$a2 = [ 100,250,300,500,666, 700,850,900,950,990,1000 ]



login()
menuInicial()