Registros 1. se ingresan varios datos de n

Anuncio
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
Registros
1. se ingresan varios datos de n estudiantes (n dado por teclado) de un colegio, como el
nombre, código, curso, y el nombre y nota de 3 materias por cada estudiante. Se desea
saber la información de cualquier estudiante mediante su código, y al mismo tiempo
determinar su promedio de las 3 notas de las materias ingresadas. El sistema dejará de
correr cuando no se desee saber más información de los alumnos en la base de datos.
#include<stdio.h>
#include<conio.h>
struct materias
{
char nom[50];
float nota;
};
struct base
{
char nombre[20];
long codigo;
int curso;
struct materias m[2];
};
void llenar(struct base b[50],int n);
void buscar(struct base b[50],long int cod,int n);
main()
{
struct base b[50];
struct materias m[2];
int n;
long int cod;
char cd[0];
printf("ingrese el numero de alumnos ");
scanf("%d",&n);
llenar(b,n);
do
{
printf("desea saber la informacion y el promedio de algun alumno, S(si),N(no) ");
scanf("%s",&cd[0]);
if(cd[0]=='s')
{
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
printf("digite codigo del alumno ");
scanf("%d",&cod);
buscar(b,cod,n);
}
else
{
printf("gracias por utilizar nuestro sistema ");
}
}while(cd[0]!='n');
getch();
return(0);
}
void llenar(struct base b[50],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("ingrese nombre del alumno %d ",i+1);
fflush(stdin);
gets(b[i].nombre);
printf("ingrese codigo del alumno %d ",i+1);
scanf("%d",&b[i].codigo);
printf("ingrese el grado que cursa 9, 10, 11 ");
scanf("%d",&b[i].curso);
for(j=0;j<=2;j++)
{
printf("ingrese nombre de la materia %d ",j+1);
fflush(stdin);
gets(b[i].m[j].nom);
printf("ingrese nota de la materia %d ",j+1);
scanf("%f",&b[i].m[j].nota);
}
}
}
void buscar(struct base b[50],long int cod,int n)
{
int i,j;
float prom,sum=0;
for(i=0;i<n;i++)
{
if(cod==b[i].codigo)
{
This image cannot currently be display ed.
}
}
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
for(j=0;j<=2;j++)
{
sum=sum+b[i].m[j].nota;
}
prom=sum/3;
printf("nombre del alumno \n");
puts(b[i].nombre);
printf("codigo del alumno %d \n",b[i].codigo);
printf("curso del alumno %d \n",b[i].curso);
printf("materia 1 \n");
puts(b[i].m[0].nom);
printf("nota %f \n",b[i].m[0].nota);
printf("materia 2 \n ");
puts(b[i].m[1].nom);
printf("nota %f \n",b[i].m[1].nota);
printf("materia 3 \n");
puts(b[i].m[2].nom);
printf("nota %f \n",b[i].m[2].nota);
printf("promedio del alumno por materias %f \n ",prom);
}
2. En un colegio, se desea saber el profesor más joven, el promedio de edades de todos, las
profesoras con edad mayor al promedio, y los profesores con edad menor el promedio. No
se sabe cuántos profesores son. El conteo terminara al ingresar una letra distinta a m o f
minúscula en el campo “sexo”.
#include<stdio.h>
#include<conio.h>
struct profesores
{
char nombre[50];
char sexo[20];
int edad,sueldo;
};
int llenar(struct profesores p[50]);
float busprom(struct profesores p[50],int n);
void busprof(struct profesores p[50],int i,float prom);
main()
{
struct profesores p[50];
int n;
float prom;
n=llenar(p);
This image cannot currently be display ed.
prom=busprom(p,n);
busprof(p,n,prom);
getch();
return(0);
}
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
int llenar(struct profesores p[50])
{int i=0,j=0;
do
{
printf("ingrese sexo del profesor %d ",i+1);
fflush(stdin);
gets(p[i].sexo);
if(p[i].sexo[0]=='m'||p[i].sexo[0]=='f')
{
printf("ingrese nombre del profesor(a) ");
fflush(stdin);
gets(p[i].nombre);
printf("ingrese edad del profesor ");
scanf("%d",&p[i].edad);
printf("ingrese sueldo del profesor ");
scanf("%d",&p[i].sueldo);
j++;
}
else
{p[i].sexo[0]='h';
}
i++;
}
while(p[i-1].sexo[0]!='h');
return(j);
}
float busprom(struct profesores p[50],int n)
{int i,sum=0,men=1000,pos;
float prom;
for(i=0;i<n;i++)
{sum=sum+p[i].edad;
if(p[i].edad<men)
{
men=p[i].edad;
pos=i;
}
}
prom=sum/n;
printf("el empleado mas joven es ");
puts(p[pos].nombre);
This image cannot currently be display ed.
return(prom);
}
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
void busprof(struct profesores p[50],int n,float prom)
{
int i;
printf("profesoras con edad mayor al promedio\n");
for(i=0;i<n;i++)
{if(p[i].sexo[0]=='f'&&p[i].edad>prom)
{
puts(p[i].nombre);
}
}
printf("profesores con edad menor al promedio\n");
for(i=0;i<n;i++)
{if(p[i].sexo[0]=='m'&&p[i].edad<prom)
{
puts(p[i].nombre);
}
}
}
3. Se tienen los datos de las bombas de gasolina de Cúcuta, y se sabe por cada bomba el
nombre del que la cuida, y el ingreso bimestral (cada 2 meses) de la bomba, y se desea
saber cual bomba obtuvo más ingresos en el año, el nombre del que la cuida, y la
bonificación para el empleado que mas vendió que es del 20% de lo vendido. El número de
bombas es dado por teclado.
#include<stdio.h>
#include<conio.h>
struct ganancia
{
float ingresos;
};
struct encargados
{char nombre[20],bomba[20];
struct ganancia g[6];
};
void llenar(struct encargados e[50],int n);
void busboni(struct encargados e[50],int pos,float sum);
void busgana(struct encargados e[50],int n);
main()
This image cannot currently be display ed.
{struct encargados e[50];
struct ganancia g[6];
int n;
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
printf("cuantas bombas existen en cucuta ");
scanf("%d",&n);
llenar(e,n);
busgana(e,n);
getch();
return(0);
}
void llenar(struct encargados e[50],int n)
{int i,j;
for(i=0;i<n;i++)
{printf("nombre de la bomba %d ",i+1);
fflush(stdin);
gets(e[i].bomba);
printf("nombre del encargado ");
fflush(stdin);
gets(e[i].nombre);
for(j=0;j<6;j++)
{
printf("digite ingresos bimestre %d ",j+1);
scanf("%f",&e[i].g[j].ingresos);
}
}
}
void busgana(struct encargados e[50],int n)
{
int i,j,pos;
float may=0,sum=0;
for(i=0;i<n;i++)
{sum=0;
for(j=0;j<6;j++)
{
sum= sum + e[i].g[j].ingresos;
}
if(sum>may)
{
may=sum;
pos=i;
}
}
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
printf("la estacion con mayor ganancia fue la bomba de \n");
puts(e[pos].bomba);
printf("con unos ingresos de %f \n ",sum);
busboni(e,pos,sum);
}
void busboni(struct encargados e[50],int pos,float sum)
{float bonificacion;
printf("el empleado ganador es \n");
puts(e[pos].nombre);
}
bonificacion=(sum*20)/100;
printf("y se lleva una bonificacion de %f pesos ",bonificacion);
4. un programa que pida por teclado el número de estudiantes, el nombre de cada uno, el
código , las materias matriculadas, las notas y créditos de las mismas , y encuentre el
promedio de algún estudiante por su código, o bien un listado con todos los datos
ingresados.
#include<stdio.h>
#include<conio.h>
struct materia
{float nota;
int creditos;
};
struct alumno
{char nombre[20];
long codigo;
int materias;
struct materia m[20];
};
void llenar(struct alumno a[100],int n);
void busalumn(struct alumno a[100],int n);
void impri(struct alumno a[100],int n);
main()
{struct alumno a[100];
struct materia m[20];
int n,k;
printf("cuantos alumnos son ");
scanf("%d",&n);
llenar(a,n);
do
{
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
printf("desea saber el promedio y los datos de algun alumno marque 1 \n ");
printf("desea saber el listado de todos los alumnos marque 2 \n ");
printf("para salir marque 3 \n");
scanf("%d",&k);
if(k==1)
{
busalumn(a,n);
}
if(k==2)
{impri(a,n);
}
}while (k!=4);
getch();
return(0);
}
void llenar(struct alumno a[100],int n)
{int i,j;
for(i=0;i<n;i++)
{printf("ingrese nombre alumno %d ",i+1);
fflush(stdin);
gets(a[i].nombre);
printf("ingrese codigo alumno ");
scanf("%d",&a[i].codigo);
printf("cuantas materias tiene matriculadas ");
scanf("%d",&a[i].materias);
for(j=0;j<a[i].materias;j++)
{
printf("nota materia %d ",j+1);
scanf("%f",&a[i].m[j].nota);
printf("numero de creditos materia %d ",j+1);
scanf("%d",&a[i].m[j].creditos);
}
}
}
void busalumn(struct alumno a[100],int n)
{int i,j,sumcre,pos;
float multi,prom;
long cod;
printf ("ingrese codigo del alumno a buscar\n");
scanf("%d",&cod);
for(i=0;i<n;i++)
{
if(cod==a[i].codigo)
{sumcre=0;
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
pos=i;
multi=0;
for(j=0;j<a[i].materias;j++)
{sumcre=sumcre+a[i].m[j].creditos;
multi=multi+(a[i].m[j].nota *a[i].m[j].creditos);
}
}
}
prom=multi/sumcre;
printf("nombre de alumno\n");
puts(a[pos].nombre);
printf("el promedio del alumno es %f \n ",prom);
}
void impri(struct alumno a[100],int n)
{int i,j;
for(i=0;i<n;i++)
{printf(" nombre alumno %d\n ",i+1);
puts(a[i].nombre);
printf(" codigo alumno =%d\n ",a[i].codigo);
printf(" materias matriculadas =%d \n",a[i].materias);
for(j=0;j<a[i].materias;j++)
{printf("nota materia %d = %f\n ",j+1,a[i].m[j].nota);
printf(" creditos materia %d =%d \n",j+1,a[i].m[j].creditos);
}
}
}
5. Se quiere fumigar ciertos suelos, para ello se conoce el tipo de fumigación, nombre,
metros fumigados y la fecha. Cada tipo de fumigación tiene un valor. Tipo 1 contra coca
vale 2300 xm2, tipo 2 contra broca vale 2500xm2, tipo 3 contra hormigas vale 1500xm2,
tipo 4 contra gusanos vale 2000xm2.el programa dejara de tomar datos cuando el tipo de
fumigación sea mayor a 4.
#include<stdio.h>
#include<conio.h>
struct fecha
{int dia;
int mes;
int anio;
};
struct fumigacion
{char nombre[20];
int tipo;
int metros;
struct fecha fe;
};
int llenar(struct fumigacion f[100]);
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
void busaldo(struct fumigacion f[100],int n);
main()
{
struct fumigacion f[100];
struct fecha fe[2];
int n;
n=llenar(f);
busaldo(f,n);
getch();
return(0);
}
int llenar(struct fumigacion f[100])
{int i=0,h=0;
do
{printf("tipo de fumigacion\n 1 contra coca\n 2contra broca\n3contra hormigas\n4contra gusanos
\n");
scanf("%d",&f[i].tipo);
if(f[i].tipo>0&&f[i].tipo<5)
{printf("ingrese nombre \n"),
fflush(stdin);
gets(f[i].nombre);
printf("metros cuadrados que se van a fumigar \n");
scanf("%d",&f[i].metros);
printf("ingrese fecha\n");
printf("dia ");
scanf("%d",&f[i].fe.dia);
printf("mes ");
scanf("%d",&f[i].fe.mes);
printf("anio ");
scanf("%d",&f[i].fe.anio);
i++;
}
else
{h=1;
}
}while(h==0);
return(i);
}
void busaldo(struct fumigacion f[100],int n)
{int i,total;
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
for(i=0;i<n;i++)
{printf("nombre= \n");
puts(f[i].nombre);
printf("metros fumigados= %d\n",f[i].metros);
if(f[i].tipo==1)
{printf("fumigacion contra coca, valor por metro cuadrado = 2300");
total=f[i].metros*2300;
}
if(f[i].tipo==2)
{printf("fumigacion contra broca, valor por metro cuadrado = 2500");
total=f[i].metros*2500;
}
if(f[i].tipo==3)
{printf("fumigacion contra hormigas, valor por metro cuadrado = 1500");
total=f[i].metros*1500;
}
if(f[i].tipo==4)
{printf("fumigacion contra gusanos, valor por metro cuadrado = 2000");
total=f[i].metros*2000;
}
printf("total a pagar = %d \n",total);
printf("%d/%d/%d\n",f[i].fe.dia,f[i].fe.mes,f[i].fe.anio);
}
}
6. Se ingresan n elementos de la tabla periódica, de los cuales se conoce el nombre, símbolo
y número atómico, para posteriormente realizar la búsqueda de cualquiera de ellos por
medio de su número atómico. El programa dejara de ingresar elementos cuando el nuero
atómico sea 0, y finalizara cuando no se quiera saber más ningún dato.
Getchar(): va a pausar la ejecucion de tu programa para esperar el ingreso de un caracter por
la entrada estandar del sistema, en este caso, el teclado.
Fflush(stdin): Limpia el buffer utilizado por la entrada estandar, en este caso, el teclado.
#include<stdio.h>
#include<conio.h>
struct elemento
{char nombre[20];
char simbolo[20];
int nuato;
};
void buselem(struct elemento e[100],int n);
int llenar(struct elemento e[100]);
main()
{struct elemento e[100];
This image cannot currently be display ed.
int n,h=0;
char cd[0];
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
n=llenar(e);
do
{
printf("desea buscar algun elemento, s(si), n(no)\n");
gets(cd);
if(cd[0]=='s')
{buselem(e,n);
}
if(cd[0]=='n')
{h=1;
}
}while(h==0);
getch();
return(0);
}
int llenar(struct elemento e[100])
{int i=0,h=0;
do
{
printf("ingrese numero atomico del elemento \n");
scanf("%d",&e[i].nuato);
if(e[i].nuato!=0)
{printf("ingrese nombre del elemento\n");
fflush(stdin);
gets(e[i].nombre);
printf("ingrese simbolo del elemento\n");
gets(e[i].simbolo);
i++;
}
else
{h=1;
}
}while(h==0);
return(i);
}
void buselem(struct elemento e[100],int n)
{int i,l,nu;
printf("buscar el elemento por numero atomico\n");
printf("ingrese el numero atomico a buscar\n");
scanf("%d",&nu);
for(i=0;i<n;i++)
This image cannot currently be display ed.
UNIVERSIDAD DE PAMPLONA
PROGRAMACION II - GRUPO AR
DOCENTE: ESP. ALEXIS OLVANY TORRES CH.
SEGUNDO SEMESTRE 2011
{if(nu==e[i].nuato)
{printf("nombre del elemento\n");
puts(e[i].nombre);
printf("simbolo del elemento\n");
puts(e[i].simbolo);
printf("numero atomico %d\n",e[i].nuato);
}
}
}
Descargar