elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


  Mostrar Mensajes
Páginas: [1] 2
1  Programación / Scripting / Ayuda imprimir en diferentes partes de la consola python en: 11 Marzo 2021, 21:27 pm
Ayuda necesito imprimir en consola en diferentes partes de la consola.En la parte izquierda se tiene que mostrar los procesos a ejecutar, en la parte de enmedio tienen que aparecer los procesos en ejecucion y en la parte derecha tiene que aparecer los procesos terminados.
Código
  1. import os
  2. global Id
  3. global aux
  4. global listap
  5. global ids
  6. global proceso
  7. ids=list()
  8.  
  9. listap=list()
  10.  
  11.  
  12. class procesos:
  13.    nombre=""
  14.    idp=0
  15.    signo=""
  16.    ope1=0
  17.    ope2=0
  18.    tiempom=0
  19.  
  20. def cantidadp ():
  21.    p=0
  22.    a=0
  23.    b=False
  24.    p=int(input("cuantos procesos vas a registrar--> "))
  25.    while a<p:
  26.        os.system("cls")
  27.        proceso=procesos()
  28.        proceso.nombre=nombrep()
  29.        proceso.idp=idp()
  30.        proceso.signo=signov()
  31.        proceso.ope1=int(input("Ingrese primer operando--> "))
  32.        if(proceso.signo=="/"):
  33.            while b!=True:
  34.                print("Para division y residuo el segundo opeando debe ser mayor a 0")
  35.                op2=int(input("ingrese segundo operando--> "))
  36.                if(op2>0):
  37.                    proceso.ope2=op2
  38.                    b=True
  39.                else:
  40.                    print("ingrese otro operando")
  41.        else:
  42.            proceso.ope2=int(input("Ingrese segundo operando--> "))
  43.        b=False
  44.        while b!=True:
  45.            tiempo=int(input("Ingrese el tiempo maximo--> "))
  46.            if(tiempo>0):
  47.                print("tiempo valido")
  48.                proceso.tiempom=tiempo
  49.                b=True
  50.            else:
  51.                print("tiempo invalido ingrese un tiempo mayor a 0")
  52.        listap.append(proceso)
  53.  
  54.        a+=1
  55.  
  56.  
  57. def signov():
  58.    print("operacion a hacer? teclee el signo \n suma + \n resta - \n division / \n residuo % \n multiplicacion * " )
  59.    b=False
  60.    while b!=True:
  61.        s=input("Ingrese la operacion--> ")
  62.        if(s=="+"):
  63.            print("signo valido")
  64.            return s
  65.            b=True
  66.        elif(s=="-"):
  67.            print("signo valido")
  68.            return s
  69.            b=True
  70.        elif(s=="/"):
  71.            print("signo valido")
  72.            return s
  73.            b=True
  74.        elif(s=="%"):
  75.            print("signo valido")
  76.            return s
  77.            b=True
  78.        elif(s=="*"):
  79.            print("signo valido")
  80.            return s
  81.            b=True
  82.        else:
  83.            print("signo invalido,vuelva a escribirlo")
  84.  
  85.  
  86.  
  87. def nombrep():
  88.    b=False
  89.    while b!=True:
  90.        nombre=input("ingrese el nombre --> \t")
  91.        if nombre.isalpha():
  92.            print("Nombre Correcto")
  93.            return nombre
  94.            b=True
  95.        else:
  96.            print("nombre incorrecto, intenta de nuevo")
  97.  
  98.  
  99. def idp():
  100.    b=False
  101.    while b!=True:
  102.        try:
  103.            global Id
  104.            global aux
  105.            Id=int(input("ingresa el id del proceso--> "))
  106.            if Id in ids:
  107.                print("id repetido")  
  108.            else:
  109.                print("id valido")
  110.                aux=Id
  111.                ids.append(Id)
  112.                return Id
  113.                b=True
  114.        except:
  115.            print("id invalido")
  116.  
  117.  
  118. def mostrar():
  119.        for proceso in listap:
  120.            print(" nombre: ",proceso.nombre,"\n","id: ",proceso.idp,"\n","operacion: ",proceso.signo,"\n","operador 1: ",proceso.ope1,"\n", "operando 2: ",proceso.ope2,"\n","tiempo de proceso: ",proceso.tiempom)
  121.  
  122. #print(cantidadp())
  123.  
  124. def procesar():
  125.    os.system("cls")
  126.    cadena="lotes a procesar"
  127.    print(cadena.center(20,"="))
  128.    a=1
  129.    b=0
  130.    for proceso in listap:
  131.            if(a==1):
  132.                b+=1;
  133.                print("=====Lotes #",b,"=====")
  134.                a=0;
  135.            print(" nombre: ",proceso.nombre,"\n","id: ",proceso.idp,"\n","operacion: ",proceso.signo,"\n","operador 1: ",proceso.ope1,"\n", "operando 2: ",proceso.ope2,"\n","tiempo de proceso: ",proceso.tiempom)
  136.            a+=1
  137.    os.system("pause")
  138.    print("Pulsa una tecla para comenzar a procesar")
  139.  
  140.  
  141.  
  142. def menu():
  143.    opc=0
  144.    while opc !=3:
  145.        print("---menu---")
  146.        print("1.registro de procesos ")
  147.        print("2.procesar ")
  148.        print("4.mostrar lista ")
  149.        print("3.salir ")
  150.        opc=int(input(" elija una opcion?" ))
  151.  
  152.        if opc==1:
  153.            cantidadp()
  154.            os.system("cls")
  155.        elif opc==2:
  156.            procesar()
  157.        elif opc==4:
  158.            os.system("cls")
  159.            mostrar()
  160.  
  161.  
  162.  
  163.  
  164. menu()
  165.  
  166. os.system("pause")      
  167.  
  168.  
  169.  


de antemano gracias por su ayuda
 
2  Programación / Java / AYUDA error de conexion a base de datos en: 9 Noviembre 2019, 01:27 am
Al hacer una conexion con mi base de datos en posgresSQL , primero si la conecto aparece red conectada de manera correcta , pero al ingresar datos me aparece error de conexion
Me podrian ayudar?

Código
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11.  *
  12.  * @author andy
  13.  */
  14. public class InterfazInicio extends javax.swing.JFrame {
  15.    private  Connection connection = null;
  16.    private ResultSet  rs = null;
  17.    private Statement s=null;
  18.    /**
  19.      * Creates new form InterfazInicio
  20.      */
  21.    public InterfazInicio()
  22.    {
  23.        initComponents();
  24.    }
  25.     public void conexion (){
  26.    if (connection != null){
  27.        return;
  28.    }
  29.    String url = "jdbc:postgresql://127.0.0.1:5432/neveria";
  30.    String password = "1234";
  31.    try {
  32.        Class.forName("org.postgresql.Driver");
  33.        connection = DriverManager.getConnection(url,"andres",password);
  34.        if(connection !=null){
  35.  
  36.            System.out.println("Base de datos conectada");
  37.        }        
  38.    }catch(Exception e){
  39.  
  40.        System.out.println("Base de datos no conectada");
  41.    }  
  42.  
  43. }
  44.  
  45.    @SuppressWarnings("unchecked")
  46.    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  47.    private void initComponents() {
  48.  
  49.        jTextField1 = new javax.swing.JTextField();
  50.        jButton1 = new javax.swing.JButton();
  51.        jTextField2 = new javax.swing.JTextField();
  52.        jButton2 = new javax.swing.JButton();
  53.  
  54.        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  55.  
  56.        jTextField1.addActionListener(new java.awt.event.ActionListener() {
  57.            public void actionPerformed(java.awt.event.ActionEvent evt) {
  58.                jTextField1ActionPerformed(evt);
  59.            }
  60.        });
  61.  
  62.        jButton1.setText("Registrar");
  63.        jButton1.addActionListener(new java.awt.event.ActionListener() {
  64.            public void actionPerformed(java.awt.event.ActionEvent evt) {
  65.                jButton1ActionPerformed(evt);
  66.            }
  67.        });
  68.  
  69.        jButton2.setText("Consultar");
  70.  
  71.        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  72.        getContentPane().setLayout(layout);
  73.        layout.setHorizontalGroup(
  74.            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  75.            .addGroup(layout.createSequentialGroup()
  76.                .addGap(32, 32, 32)
  77.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  78.                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
  79.                    .addComponent(jTextField1))
  80.                .addGap(65, 65, 65)
  81.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  82.                    .addComponent(jButton1)
  83.                    .addComponent(jButton2))
  84.                .addContainerGap(71, Short.MAX_VALUE))
  85.        );
  86.        layout.setVerticalGroup(
  87.            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88.            .addGroup(layout.createSequentialGroup()
  89.                .addGap(27, 27, 27)
  90.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  91.                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  92.                    .addComponent(jButton1))
  93.                .addGap(43, 43, 43)
  94.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  95.                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  96.                    .addComponent(jButton2))
  97.                .addContainerGap(55, Short.MAX_VALUE))
  98.        );
  99.  
  100.        pack();
  101.    }// </editor-fold>                        
  102.  
  103.    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  104.        conexion();
  105.            try{
  106.                 String name = jTextField1.getText();
  107.                s = connection.createStatement();
  108.                int z = s.executeUpdate ("INSERT INTO cliente (nombre) VALUES('" +name+ "')");
  109.                if(z == 1){
  110.                  System.out.println("Se agrego registro correctamente");
  111.              } else{
  112.                  System.out.println("Intente de nuevo");
  113.              }  
  114.          }catch(SQLException e){
  115.              System.out.println("Error al conectar con la base de datos");
  116.          }
  117.    }                                        
  118.  
  119.    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  120.        // TODO add your handling code here:
  121.    }                                          
  122.  
  123.    /**
  124.      * @param args the command line arguments
  125.      */
  126.    public static void main(String args[]) {
  127.        /* Set the Nimbus look and feel */
  128.        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  129.        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  130.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  131.          */
  132.        try {
  133.            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  134.                if ("Nimbus".equals(info.getName())) {
  135.                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
  136.                    break;
  137.                }
  138.            }
  139.        } catch (ClassNotFoundException ex) {
  140.            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  141.        } catch (InstantiationException ex) {
  142.            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  143.        } catch (IllegalAccessException ex) {
  144.            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  145.        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  146.            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  147.        }
  148.        //</editor-fold>
  149.  
  150.        /* Create and display the form */
  151.        java.awt.EventQueue.invokeLater(new Runnable() {
  152.            public void run() {
  153.                new InterfazInicio().setVisible(true);
  154.            }
  155.        });
  156.    }
  157.  
  158.    // Variables declaration - do not modify                    
  159.    private javax.swing.JButton jButton1;
  160.    private javax.swing.JButton jButton2;
  161.    private javax.swing.JTextField jTextField1;
  162.    private javax.swing.JTextField jTextField2;
  163.    // End of variables declaration                  
  164. }
  165.  
  166.  
  167.  
3  Programación / Programación C/C++ / Ayuda funcion eliminar en: 9 Septiembre 2019, 03:42 am
Alguien me podria porque a la hora de eliminar mi programa no reconoce el if

Código
  1.  
  2. void Alumno::eliminar(){
  3.    int a,k,i,opc;
  4.  
  5.            if(strcmp(auxiliar,nombre)==0){
  6.                cout<<"\nNombre: "<<nombre<<"\nGrado: "<<grado<<"\nGrupo: "<<grupo<<"\nMaestra: "<<maestra<<"\nMadre: "<<madre<<"\nCelular de la madre: "<<celMadre<<"\nPadre: "<<padre
  7. <<"\nCelular del padre: "<<celPadre<<"\nTelefono de casa: "<<telCasa<<"\nTelefono de trabajo: "<<telTrabajo<<"\nCorreo: "<<correo<<endl<<endl;
  8.                bandera = true;
  9.                cout<<"quieres eliminar algun dato?\n 1.si\n 0.no: \n";
  10.                cin>>opc;
  11.            }
  12.        }//while
  13.        leer.close();
  14.  
  15. if(opc == 1)//este if
  16.    {
  17.        ifstream leer("alumnoPri.txt.txt");
  18.        ofstream abrir("ayuda.txt", ios::app);
  19.        while(!leer.eof())
  20.        {
  21.                leer.read((char *)&a,sizeof(int));
  22. leer.read((char *)&nombre,a);
  23.  
  24. valor = strcmp(auxiliar,nombre);
  25.  
  26. leer.read((char *)&a,sizeof(int));
  27. leer.read((char *)&grado,a);
  28.  
  29.  
  30. leer.read((char *)&a,sizeof(int));
  31. leer.read((char *)&grupo,a);
  32.  
  33.  
  34. leer.read((char *)&a,sizeof(int));
  35. leer.read((char *)&maestra,a);
  36.  
  37.  
  38. leer.read((char *)&a,sizeof(int));
  39. leer.read((char *)&madre,a);
  40.  
  41.  
  42. leer.read((char *)&a,sizeof(int));
  43. leer.read((char *)&celMadre,a);
  44.  
  45. leer.read((char *)&a,sizeof(int));
  46. leer.read((char *)&padre,a);
  47.  
  48. leer.read((char *)&a,sizeof(int));
  49. leer.read((char *)&celPadre,a);
  50.  
  51. leer.read((char *)&a,sizeof(int));
  52. leer.read((char *)&telCasa,a);
  53.  
  54. leer.read((char *)&a,sizeof(int));
  55. leer.read((char *)&telTrabajo,a);
  56.  
  57. leer.read((char *)&a,sizeof(int));
  58. leer.read((char *)&correo,a);
  59.  
  60.                    if(strcmp(auxiliar,nombre) != 0)
  61.                    {
  62.                        abrir.write((char*)&a, sizeof(int));
  63.                        abrir.write((char*)&nombre, a);
  64.  
  65.                        abrir.write((char*)&a, sizeof(int));
  66.                        abrir.write((char*)&grado, a);
  67.  
  68.                        abrir.write((char*)&a, sizeof(int));
  69.                        abrir.write((char*)&grupo, a);
  70.  
  71.                        abrir.write((char*)&a, sizeof(int));
  72.                        abrir.write((char*)&maestra, a);
  73.  
  74.                        abrir.write((char*)&a, sizeof(int));
  75.                        abrir.write((char*)&madre, a);
  76.  
  77.                        abrir.write((char*)&a, sizeof(int));
  78.                        abrir.write((char*)&celMadre, a);
  79.  
  80.                        abrir.write((char*)&a, sizeof(int));
  81.                        abrir.write((char*)&padre, a);
  82.  
  83.                        abrir.write((char*)&a, sizeof(int));
  84.                        abrir.write((char*)&celPadre, a);
  85.  
  86.                        abrir.write((char*)&a, sizeof(int));
  87.                        abrir.write((char*)&telCasa, a);
  88.  
  89.                        abrir.write((char*)&a, sizeof(int));
  90.                        abrir.write((char*)&telTrabajo, a);
  91.  
  92.                        abrir.write((char*)&a, sizeof(int));
  93.                        abrir.write((char*)&correo, a);
  94.  
  95.                    }
  96.  
  97.        }
  98.        abrir.close();
  99. leer.close();
  100. remove("alumnoPri.txt");
  101. rename("ayuda.txt", "alumnoPri.txt");
  102.    }
  103. }
  104. }
  105.  
  106.  
4  Programación / Programación C/C++ / Funcion buscar en archivos en: 2 Septiembre 2019, 04:06 am
Tengo este codigo y esto trabado en la funcion buscar no se como realizarla alguien me podria explicar?
Código
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<fstream>
  4. #include<string.h>
  5. #include <stdio.h>
  6.  
  7. using namespace std;
  8.  
  9. class provedor{
  10.  
  11.    public:
  12.        char nombre[20];
  13.        char codigo[10];
  14.        void agregar();
  15.        void imprimir();
  16.        void buscar();
  17.        void modificar();
  18.        void eliminar();
  19.  
  20. };
  21.  
  22.  
  23. int main(){
  24.    provedor prov;
  25.    prov.agregar();
  26.    prov.buscar();
  27. }
  28.  
  29.  
  30. void provedor::agregar(){
  31.    cout<<"nombre provedor: "<<endl;
  32.    cin.getline(nombre,20);
  33.    fflush(stdin);
  34.    cout<<"codigo de provedor:"<<endl;
  35.    cin.getline(codigo,10);
  36.    fflush(stdin);
  37.    ofstream archivo("Provedores.txt", ios::app);
  38.    archivo<<codigo<<"|"<<nombre<<"|"<<"\n";
  39.    archivo.close();
  40. }
  41.  
  42. void provedor::buscar(){
  43.    char ref[35], comp[35], prev[35];
  44.    int band=1;
  45.    cout<<"\nEscribe el codigo del proveedor a buscar \n";
  46.    fflush(stdin);
  47.    cin.getline(ref, 35);
  48.    ifstream lee("Provedores.txt",ios::app);
  49.    if(!lee.good()){
  50.        cout<<"\nEl archivo no existe";
  51.    }
  52.    else
  53.        {
  54.            while(!lee.eof() && band==1)
  55.            {
  56.                lee.getline(prev, 35, '|');
  57.                lee.getline(comp, 35, '|');
  58.                if(strcmp(comp, ref)==0)
  59.                {
  60.                cout<<"encontrado"<<endl;
  61.                band=0;
  62.                }
  63.                else
  64.                {
  65.                   lee.getline(comp, 35, '|');
  66.                   lee.getline(comp, 35, '|');
  67.                }
  68.            }
  69.            if(band)
  70.            cout<<"\nNo se encontro el proveedor";
  71.        }
  72. }
  73.  
  74.  
  75.  
5  Programación / Programación C/C++ / ayuda funcion buscar en: 22 Mayo 2019, 05:53 am
Cuando uso la funcion buscar en mi codigo, esta no busca. Me podrian ayudar?
Código
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define TAM 1000
  4.  
  5.  
  6. struct Ferreteria{
  7.  
  8.    int sueldoH;
  9.    char nombre[20], ap[30], direccion[20], telefono[10];
  10.    char edad[2], contrato[30], hrsextras[5];
  11.  
  12. }p[TAM];
  13.  
  14. struct Ferreteria capturar(struct Ferreteria x){
  15.  
  16. printf("\nNOMBRE: ");
  17.    fflush(stdin);
  18.    scanf("%s", &x.nombre);
  19.    printf("\nAPELLIDO: ");
  20.    fflush(stdin);
  21.    gets(x.ap);
  22.    printf("\nDIRECCION: ");
  23.    fflush(stdin);
  24.    gets(x.direccion);
  25.    printf("\nTELEFONO: ");
  26.    fflush(stdin);
  27.    gets(x.telefono);
  28.    printf("\nTIPO DE CONTRATO: ");
  29.    fflush(stdin);
  30.    scanf("%s", &x.contrato);
  31.    printf("\nHORAS EXTRAS: ");
  32.    fflush(stdin);
  33.    gets(x.hrsextras);
  34.    return x;
  35.  
  36.  
  37. }
  38.  
  39. void mostrar(struct Ferreteria x){
  40.  
  41.            fflush(stdin);
  42.    printf("\nLOS DATOS SON: \n"
  43.           "\nNOMBRE: %s \nAPELLIDO: %s"
  44.           "\nDIRECCION: %s" "\nTELEFONO: %s\n"
  45.           "TIPO DE CONTRATO: %s",
  46.           x.nombre,x.ap, x.direccion, x.telefono, x.contrato,x.hrsextras);
  47.           fflush(stdin);
  48.  
  49.           if(strcmp(x.contrato, "obrero")==0)
  50.           {
  51.               fflush(stdin);
  52.               x.sueldoH=x.sueldoH+70;
  53.               fflush(stdin);
  54.               printf("\nSUELDO POR HORA: %i", x.sueldoH);
  55.               fflush(stdin);
  56.           }
  57.           fflush(stdin);
  58.  
  59.           if(strcmp(x.contrato, "administrativo")==0)
  60.           {
  61.               fflush(stdin);
  62.               x.sueldoH=x.sueldoH+80;
  63.               fflush(stdin);
  64.               printf("\nSUELDO POR HORA: %i", x.sueldoH);
  65.               fflush(stdin);
  66.           }
  67.  
  68.           if(strcmp(x.contrato, "jefe de area")==0)
  69.           {
  70.               fflush(stdin);
  71.               x.sueldoH=x.sueldoH+90;
  72.               fflush(stdin);
  73.               printf("\nSUELDO POR HORA: %i", x.sueldoH);
  74.           }
  75.           fflush(stdin);
  76.  
  77.  
  78. }
  79.  
  80. int buscar(struct Ferreteria x[], int n, char nom[]){
  81.    int i;{
  82.    for(i=0; i<n; i++)
  83.        if (!(strcmp(x[i].nombre, nom))){
  84.        return i;
  85.        }
  86.    }
  87. return 0;
  88.  
  89. }
  90.  
  91. int localizar(struct Ferreteria x[], int n, char nom){
  92.    int i;{
  93.    for(i=0; i<n; i++)
  94.        if (nom == x[i].nombre){
  95.        return 1;
  96.        }
  97.    }
  98. return 0;
  99.  
  100. }
  101.  
  102. int eliminar(struct Ferreteria x[], int n, int index){
  103.  
  104.    int i;
  105.  
  106.    for(i= index; i < n; i++)
  107.        x[i] = x[i+1];
  108.    n--;
  109.    return n;
  110.  
  111.  
  112. }
  113.  
  114.  
  115. main(){
  116.  
  117. int n,i;
  118. char c[20];
  119.  
  120. printf("CUANTOS EMPLEADOS QUIERES REGISTAR: ");
  121. scanf("%d",  &n);
  122. for(i = 0; i<n; i++)
  123.  
  124. p[i] = capturar(p[i]);
  125.  
  126. for(i=0; i<n; i++)
  127. mostrar(p[i]);
  128.  
  129.    printf("\nNOMBRE DEL EMPLEADO: ");
  130.    scanf("%s", &c);
  131.        if(buscar(p,n,c))
  132.            printf("si existe el empledado\n");
  133.            else
  134.            printf("no existe el empleado\n");
  135.  
  136.  
  137.  
  138.          int a= localizar(p,n,c);
  139.        if(a >=0){
  140.  
  141.            n = eliminar(p,n,a);
  142.            printf("registro eliminado");
  143.  
  144.            for(i = 0; i <n; i++)
  145.            mostrar(p[i]);
  146.        }
  147.            else
  148.                printf("no exsiste");
  149.  
  150. }
  151.  
  152.  
6  Programación / Programación C/C++ / ayuddaa con OBjetos en: 30 Marzo 2019, 03:33 am
Apenas comence con objetos y me dejaron inicialiezar esta lista pero no se coomo hacerlo, me podrian ayudar?

#ifndef ARREGLO_H_INCLUDED
#define ARREGLO_H_INCLUDED
#include "Empleado.h"
class Arreglo{
private:
    Empleado elementos[10];

public:
    Arreglo();
    void insertar(Empleado, int);
    int eliminar(int, int);
    void mostrar(int);
    int buscar(char *, int);

};

#endif // ARREGLO_H_INCLUDED


#include "Arreglo.h"
#include <iostream>
#include "cstring"


Arreglo::Arreglo(int) {


}

void Arreglo::insertar(Empleado e,int p) {

        elementos[p] = e;

    }

int Arreglo::eliminar(int p, int cont) {
    int i;

    for (i = p; i < cont; i++) {
        elementos = elementos[i + 1];
        }
    return --cont;

    }

void Arreglo::mostrar(int cont) {

    for(int i  = 0; i < cont; i++) {
        std::cout << "\n\n";
        std::cout << "NOMBRE:"  << "\t" << elementos.nombre << std::endl;
        std::cout << "TELEFONO:" << "\t" << elementos.tel_emp << std::endl;
        std::cout << "SUELDO:" << "\t" << elementos.salario << std::endl;
        }
    }

int Arreglo::buscar(char *e, int cont) {

    for(int i = 0; i < cont; i++) {
        if(strcmp(e, elementos.nombre) == 0)
            return i;
        }
    return -1;
    }

Me gustaria si pudieran proporcionarme algun libro o tutoriales para enteder este concepto?
muchas gracias de antemano
7  Programación / Programación C/C++ / ayuda en: 15 Febrero 2019, 06:39 am
ERROR: EXPECTED UNQUALIFIED-ID BEFORE '.' TOKEN

ya he creado todo mi codigo en poo pero al mandar llamar mis funciones en el menu, en la funcion main me aparece ese error.Se me acabaron las ideas

¿alguien me puede decir como mandar a lllamar funciones de obejetos?


#include "cstring"
#include "iostream"

using namespace std;

class Empleado{
private:

protected:

public:
    char nombre[30];
    long tel_emp;
    float salario;

    Empleado(char *n, long t, float s);
    void capturar(void);
    void mostrar(void);
};

Empleado::Empleado(char *n, long t, float s){strcpy(nombre, n); tel_emp = t; salario = s;}

void Empleado::capturar(void){
    cout<<"NOMBRE: ";
    cin >>nombre;
    cout<<"TELEFONO:";
    cin>>tel_emp;
    cout<<"SALARIO:";
    cin>>salario;
}

void Empleado::mostrar(void){
    cout<<"NOMBRE: "<<nombre<<endl;
    cout<<"TELEFONO: "<<tel_emp<<endl;
    cout<<"SALARIO: "<<salario<<endl;
}


 main(){
    char op;
    Empleado emp();

    do{
        cout<<"menu de opciones"<<endl;
        cout<<"1.- capturar"<<endl<<"2.- mostrar"<<endl;
        cout<<"3.- eliminar"<<endl<<"4.- buscar"<<endl<<"5.- Salir"<<endl;
        cout<<"Elige una opcion: "<<endl;
        cin>>op;
        switch (op){
        case 1:
            Empleado.capturar()
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        }
    }while (op != '5');

}
en otros archivos tengo los header, si son necesarios para corregir haganmelo saber

8  Programación / Programación C/C++ / ayuda matrices en: 10 Enero 2019, 06:34 am
#include<iostream>
using namespace std;

main()
{
int game [3][3];
int a=1;
for(int i=1;i<4;i++)
{
    cout<<endl<<endl;
    for(int j=1;j<4;j++)
    {
        game[j]=a++;
        cout.width(5);
        cout << game[j] << " ";

    }
    cout<<endl<<endl;

}
}

Alguien me puede decir si asi es el metodo correcto para llenar  una matriz?

Y si lo es porque cuando imprimo aparece asi   1  2  3
                                                                    4  5  4535... (es una matriz)
                                                                   122  8 9

Gracias
9  Programación / Programación C/C++ / COMO DIVIDIR MI CODIGO EN FUNCIONES(VOID) en: 24 Octubre 2018, 06:55 am
TENGO QUE DIVIDIR MI CODIGO EN FUNCIONES USANDO VOID PERO NO SALE ME QUEDAN INSERVIBLES LAS LINEAS DE CODIGO

#include<stdio.h>
#define t 100
main()
{
    int cal[t],ac,prom,rep,na,i,mayor,menor;
    char nomalum[t][t];


    do
    {
        printf(" cuantos alumnos tenemos max 100 ");
        scanf("%i",&na);
        ac=0;
        for(i=0;i<na;i++)
        {
            printf(" tecle el nombre de, alumno %i \n ",i+1);
            fflush(stdin),gets(nomalum);
            printf(" teclea la calificacion de %s \n",nomalum);
            scanf("%i",&cal);
            ac+=cal;
        }
        prom= ac/na;
        printf(" \n el promedio del grupo fue de %i \n",prom );
        printf(" \n los alumnos por arriba del promedio fueron\n  ");

        for(i=0;i<na;i++)
            if(cal>prom)
                printf("\n %s con calificacion de %i \n",nomalum,cal);
        mayor=0;
        for(i=0;i<na;i++)
        {
            if(cal>mayor)
            {
                mayor=cal;
            }
        }
        printf("\n la calificacion mayor es %i ",mayor,dia);
        menor=prom;
        for(i=0;i<na;i++)
        {
            if(cal<menor)
            {
                menor=cal;
            }
        }
        printf("\n la calificacion menor es %i ",menor,dia);


        printf(" \n deseas volver a correr el programa 1=si \n");
        scanf(" %i ",& rep);
    }while(rep==1);
}
10  Programación / Programación C/C++ / ayuda en: 23 Octubre 2018, 07:31 am
tengo el siguiente codigo en el cual solo puedo introducir un pais y una capital, y necesito colocar varios ya que es un juego de aciertos y errores .



#include"stdio.h"
#include"string.h"
#define t 20
main()
{
    int i,n=4,error=0,acierto=0;
    char pais1[t]="mexico ";
    char capital1[t]="distrito-federal";
    char respuesta[t];
    printf("cual es la capital de %s ? \n",pais1);
    fflush(stdin),gets(respuesta);
    if (strcmp(capital1,respuesta)==0)
        {printf(" correcto\n");
        acierto+=1;
        }
    else
       {
         printf("incorrecto\n");
        error+=1;
       }

    printf(" \n marcador\n");
    printf("numero de aciertos %i\n",acierto);
    printf(" numero de errores %i\n",error);
Páginas: [1] 2
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines