Documentos de Académico
Documentos de Profesional
Documentos de Cultura
salario);
if(emp[e].salario>mayor) {
DOC. JAVIER DE LA CRUZ
mayor=emp[e].salario;
EJERCICIOS RESUELTOS DE STRUCT C++
pmay=e;
}
1). La informacin de todos los empleados de
la empresa DATASYSTEM est almacenada if(emp[e].salario<menor) {
en una variable de tipo struct llamada
menor=emp[e].salario;
empleado. La informacin con que se
cuenta de cada empleado es: nombre, sexo y pmen=e;
sueldo.
}
Por tanto se pide: Realizar un programa en C
que lea en un array de estructuras los datos }
de los N trabajadores de la empresa y que printf("\n\n%s es el trabajador con MAYOR
imprima los datos del empleado con mayor y salario\n",emp[pmay].nombre);
menor salario.
printf("%s es el trabajador con MENOR
Solucin: salario\n",emp[pmen].nombre);
#include<stdio.h> struct empleado }
{
char nombre[30]; char sexo[12]; float salario; 2). A partir de la declaracin de las siguientes
}; estructuras realice un programa en C que lea
el array ats y devuelva los datos (nombre,
void main() { pas, deporte) del atleta que ha ganado
mayor nmero de medallas.
struct empleado emp[100];
int e,nemp,pmay,pmen;
struct datos{
float mayor=0.0, menor=9999.0;
printf("Introduzca el numero de empleados: char nombre[40]; char pais[25];
");
};
scanf("%d",&nemp);
struct atleta{
for(e=0;e<nemp;e++) {
char deporte[30]; struct datos pers; int
printf("\n"); printf("Nombre[%d]: ",e+1); nmedallas;
scanf("%s",emp[e].nombre); };
printf("Sexo[%d]: ",e+1); struct atleta ats[30];
scanf("%s",emp[e].sexo); Solucin:
printf("Salario[%d]: ",e+1); //atletas.c
#include<stdio.h> printf("PAIS: %s\n",ats[posmay].pers.pais);
printf("DEPORTE:
struct datos{
%s\n",ats[posmay].deporte);
char nombre[40]; char pais[25];
printf("NUMERO DE MEDALLAS:
}; %d\n",ats[posmay].nmedallas);
struct atleta{ }
for(a=0;a<3;a++) { *************************************
printf("Deporte[%d]: ",a+1);
#include<iostream>
scanf("%s",ats[a].deporte);
#include<cstdlib>
printf("Numero de Medallas[%d]: ",a+1);
scanf("%d",&ats[a].nmedallas); #include<string.h>
} #define maxchar 50
{ struct nodo{
} cin.getline(q->nombres,maxchar);
cin.ignore();
cout<<"\n\t\t[ ESPECIFIQUE CAMPO A cout<<"\tDIRECCION:";
ACTUALIZAR ]\n";
cin.getline(q->direccion,maxchar);
cout<<"\t\t----------------------------\n\n";
cin.ignore();
cout<<" 1. NOMBRES "<<endl;
cout<<"\n\tTELEFONO:"; delete(q);
cin>>q->telefono; cout<<"\n\n\tREGISTRO
ELIMINADO...!!!!!\n";
system("cls");
return;
q->sgte = NULL;
}else {
if(lista==NULL){
t=q;
lista = q;
q=q->sgte;
} else {
}
t = lista;
while(t->sgte!=NULL){
}
t = t->sgte;
if(q==NULL)
}
cout<<"\n\tCODIGO
t->sgte = q;
INCORRECTO...!!\n";
}
}
}
/*-------------------- FUNCION ACTUALIZAR
PACIENTE -------------------*/
while(q!=NULL){ if(q->codigo==cod){
if(q->codigo==cod){ system("cls");
lista=lista->sgte; cout<<"\n\t--------------------";
cout<<"\tAPELLIDOS: "<<q- }
>apellidos<<endl;
cout<<"\n\n\tREGISTRO
cout<<"\tDIRECCION: "<<q- ACTUALIZADO...!!!!!\n";
>direccion<<endl;
return;
cout<<"\tTELEFONO : "<<q-
}else {
>telefono<<endl;
q=q->sgte;
menu_actualizar();
}
cin>>x;
switch(x){
}
case 1: cout<<"\n\n\tINGRESE
NOMBRES:"; if(q==NULL)
cin.ignore(); cin.getline(q- cout<<"\n\tCODIGO
>nombres,maxchar); INCORRECTO...!!\n";
break; }
case 2: cout<<"\n\n\tINGRESE /*---------------------- FUNCION MOSTRAR
APELLIDOS:"; PACIENTE -------------------*/
cin.ignore(); cin.getline(q- void mostrar_pacientes(PLista q){
>apellidos,maxchar);
int i=1;
break;
while(q!=NULL){
case 3: cout<<"\n\n\tINGRESE
DIRECCION:"; cout<<"\n\tDATOS DEL PACIENTE
["<<i<<"] ";
cin.ignore(); cin.getline(q-
>direccion,maxchar); cout<<"\n\t------------------------";
cout<<"\n\tNOMBRES : "<<q-
case 4: cout<<"\n\n\tINGRESE >nombres<<endl;
TELEFONO:";
cout<<"\tAPELLIDOS: "<<q-
cin>>q->telefono; >apellidos<<endl;
break; cout<<"\tDIRECCION: "<<q-
>direccion<<endl;
cout<<"\tTELEFONO : "<<q- cout<<"\tAPELLIDOS: "<<p-
>telefono<<endl; >apellidos<<endl;
p=lista;
cout<<"\n\tDATOS DEL PACIENTE A
q=lista;
SUSITUIR ";
char dato[maxchar];
cout<<"\n\t--------------------";
cout<<"\n\n\n\tCOPIAR DATOS DE
cout<<"\n\n\tCODIGO : "<<q-
PACIENTE A OTRO";
>codigo<<endl;
cout<<"\n\n\n\t--------------------------------";
cout<<"\n\tNOMBRES : "<<q-
cout<<"\n\n\tINGRESE CODIGO DE >nombres<<endl;
PACIENTE A COPIAR:"; cin>>cod1;
cout<<"\tAPELLIDOS: "<<q-
cout<<"\n\n\tINGRESE CODIGO DE >apellidos<<endl;
PACIENTE A SUSTITUIR:";cin>>cod2;
cout<<"\tDIRECCION: "<<q-
system("cls"); >direccion<<endl;
break; switch(opcion){
strcpy(q->direccion,dato); break;
} break;
}else { }else{
q=q->sgte; actualizar_paciente(lista);
} }
} break;
} }else {
do{ }else{
menu(); copiar_datos_paciente(lista);
}
break;
case 6: return 0;
system("pause"); system("cls");
}while(opcion!=6);
system("pause");
return 0;