Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Inicio menu()
Variables nom[50],ed[50],sex[50],N=0,opc Variables opc
opc = menu( ) Escribir: “Menu“
opc Escribir:”[1]Ingresar”
1 2 3 4 Escribir:”[2]Reportar”
consultar(nom,ed,sex,N)
Escribir:”[3]Consultar”
reportar(nom,ed,sex,N)
ingresar(nom,ed,sex,N)
Escribir:”[4]Terminar”
Escribir:”Escoger opción[1-4]”
N=leenum()
terminar( )
Leer opc
opc <1 V opc>4
retornar opc
opc ≠ 4
Fin
Leer ed[i]
reportar(nom[ ], ed[ ], sex[ ], N) ed[i] ≤ 0
Variables i
Leer sex[i]
I=0; i<N ; i = I +1
Escribir: nom[i], ed[i], sex[ i ] sex[i] ≠ ‘M’ Λ sex[i] ≠ ‘F’
retornar retornar
1
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
pos = i
i=N
V pos=-1 F
Escribir: “Dato no Escribir: nom[pos]
Existe” ed[pos], sex[pos]
retornar
Código en java
import java.io.*;
public class ejem1
{ static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
2
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
static void ingresar(String nom[], int ed[], char sex[], int N) throws IOException
{int i;
String cad;
System.out.println("\nIngreso de datos\n");
for(i=0; i<N; i++)
{System.out.println("Nombre["+i+"] :");
nom[i]=br.readLine();
nom[i]=nom[i].toUpperCase();
do{System.out.println("Edad["+i+"] :");
ed[i]=Integer.parseInt(br.readLine());
}
while(ed[i]<=0) ;
do{System.out.println("Sexo["+i+"] :");
cad=br.readLine();
cad=cad.toUpperCase();
sex[i]=cad.charAt(0);
}
while(sex[i]!='M' &&sex[i]!='F') ;
}
return;
}
3
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
static void reportar(String nom[], int ed[], char sex[], int N) throws IOException
{int i;
System.out.println("\nReporte de datos\n");
for(i=0; i<N; i++)
{System.out.println("\t"+ nom[i]+"\t"+ ed[i]+"\t"+sex[i]);
}
return;
}
static void consultar(String nom[], int ed[], char sex[], int N) throws IOException
{ int i, pos = -1;
String nomaux;
System.out.println("\nConsulta de datos\n");
System.out.println("\nIngrese nombre a buscar : ");
nomaux=br.readLine();
nomaux=nomaux.toUpperCase();
for(i=0; i<N; i++)
{ if(nom[i].compareTo(nomaux)==0)
{ pos =i;
break;
}
}
if(pos == -1)
{System.out.println("\nDato buscado no existe\n");
}
else
{System.out.println("\nDato encontrado\n");
System.out.println("\t"+ nom[pos]+"\t"+ed[pos]+"\t"+sex[pos]);
}
return;
}
4
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
2.- Escribir un programa que presente un menú en el que se permita seleccionar alguna
de las siguientes tareas a realizar:
1.-Ingresar datos (nombre de producto : de tipo String , precio de producto : de tipo
real y tipo de producto : de tipo char) de N productos.
El tipo de producto puede ser: ‘N’=Nacional o ‘I’=Importado.
2.-Reportar todos los datos
3.-Agregar datos
4.-Modificar datos
5.-Terminar
El programa se debe ejecutar mientras no se escoge la opción terminar.
Inicio menu()
Variables nom[50],pre[50], tip[50], N=0, opc Variables opc
opc = menu( ) Escribir: “Menu“
opc Escribir:”[1] Ingresar”
1 2 3 4 5 Escribir:”[2] Reportar”
modificar(nom,pre,tip,N)
Escribir:”[3] Agregar”
reportar(nom,pre,tip,N)
ingresar(nom,pre,tip,N)
agregar(nom,pre,tip,N)
Escribir:”[4] Modificar”
Escribir:”[5] Terminar”
N = lenum()
Escribir:”Escoger opción[1-5]”
terminar( )
Leer opc
opc <1 V opc>5
opc ≠ 5 retornar opc
Fin
leenum( )
ingresar (nom[ ], pre[ ], tip[ ], N)
Variables N
Variables i
Leer N
N ≤ 0 V N > 50 i=0; i<N ; i = i +1
retornar N Leer nom[i]
Leer pre[i]
retornar retornar
5
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
retornar retornar
Código en java
import java.io.*;
public class ejem2
{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String [] args) throws IOException
{ String nom[ ] = new String[50];
double pre [ ] = new double[50];
char tip [ ] = new char[50];
int N=0 , opc;
do { opc= menu ( );
switch( opc )
{ case 1 : N=leenum();
ingresar(nom,pre,tip,N);
break;
case 2 : reportar(nom,pre,tip,N);
break;
case 3 : N=agregar(nom,pre,tip,N);
break;
case 4 : modificar(nom,pre,tip,N);
break;
case 5 : terminar();
break;
}
}while(opc!=5);
} // llave fin de main
6
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
static void ingresar(String nom[], double pre[], char tip[], int N) throws IOException
{int i;
String cad;
System.out.println("\nIngreso de datos\n");
for(i=0; i<N; i++)
{System.out.print("Nombre["+i+"] :");
nom[i]=br.readLine();
nom[i]=nom[i].toUpperCase();
do{System.out.print("Precio["+i+"] :");
pre[i]=Double.parseDouble(br.readLine());
}
while(pre[i]<=0) ;
do{System.out.print("Tipo["+i+"] :");
cad=br.readLine();
cad=cad.toUpperCase();
tip[i]=cad.charAt(0);
}
while(tip[i]!='N' && tip[i]!='I') ;
}
return;
}
7
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
static void reportar(String nom[], double pre[], char tip[], int N) throws IOException
{int i;
System.out.println("\nReporte de datos\n");
for(i=0; i<N; i++)
{System.out.println("\t"+ nom[i]+"\t"+ pre[i]+"\t"+tip[i]);
}
return;
}
static int agregar(String nom[], double pre[], char tip[], int N) throws IOException
{ String cad;
System.out.println("\nAgregar datos\n");
if(N<50)
{ System.out.print("Nuevo Nombre["+N+"] :");
nom[N]=br.readLine();
nom[N]=nom[N].toUpperCase();
do{ System.out.print("Nuevo Precio["+N+"] :");
pre[N]=Double.parseDouble(br.readLine());
}
while(pre[N]<=0) ;
do{System.out.print("Nuevo Tipo["+N+"] :");
cad=br.readLine();
cad=cad.toUpperCase();
tip[N]=cad.charAt(0);
}
while(tip[N]!='N' && tip[N]!='I') ;
N++;
System.out.println("Los datos han sido agregados…!");
}
else{System.out.println("\nArreglo lleno....!");
}
return N;
}
static void modificar(String nom[], double pre[], char tip[], int N) throws IOException
{ int i, pos = -1;
String nomaux , cad;
System.out.println("\nModificación de datos\n");
System.out.println("\nIngrese nombre a buscar : ");
nomaux=br.readLine();
nomaux=nomaux.toUpperCase();
for(i=0; i<N; i++)
{ if (nom[i].compareTo(nomaux)==0)
{ pos =i;
break;
}
}
8
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
if(pos== -1)
{System.out.println("\nDato buscado no existe\n");
}
else
{ System.out.println("\nDatos Actuales encontrados\n");
System.out.println("\t"+ nom[pos]+"\t"+pre[pos]+"\t"+tip[pos]);
System.out.print("Nuevo Nombre["+pos+"] :");
nom[pos]=br.readLine();
nom[pos]=nom[pos].toUpperCase();
do{ System.out.print("Nuevo Precio["+pos+"] :");
pre[pos]=Double.parseDouble(br.readLine());
}
while(pre[pos]<=0) ;
do{ System.out.print("Nuevo Tipo["+pos+"] :");
cad=br.readLine();
cad=cad.toUpperCase();
tip[pos]=cad.charAt(0);
}
while(tip[pos]!='N' && tip[pos]!='I') ;
}
return;
}
9
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
3.- Escribir un programa que presente un menú en el que se permita seleccionar alguna
de las siguientes tareas a realizar:
a.-Ingresar datos (nombre de producto : de tipo String , precio de producto : de tipo
real y tipo de producto : de tipo char) de N productos.
El tipo de producto puede ser: ‘N’=Nacional o ‘I’=Importado.
b.-Reportar todos los datos
c.-Eliminar datos
d.-Ordenar datos alfabéticamente
e.-Insertar datos en la lista ordenada
f.-Terminar
El programa se debe ejecutar mientras no se escoge la opción terminar.
Inicio menu()
Variables nom[50],pre[50], tip[50], N=0, opc Variables opc
opc = menu( ) Escribir: “Menu“
opc Escribir:”[A] Ingresar”
A B C D E F Escribir:”[B] Reportar”
Escribir:”[C] Eliminar”
reportar(nom,p re, tip, N)
Escribir:”[D] Ordenar”
Escribir:”[E] Insertar”
Escribir:”[F] Terminar”
N=leenum()
terminar( )
Escribir:”Escoger opción[A-F]”
Leer opc
opc ≠ ‘F’ opc <’A’ V opc >´F´
Fin retornar opc
Leer pre[i]
retornar
retornar 10
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
eliminar (nom[ ], pre[ ], tip[ ], N) insertar(nom[ ], pre[ ], tip[ ], N)
variables i, nomaux, pos = -1 variables i, nomaux, pos = -1
Leer nomaux Leer nomaux
i=0; i<N ; i = i +1 i=0; i<N ; i = i +1
V nom[i] = nomaux F V nom[i] > nomaux F
pos = i pos = i
i=N i=N
V pos=-1 F V pos = -1 F
Escribir: nom[pos] = nom[N-1] pos = N
“Dato No Existe” pre[pos] = pre[N-1] i = N ; i > pos ; i = i – 1
tip[pos] = tip[N-1] nom[i] = nom[i-1]
N=N-1 pre[i] = pre[i-1]
retornar N tip [i] = tip[i-1]
nom[pos] = nomaux
Leer pre[pos]
ordenar (nom[ ], pre[ ], tip[ ], N)
pre[pos] ≤ 0
variables i, j, nomaux, preaux, tipaux
i=0; i<N ; i = i +1 Leer tip[pos]
j= i +1; j<N; j=j+1 tip[pos] ≠ ‘N’ Λ tip[pos] ≠ ‘I’
V nom[i] > nom[j] F N = N +1
nomaux=nom[j]; retornar N
nom[j] =nom[i];
nom[i] =nomaux;
preaux =pre[j];
pre[j] =pre[i]; terminar( )
pre[i] =preaux;
Variables
tipaux =tip[j];
Escribir: “Fin del programa”
tip[j] =tip[i];
tip[i] =tipaux; retornar
retornar
11
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
Código en java
import java.io.*;
import java.io.*;
public class ejem3
public class ejem3
{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String [] args) throws IOException
{ String nom[ ] = new String[50];
double pre [ ] = new double[50];
char tip [ ] = new char[50];
int N=0 ;
char opc;
do { opc= menu ( );
switch( opc )
{ case 'A' : N=leenum();
ingresar(nom,pre,tip,N);
break;
case 'B' : reportar(nom,pre,tip,N);
break;
case 'C' : N=eliminar(nom,pre,tip,N);
break;
case 'D' : ordenar(nom,pre,tip,N);
break;
case 'E' : N = insertar(nom,pre,tip,N);
break;
case 'F' : terminar();
break;
}
}
while(opc!='F');
} // llave fin de main
static void ingresar(String nom[], double pre[], char tip[], int N) throws IOException
{int i;
String cad;
System.out.println("\nIngreso de datos\n");
for(i=0; i<N; i++)
{System.out.print("Nombre["+i+"] :");
nom[i]=br.readLine();
nom[i]=nom[i].toUpperCase();
do{System.out.print("Precio["+i+"] :");
pre[i]=Double.parseDouble(br.readLine());
}
while(pre[i]<=0) ;
do{System.out.print("Tipo["+i+"] :");
cad=br.readLine();
cad=cad.toUpperCase();
tip[i]=cad.charAt(0);
}
while(tip[i]!='N' && tip[i]!='I') ;
}
return;
}
static void reportar(String nom[], double pre[], char tip[], int N) throws IOException
{int i;
System.out.println("\nReporte de datos\n");
for(i=0; i<N; i++)
{System.out.println("\t"+ nom[i]+"\t"+ pre[i]+"\t"+tip[i]);
}
return;
}
static int eliminar(String nom[], double pre[], char tip[], int N) throws IOException
{ int i, pos = -1;
String nomaux;
System.out.println("\nEliminacion de datos\n");
System.out.println("\nIngrese nombre a eliminar : ");
nomaux=br.readLine();
nomaux=nomaux.toUpperCase();
13
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
return ;
14
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
static int insertar(String nom[], double pre[], char tip[], int N) throws IOException
{ int i, j, pos = -1;
String nomaux , cad;
ordenar(nom,pre,tip,N); // por si los datos están desordenados, se ordenan
System.out.println("\nInsercion de datos \n");
System.out.println("\nIngrese nombre a insertar: ");
nomaux=br.readLine();
nomaux=nomaux.toUpperCase();
/***primero se busca el lugar donde se insertara el dato*/
for(i=0; i<N; i++)
{ if(nom[i].compareTo(nomaux)>0)
{ pos =i;
break;
}
}
if(pos== -1) // si se tiene que colocar en la última posición
{pos=N;
}
/*se desplazan todos los datos una posición hacia abajo, para insertar el dato*/
for(i=N; i>pos; i--)
{ nom[i] = nom[i-1];
pre[i] = pre[i-1];
tip[i] = tip[i-1];
}
/*se procede a insertar el dato */
nom[pos]= nomaux;
do{ System.out.print("Nuevo Precio["+pos+"] :");
pre[pos]=Double.parseDouble(br.readLine());
}
while(pre[pos]<=0) ;
do{ System.out.print("Nuevo Tipo["+pos+"] :");
cad=br.readLine();
cad=cad.toUpperCase();
tip[pos]=cad.charAt(0);
}
while( tip[pos]!='N' && tip[pos]!='I' ) ;
System.out.print("Los datos han sido insertados");
N++;
return N;
}
static void terminar() throws IOException
{System.out.println("\nFin del programa\n");
return;
}
} // llave fin de la clase
15
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
4.-Escribir un programa que presente un menú que permita ejecutar alguna de las
siguientes opciones.
1.-Ingresar datos (se ejecuta una sola vez)
2.-Reportar datos (se ejecuta sólo si hay datos)
3.-Consultar Datos (se ejecuta sólo si hay datos)
4.-Eliminar Datos (se ejecuta sólo si hay datos)
5.-Terminar (siempre que se desee)
El programa se debe ejecutar mientras no se escoja la opción 5 (terminar).
Los datos a ingresar son: nombre (String), autor (String) y código (int de 4 dígitos) de
N libros.
Inicio
Variables nom[50],aut[50], cod[50], N=0, opc
opc = menu( )
opc
1 2 3 4 5
N=0 N>0 N>0 N>0
V F V F V F V F
reportar(nom, aut, cod,N)
consultar(nom,aut,cod,N)
eliminar(nom,aut,cod,N)
ingresar(nom,aut,cod,N)
termina( )
datos”
datos”
datos”
datos”
opc ≠ 5
Fin
menu()
Variables opc
Escribir: “Menu“
Escribir:”[1] Ingresar”
Escribir:”[2] Reportar”
Escribir:”[3] Consultar”
leenum( )
Escribir:”[4] Eliminar”
Variables N
Escribir:”[5] Terminar”
Leer N
Escribir:”Escoger opción[1-5]”
N ≤ 0 V N > 50
Leer opc
retornar N
opc < 1 V opc > 5
retornar opc
16
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
Variables i Variables i
Leer aut[i]
Leer cod[i] retornar
terminar( )
Variables
retornar
17
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
Código en java
import java.io.*;
public class ejem4
{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static void consultar(String nom[], String aut[], int cod[], int N) throws IOException
{ int i, pos = -1;
String nomaux;
System.out.println("\nConsulta de datos\n");
System.out.print("\nIngrese nombre a buscar : ");
nomaux=br.readLine();
nomaux=nomaux.toUpperCase();
19
UNIVERSIDAD PRIVADA ANTENOR ORREGO WALTER LAZO AGUIRRE
INGENIERÍA DE COMPUTACIÓN Y SISTEMAS ARREGLOS-MÉTODOS
INTRODUCCIÓN A LA PROGRAMACIÓN MENÚ
static int eliminar(String nom[], String aut[], int cod[], int N) throws IOException
{ int i, pos = -1;
String nomaux;
System.out.println("\nEliminacion de datos\n");
System.out.print("\nIngrese nombre a eliminar : ");
nomaux=br.readLine();
nomaux=nomaux.toUpperCase();
for(i=0; i<N; i++)
{ if(nom[i].compareTo(nomaux)==0)
{ pos =i;
break;
}
}
if(pos== -1)
{System.out.println("\nDato buscado no existe\n");
}
else
{ System.out.println("\nDatos Actuales encontrados\n");
System.out.println("\t"+ nom[pos]+"\t"+aut[pos]+"\t"+cod[pos]);
nom[pos]=nom[N-1];
aut[pos]=aut[N-1];
cod[pos]=cod[N-1];
System.out.println("Los datos han sido borrados....!");
N=N -1;
}
return N;
}