Está en la página 1de 7

EJERCICIOS SOBRE ESTRUCTURAS DE DATOS

1. DADA LA SIGUIENTE ESTRUCTURA DE DATOS:

Lado 1
Triangulo Lado 2
Lado3

REALIZAR ANÁLISIS E IMPLEMENTAR UN PROGRAMA C++ FUNCIONAL


CON PROTOTIPOS Y VARIABLES GLOBALES PARA DETERMINAR SI
LOS LADOS FORMAN UN TRIÁNGULO EQUILÁTERO, ISÓSCELES O
ESCALENO. DEBE REALIZAR TODO LOS CONTROLES QUE EL CASO
REQUIERA.

ANÁLISIS
Se debe determinar los lados de un triangulo con estructura de datos.
DATOS DE ENTRADA
 Se debe declarar los tres lados del triángulo.
 Utilizar los tipos de dato estructura con la palabra reservada struct
 Se debe llamar a la llamada recursiva.
DATOS DE SALIDA
 Se debe imprimir para los tres lados.
 Se debe realizar las comparaciones.
 cuando los tres lados son iguales (equilátero).
 cuando los dos lados son iguales y uno distinto (isósceles).
 cuando los tres lados son distintos (escaleno).

# include <iostream>
using namespace std;
struct triangulo
{
int l1,l2,l3;
};
struct triangulo t;
void leer();
void proceso();
int main()
{
leer();
proceso();
}
void leer()
{
cout<<"\n\t\t INGRESE EL PRIMER LADO: "; cin>>t.l1;
cout<<"\n\t\t INGRESE EL SEGUNDO LADO: "; cin>>t.l2;
cout<<"\n\t\t INGRESE EL TERCER LADO: "; cin>>t.l3;
if(t.l1<=0 ||t.l2<=0 ||t.l3<=0 )
{
cout<<"\n\t\t ERROR UNO O MAS LADOS NO SON
PERMITIDOS";
cout<<"\n\t\t DEBE INTRODUCIR VALORES POSITIVOS PARA LOS
LADOS DEL TRIANGULO:""\n";
leer(); //llamada recursiva
}
}
void proceso()
{
if(t.l1==t.l2&&t.l1==t.l3&&t.l2==t.l3){
cout<<"\n\t\t __________________________ ";
cout<<"\n\t\t El triangulo es equilatero "; //cuando los tres lados son
iguales
cout<<"\n\t\t __________________________ ";
}
else if(t.l1==t.l2||t.l1==t.l3&&t.l2==t.l3){
cout<<"\n\t\t ________________________ ";
cout<<"\n\t\t El triangulo es isoceles ";//cuando los dos lados son
iguales y uno distinto
cout<<"\n\t\t ________________________ ";
}
else {
cout<<"\n\t\t ________________________ ";
cout<<"\n\t\t El triangulo es escaleno ";//cuando los tres lados son
distintos
cout<<"\n\t\t ________________________ ";
}
}

CAPTURA DE PANTALLA
2. DADA LA SIGUIENTE ESTRUCTURA DE DATOS:

Nombre y apellidos
Haber Básico (Bs. 2445)
Bono Antigüedad: 17.4% del Haber Básico
Empleado Bono de Producción: 26.5% del Haber Básico
Descuento AFP: 10% del Haber Básico
Federación: 0.5% del Haber Básico
Líquido Pagable.
REALIZAR ANÁLISIS E IMPLEMENTAR PROGRAMA C++ FUNCIONAL,
SIN PROTOTIPOS Y VARIABLES GLOBALES PARA CALCULAR EL
TOTAL GANADO, EL TOTAL DE LOS DESCUENTOS Y EL LÍQUIDO
PAGABLE. LUEGO IMPRIMIR LA BOLETA CON TODA LA INFORMACIÓN
PROCESADA. EL HABER BÁSICO DEBE CONTROLARSE, DEBE ESTAR
ENTRE 1800 Y 2500 BS.

ANÁLISIS
Se debe determinar que datos y sentencias utilizara.
DATOS DE ENTRADA
 Se debe declarar el tipo de dato estructura con la palabra reservada
struct.
 Se debe declarar las variables de tipo estructura:
char nom[30];
int hb;
float boant, boprod, desafp, fede, tg, tdes, lp;
 se debe de realizar control al haber básico con la sentencia condicional
if.

DATOS DE SALIDA
 Se debe imprimir una boleta con todos con todos los datos utilizados.

#include <iostream>
#include <stdio.h>

using namespace std;

struct empleado
{
char nom[30];
int hb;
float boant, boprod, desafp, fede, tg, tdes, lp;
};

struct empleado em;

void leer()
{

cout<<"\n\n\t\t\t\t REGISTRO SALARIAL ";


cout<<"\n\n\tINGRESE NOMBRE Y APELLIDO DEL
EMPLEADO: ";
gets(em.nom);
cout<<"\n\n\tINGRESE EL HABER BASICO DEL
EMPLEADO: ";
cin>>em.hb;
// Controlando el haber basico

if(em.hb<1800||em.hb>2500)
{
cout<<"\n\tError el haber basico no puede ser menor
a 1800 y mayor a 2500";
cout<<"\n\tIngrese la cantidad en los rangos
establecidos en le mensaje: ";
leer();
}
}

void calcular()
{

em.boant = (em.hb * 17.4)/100;


em.boprod = (em.hb * 26.5)/100;
em.desafp = em.hb * 0.1;
em.fede = em.hb * 0.5;

em.tg = (em.hb + em.boant + em.boprod + em.fede);


em.tdes= em.desafp;
em.lp= em.tg-em.tdes;
}

void mostrar()
{

cout<<"\n\n\n\t ******************** BOLETA DE IMPRESION


*****************\n";
cout<<"\n\n\t\tNOMBRE Y APELLIDO :" <<em.nom;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tHABER BASICO :" <<em.hb;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tBONO ANTIGUEDAD :" <<em.boant;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tBONO DE PRODUCCION :" <<em.boprod;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tDESCUENTOS AFP :" <<em.desafp;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tFEDERACION :" <<em.fede;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tTOTAL GANADO :" <<em.tg;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tTOTAL DESCUENTO :" <<em.tdes;
cout<<"\n\t\t___________________________________________",
cout<<"\n\n\t\tLIQUIDO PAGABLE :" <<em.lp;
cout<<"\n\n\n\t ----------------------------------------------------------\n";
}

int main()
{
leer();
calcular();
mostrar();
}

CAPTURA DE PANTALLA

También podría gustarte