//el siguiente archivo contiene datos acerca de los empleados de una empresa, estos datos son los siguentes //nombre //apellido //sueldo //cantidad de cargas familiares //seguro medico //fonasa o isapre //afp // se pide dise�ar un programa que realice los siguentes procesos //a) un procedimiento que cree los archivos con los datos iniciales( el usuario debe definir cuando no quiera seguir ingresando los datos) // b) un procedimiento que liste todos los datos del archivo // c) un procedimiento que permita a�adir un empleado // d) una funcion que retorne la cantidad de empleados que tienen mas de 3 cargas familiares, imprimir es este dato en el programa principal // e) una funcion que reciba por parametro el apellido de un empleado y retorne su sueldo // f)una funcion que retorne la suma total de todos los sueldos de los empleados // el programa principal debe incluir el menu con las siguentes opciones: // 1 crear archivo // 2 listar empleados // 3 agregar empleados // 4cantidad de cargas // 5 sueldo de empleado // 6total sueldo // ingrese su opcion #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <conio.h> void ingresar(); void listar(); void agregar(); int cantidad(); long suel_emple(char apellido[15]); long sueldos(void); struct empleado { char nomb[10]; char apell[15]; int cargas; long sueldo; char seguro[7]; char afp[20]; }; struct empleado emple; FILE *f; int main() { int opc, cant; long sueldo; char a[15]; do { system("CLS"); printf("\n\n\n MENU PRINCIPAL "); printf("\n ==== ========= \n\n\n"); printf(" 1) crear archivo\n"); printf(" 2) listar empleados\n"); printf(" 3) agregar empleados\n"); printf(" 4) cantidad de cargas\n"); printf(" 5) sueldo de empleado\n"); printf(" 6) total sueldos\n"); printf(" 0) salir\n"); printf("Ingrese su opcion : "); scanf("%d", &opc); switch (opc) { case 1: system("CLS"); ingresar(); break; case 2: system("CLS"); listar(); getchar(); break; case 3: system("CLS"); agregar(); break; case 4: system("CLS"); cant = cantidad(); printf("\n\nLa cantidad de cargas de los empleados es: %d", cant); getchar(); break; case 5: system("CLS"); printf("\n\nIngrese el nombre del empleado que desea buscar: "); fflush(stdin); gets(a); fflush(stdin); sueldo = suel_emple(a); if (sueldo ==0) { printf("\n\nEl empleado no existe"); } else{ printf("\n\nEl sueldo del empleado es: %ld", sueldo); } getchar(); break; case 6: system("CLS"); sueldo = sueldos(); printf("\n\nEl total de los sueldos de los empleados es: %ld", sueldo); getchar(); break; case 0: system("CLS"); printf("\n\n\n\n\nPROGRAMA FINALIZADO......"); getchar(); break; default: printf("Ingrese opcion nuevamente"); getchar(); } }while (opc!=0); } void ingresar() { char resp; char cadena[100]; if((f=fopen("empleados.dat","w"))==NULL) { printf("El archivo no existe"); getchar(); return; } do { printf("\n\n\nIngrese nombre: "); fflush(stdin); fgets(emple.nomb,10,stdin); fflush(stdin); printf("\nIngrese apellido: "); fgets(emple.apell,15,stdin); fflush(stdin); printf("\nIngrese cantidad de cargas familiares: "); scanf("%d",&emple.cargas); printf("\nIngrese sueldo:"); scanf("%ld",&emple.sueldo); printf("\nIngrese seguro medico (Fonasa/Isapre): "); fflush(stdin); fgets(emple.seguro,7,stdin); fflush(stdin); printf("\nIngrese AFP: "); fgets(emple.afp,20,stdin); fflush(stdin); strcpy(cadena,""); printf("%d",sizeof(struct empleado));system("PAUSE"); fwrite(&emple, sizeof(struct empleado),1,f); printf ("\n\n\nDesea continuar (S/N):"); resp = toupper(getchar()); }while(resp != 'N'); fclose(f); } void listar() { if((f=fopen("empleados.dat","r"))==NULL) { printf("El archivo no existe"); getchar(); return; } rewind(f); fread(&emple, sizeof(struct empleado),1,f); printf("%s",emple.nomb); while (!feof(f)) { printf("\n\n\nNombre: %s", emple.nomb); printf("\nApellido: %s", emple.apell); printf("\nCantidad de cargas familiares: %d", emple.cargas); printf("\nSueldo: %ld", emple.sueldo); printf("\nSeguro medico (Fonasa/Isapre): %s", emple.seguro); printf("\nAFP: %s", emple.afp); fread(&emple, sizeof(struct empleado),1,f); } fclose(f); } void agregar() { if((f=fopen("empleados.dat","a"))==NULL) { printf("El archivo no existe"); getchar(); return; } printf("\n\n\nIngrese nombre: "); fflush(stdin); gets(emple.nomb); fflush(stdin); printf("\nIngrese apellido: "); fflush(stdin); gets(emple.apell); fflush(stdin); printf("\nIngrese cantidad de cargas familiares: "); scanf("%d",&emple.cargas); printf("\nIngrese sueldo:"); scanf("%ld",&emple.sueldo); printf("\nIngrese seguro medico (Fonasa/Isapre): "); fflush(stdin); gets(emple.seguro); fflush(stdin); printf("\nIngrese AFP: "); fflush(stdin); gets(emple.afp); fflush(stdin); fwrite(&emple, sizeof(struct empleado),1,f); fclose(f); } int cantidad() { int cont=0; if((f=fopen("empleados.dat","r"))==NULL) { printf("el archivo no existe"); getchar(); return(0); } fread(&emple,sizeof(struct empleado),1,f); while(!feof(f)) { if (emple.cargas>3) cont++; fread(&emple,sizeof(struct empleado),1,f); } fclose(f); return(cont); } long suel_emple(char apellido[15]) { if((f=fopen("empleados.dat","r"))==NULL) { printf("el archivo no existe"); getchar(); return(0); } fread(&emple,sizeof(struct empleado),1,f); while(!feof(f)) { if (strcmp(apellido, emple.apell)==0){ return(emple.sueldo); } fread(&emple,sizeof(struct empleado),1,f); } fclose(f); return(0); } long sueldos(void) { long total=0; if((f=fopen("empleados.dat","r"))==NULL) { printf("el archivo no existe"); getchar(); return(0); } fread(&emple,sizeof(struct empleado),1,f); while(!feof(f)) { total=total+emple.sueldo; fread(&emple,sizeof(struct empleado),1,f); } fclose(f); return(total); }
Arrays Code
códigos fuentes de diferentes lenguajes...
viernes, 13 de abril de 2012
Trabajas con archivo de datos - C++
Gato Java - programacion estructurada
package gato;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Gato {
public static int matriz[][] = new int [3][3];
public static BufferedReader br =new BufferedReader (new InputStreamReader (System.in));
public static void main(String[] args) throws IOException {
int turno=1;
int respuesta=0;
for(int i=0;i<3;i++){
for(int b=0;b<3;b++){
matriz[i][b]=0;
System.out.print(matriz[i][b]);
}
System.out.println("");
}
System.out.println("-. Juego del Gato .-");
//inicio del videoJuego Gato ...
do{
turno=turno+1;
if(turno%2==0){
llenarMatrizP1();
}else{
llenarMatrizP2();
}
mostrarMatriz();
respuesta=verificarMatriz(respuesta);
}while(respuesta==0);
}
private static void mostrarMatriz() {
for(int i=0;i<3;i++){
for(int b=0;b<3;b++){
System.out.print(matriz[i][b]);
}
System.out.println("");
}
}
private static int verificarMatriz(int respuesta) {
int jugadorG=0;
/* horizontal primera fila
*
* 111
* 000
* 000
*
*
*/
if(matriz[0][0]==1 && matriz[1][0]==1 && matriz[2][0]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[0][0]==2 && matriz[1][0]==2 && matriz[2][0]==2 ){
jugadorG=2;
respuesta=1;
}
/* horizontal segunda fila
*
* 000
* 111
* 000
*
*
*/
if(matriz[0][1]==1 && matriz[1][1]==1 && matriz[2][1]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[0][1]==2 && matriz[1][1]==2 && matriz[2][1]==2 ){
jugadorG=2;
respuesta=1;
}
/* horizontal tercera fila
*
* 000
* 000
* 111
*
*
*/
if(matriz[0][2]==1 && matriz[1][2]==1 && matriz[2][2]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[0][2]==2 && matriz[1][2]==2 && matriz[2][2]==2 ){
jugadorG=2;
respuesta=1;
}
/* vertical primera columna
*
* 100
* 100
* 100
*
*
*/
if(matriz[0][0]==1 && matriz[0][1]==1 && matriz[0][2]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[0][0]==2 && matriz[0][1]==2 && matriz[0][2]==2 ){
jugadorG=2;
respuesta=1;
}
/* vertical segunda columna
*
* 010
* 010
* 010
*
*
*/
if(matriz[1][0]==1 && matriz[1][1]==1 && matriz[1][2]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[1][0]==2 && matriz[1][1]==2 && matriz[1][2]==2 ){
jugadorG=2;
respuesta=1;
}
/* vertical tercera columna
*
* 001
* 001
* 001
*
*
*/
if(matriz[2][0]==1 && matriz[2][1]==1 && matriz[2][2]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[2][0]==2 && matriz[2][1]==2 && matriz[2][2]==2 ){
jugadorG=2;
respuesta=1;
}
/* digagonal 1
*
* 100
* 010
* 001
*
*
*/
if(matriz[0][0]==1 && matriz[1][1]==1 && matriz[2][2]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[0][0]==2 && matriz[1][1]==2 && matriz[2][2]==2 ){
jugadorG=2;
respuesta=1;
}
/* digagonal 2
*
* 001
* 010
* 100
*
*
*/
if(matriz[0][2]==1 && matriz[1][1]==1 && matriz[2][0]==1 ){
jugadorG=1;
respuesta=1;
}
if(matriz[0][2]==2 && matriz[1][1]==2 && matriz[2][0]==2 ){
jugadorG=2;
respuesta=1;
}
if(respuesta==1 && jugadorG==1){
System.out.println("El ganador a sido el Primer player felicitaciones !!!");
}
if(respuesta==1 && jugadorG==2){
System.out.println("El ganador a sido el Segundo player felicitaciones !!!");
}
return respuesta;
}
private static void llenarMatrizP1() throws IOException {
int col;
int fil;
int apru=0;
//agregar un do while
do{
System.out.println("Turno del primer Player: ");
System.out.println("Eliga la columna:");
col = Integer.parseInt(br.readLine());
System.out.println("Eliga la fila: ");
fil = Integer.parseInt(br.readLine());
for(int i=0;i<3;i++){
for(int b=0;b<3;b++){
if(matriz[col-1][fil-1]==0){
matriz[col-1][fil-1]=1;
apru=1;
}
}
}
if(apru==0){
System.out.println("La casilla ya esta usada, vuela a intentar");
}
}while(apru==0);
}
private static void llenarMatrizP2() throws IOException {
int col;
int fil;
int apru=0;
//agregar un do while
do{
System.out.println("Turno del segundo Player: ");
System.out.println("Eliga la columna:");
col = Integer.parseInt(br.readLine());
System.out.println("Eliga la fila: ");
fil = Integer.parseInt(br.readLine());
for(int i=0;i<3;i++){
for(int b=0;b<3;b++){
if(matriz[col-1][fil-1]==0){
matriz[col-1][fil-1]=2;
apru=1;
}
}
}
if(apru==0){
System.out.println("La casilla ya esta usada, vuela a intentar");
}
}while(apru==0);
}
}
jueves, 27 de octubre de 2011
BoletaSupermercado - Objetos intermediarios
Clase principal
1 package boletaventa213; 2 3 import java.io.BufferedReader; 4 import java.io.InputStreamReader; 5 import java.io.IOException; 6 import java.util.ArrayList; 7 8 public class BoletaVenta213 9 { 10 public static ArrayList<detalleBoleta> detabol = new ArrayList(); 11 public static void main(String[] args) throws IOException 12 { 13 String producto; 14 int codigo; 15 int precio; 16 int cantidad; 17 String op; 18 boletas bole = new boletas(1,"21-12-2011"); 19 20 BufferedReader tex = new BufferedReader(new InputStreamReader(System.in)); 21 System.out.println("-.SUPERMERCADOS LA TIJUANA.-"); 22 23 do{ 24 System.out.print("Ingrese código del producto: "); 25 codigo=Integer.parseInt(tex.readLine()); 26 27 System.out.print("Ingrese nombre del producto: "); 28 producto=tex.readLine(); 29 30 System.out.print("Ingrese precio del producto: "); 31 precio=Integer.parseInt(tex.readLine()); 32 System.out.print("Ingrese cantidad del producto: "); 33 cantidad=Integer.parseInt(tex.readLine()); 34 System.out.println(""); 35 36 System.out.print("desea agregar mas productos? s/n : "); 37 op=tex.readLine(); 38 System.out.println(""); 39 subAgregaProducto(codigo,producto,precio, bole, cantidad); 40 41 42 }while(op.equals("s")); 43 44 45 int i; 46 47 48 System.out.println("DETALLE DE LA BOLETA : "); 49 50 System.out.println(detabol.get(0).getBoleta().numero); 51 System.out.println(detabol.get(0).getBoleta().fecha); 52 System.out.println("Código Nombre PrecioUnitario Cantidad Precio "); 53 for (i=0;i<detabol.size();i++) 54 { 55 56 System.out.print(detabol.get(i).getProducto().codigo+" "); 57 System.out.print(" "); 58 System.out.print(detabol.get(i).getProducto().Nombre+" "); 59 System.out.print(" "); 60 System.out.print(detabol.get(i).getProducto().precioUnitario+" "); 61 System.out.print(" "); 62 System.out.print(detabol.get(i).cantidad+" "); 63 System.out.print(" "); 64 System.out.print(detabol.get(i).getProducto().precioUnitario* 65 detabol.get(i).cantidad); 66 System.out.println(""); 67 } 68 } 69 70 public static void subAgregaProducto(int codigo, String nombre, 71 int precio,boletas bole, 72 int cantidad) 73 { 74 productos prod = new productos(codigo,nombre,precio); 75 detabol.add(new detalleBoleta(bole, prod, cantidad)); 76 77 } 78 }
viernes, 21 de octubre de 2011
Presupuesto - Python
1 # -*- coding: utf-8 -*- 2 class ModeloDePresupuesto: 3 # Datos comerciales 4 titulo = "PRESUPUESTO" 5 encabezado_nombre = "Eugenia Bahit" 6 encabezado_web = "www.eugeniabahit.com.ar" 7 encabezado_email = "mail@mail.com" 8 9 # Datos impositivos 10 alicuota_iva = 21 11 12 # Propiedades relativas al formato 13 divline = "="*80 14 15 # Setear los datos del cliente 16 def set_cliente(self): 17 self.empresa = raw_input('\tEmpresa: ') 18 self.cliente = raw_input('\tNombre del cliente: ') 19 20 # Setear los datos básicos del presupuesto 21 def set_datos_basicos(self): 22 self.fecha = raw_input('\tFecha: ') 23 self.servicio = raw_input('\tDescripción del servicio: ') 24 importe = raw_input('\tImporte bruto: $') 25 self.importe = float(importe) 26 self.vencimiento = raw_input('\tFecha de caducidad: ') 27 28 # Calcular IVA 29 def calcular_iva(self): 30 self.monto_iva = self.importe*self.alicuota_iva/100 31 32 # Calcula el monto total del presupuesto 33 def calcular_neto(self): 34 self.neto = self.importe+self.monto_iva 35 36 # Armar el presupuesto 37 def armar_presupuesto(self): 38 """ 39 Esta función se encarga de armar todo el presupuesto 40 """ 41 txt = '\n'+self.divline+'\n' 42 txt += '\t'+self.encabezado_nombre+'\n' 43 txt += '\tWeb Site: '+self.encabezado_web+' | ' 44 txt += 'E-mail: '+self.encabezado_email+'\n' 45 txt += self.divline+'\n' 46 txt += '\t'+self.titulo+'\n' 47 txt += self.divline+'\n\n' 48 txt += '\tFecha: '+self.fecha+'\n' 49 txt += '\tEmpresa: '+self.empresa+'\n' 50 txt += '\tCliente: '+self.cliente+'\n' 51 txt += self.divline+'\n\n' 52 txt += '\tDetalle del servicio:\n' 53 txt += '\t'+self.servicio+'\n\n' 54 txt += '\tImporte: $%0.2f | IVA: $%0.2f\n' % ( 55 self.importe, self.monto_iva) 56 txt += '-'*80 57 txt += '\n\tMONTO TOTAL: $%0.2f\n' % (self.neto) 58 txt += self.divline+'\n' 59 print txt 60 61 # Método constructor 62 def __init__(self): 63 print self.divline 64 print "\tGENERACIÓN DEL PRESUPUESTO" 65 print self.divline 66 self.set_cliente() 67 self.set_datos_basicos() 68 self.calcular_iva() 69 self.calcular_neto() 70 self.armar_presupuesto() 71 72 # Instanciar clase 73 presupuesto = ModeloDePresupuesto()
Suscribirse a:
Entradas (Atom)