Vous êtes sur la page 1sur 3

#include <stdio.

h>
#include <string.h>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
using namespace std;
class factorial
{
public:
long int funfact( int n);
};

struct datos
{
char nombre[30];
int edad;
char sexo[2];
float sueldo;
} empleado;
struct datos persona[50];
struct datos *apuntad; // SE ASIGNA LA ESTRUCTURA A UN APUNTADOR
class estructuras
{
public:
void leer_datos(int *cuenta);
void mostrar_datos(int *cuenta);
};

int main(void)
{
int op;
cout<<"Escoja el programa que quieres ejecutar"<<endl<<"1.-Factorial"<<endl
<<"2.-Factorial 2"<<endl<<"3.-Estructura"<<endl<<"4.-Salir"<<endl;
cin>>op;

if(op==1)
{
char si;
long int factor ;
int numfact,i;
cout.setf(ios::fixed);
system("cls");
inicio:
factor =1;
cout <<endl<< " \n INDICA EL NUMERO DEL CUAL QUIERES OBTENER SU FACTORIAL ";
cin >> numfact;
for (i=numfact ; i>0 ; i--) factor = factor *i;
if (factor <= 0 )
{
cout <<" \n *** Error se excedio la capacidad de almacenamiento"
<<" de un entero largo *** \n";
system ("pause") ; goto fin;
}
cout <<endl << " EL FACTORIAL DE " << numfact<< " es = " <<factor<< endl;
fin:
cout << " \n � QUIERE CALCULAR OTRO FACTORIAL ? "; si =getch();
if (si == 's' || si == 'S') goto inicio;
return 0;
}

if(op==2)
{
char si;
long int factor;
int numfact;
factorial facto;
cout.setf(ios::fixed);
system("cls");
inicio1:
cout <<endl<< " \n INDICA EL NUMERO DEL CUAL QUIERES OBTENER SU FACTORIAL ";
cin >> numfact;
factor = facto.funfact(numfact);
if (factor <= 0 )
{
cout <<" \n *** Error se excedio la capacidad de almacenamiento"
<<" de un entero largo *** \n";
system ("pause") ; goto fin1;
}
cout <<endl << " EL FACTORIAL DE " << numfact<< " es = " <<factor<< endl;
fin1:
cout << " \n � QUIERE CALCULAR OTRO FACTORIAL ? "; si =getch();
if (si == 's' || si == 'S') goto inicio1;
return 0;

if(op==3)
{
int cuenta=0;
estructuras estru;
estru.leer_datos(&cuenta);
estru.mostrar_datos(&cuenta);
}
while ( op != 4 );

long int factorial::funfact (int n)


{
long int acum;
if(n==0) return 1;
acum = funfact(n-1) *n ; // AUTOLLAMADO DE LA FUNCION
return acum;
}

void estructuras::leer_datos(int *cuenta2)


// FUNCION QUE LEE LOS DATOS DE PERSONAS DE MANERA CONSECUTIVA
{
char si[2];
int cuenta;
system ("cls");
cuenta= 0;
persona[cuenta].nombre[0]= '*';
while (persona[cuenta].nombre[0] !='\0')
{
gets(si); // LECTURA EN FALSO
cout <<" cual es el nombre de la persona ?";
cuenta ++;
gets( persona[cuenta].nombre);
if (persona[cuenta].nombre[0] !='\0')
{
cout << "cual es su edad ? ";
cin >> persona[cuenta].edad;
cout << " sexo ? ";
cin >>persona[cuenta].sexo;
cout << " cuanto gana : ",persona[cuenta].nombre;
cin >> persona[cuenta].sueldo;
cout <<"\n";
}
}
// ****** asignacion de un elemento de estructura en arrgeglo a una estructura
simple
*cuenta2= cuenta-1;
apuntad = &persona[*cuenta2];
cout << endl<< "COMPROBACION DE LA PRIMERA ASIGNACION "<< endl ;
cout << " edad: " << apuntad-> edad <<endl;
cout << " nombre: " << apuntad-> nombre <<endl; system ("pause");

// ***** asignacion de una estrcutura simple a un elemento de una estrcutura en


arreglo
persona[*cuenta2] = *apuntad;
cout <<endl << "COMPROBACION DE LA SEGUNDA REASIGNACION" << endl;
cout <<endl<< " nombre: " << persona[*cuenta2].nombre << endl ;
cout << endl<< " edad: " << persona [*cuenta2].edad ;
cout << endl <<" sueldo: " << persona [*cuenta2].sueldo <<endl;
system ("pause");
}

void estructuras:: mostrar_datos(int *cuenta2)


{
int cuenta,i;
cuenta = *cuenta2;
system("cls");
cout << " LISTA DE NOMBRES EN FORMA DE TABLA \n";
cout <<" N O M B R E SUELDO EDAD SEXO \n";
for (i= 1 ; i<= cuenta; i++)
{
printf("%-30s ",persona[i].nombre);
printf(" %9.2f ",persona[i].sueldo);
printf(" %3d ",persona[i].edad);
printf(" %1s ",persona[i].sexo);

printf("\n");
}
system("pause");
}

Vous aimerez peut-être aussi