MENU2.H

(Descarga Código fuente y grabalo en el archivo include del TC)

 

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define M 200

/********** Funcion que Envia por el puerto paralelo (Protocolo) *******/
void sale(double n)
{
}

/********** Funcion que Recibe del puerto paralelo (Protocolo) *********/
double entra()
{
double n;
return(n);
}

/***********************************************************************/

/* Estructura time:
struct time {
unsigned char ti_min; ----> minutes
unsigned char ti_hour; ----> hours
unsigned char ti_hund; ----> hundredths of seconds
unsigned char ti_sec; ----> seconds
};
*/

/***************** Funcion que calcula el Tiempo ***********************/

void calcula(struct time t1,struct time t2,int y)
{
int horas,minutos,segundos,milisec;
horas=t2.ti_hour-t1.ti_hour;
minutos=t2.ti_min-t1.ti_min;
if(minutos<0)
{
horas=horas-1;
minutos=minutos+60;
}
segundos=t2.ti_sec-t1.ti_sec;
if(segundos<0)
{
minutos=minutos-1;
segundos=segundos+60;
}
milisec=t2.ti_hund-t1.ti_hund;
if(milisec<0)
{
segundos=segundos-1;
milisec=milisec+100;
}
gotoxy(y,22);printf("%2d : %02d : %02d.%02d",t1.ti_hour,t1.ti_min,t1.ti_sec,t1.ti_hund);
gotoxy(y,23);printf("%2d : %02d : %02d.%02d",t2.ti_hour,t2.ti_min,t2.ti_sec,t2.ti_hund);
gotoxy(y,24);printf("%2d : %02d : %02d.%02d",horas,minutos,segundos,milisec);
}

/******************** Funcion que Calcula el Factorial *****************/

double fa(double a)
{
double i,rr=1;
for(i=1;i<=a;i++)
{
rr=i*rr;
}
return(rr);
}

/****** Funcion que realiza la suma total entre los intervalos *********/


double sum(double i,double s)
{
double rr=0,f;
for(;i<=s;i++)
{
f=pow(-1,i);
rr=(f*i)+rr;
delay(10);
}
return(rr);
}

/***********************************************************************/

double mu(double i,double s)
{
double rr=1;
for(;i<=s;i++)
{
rr=rr*i;
delay(15);
}
return(rr);
}

double poten(double i,double s, double a, double x)
{
double rr=0,n;
for(;i<=s;i++)
{
n=x-a;
rr=i*pow(n,i)+rr;
delay(15);
}
return(rr);
}

double ex(double i,double s)
{
double rr=0,f;
for(;i<=s;i++)
{
f=pow(-1,i+1);
rr=(f/fa(i))+rr;
delay(15);
}
return(rr);
}

double divi(double n[5], int op)
{
double rr=0,y;
sale(op);
y=(n[0]+n[1])/2;
switch(op)
{
case 49:rr=sum(n[0],n[0]+y);
sale(n[0]+y+1);
sale(n[1]);
rr=entra()+rr;
break;
case 50:rr=mu(n[0],n[0]+y);
sale(n[0]+y+1);
sale(n[1]);
rr=entra()+rr;
break;
case 51:rr=poten(n[0],n[0]+y,n[2],n[3]);
sale(n[0]+y+1);
sale(n[1]);
sale(n[2]);
sale(n[3]);
rr=entra()+rr;
break;
case 52:rr=ex(n[0],n[0]+y);
sale(n[0]+y+1);
sale(n[1]);
rr=entra()+rr;
break;
case 27:exit(1);
}
return(rr);
}

/***********************************************************************/

void borde(int n,int y)
{
int i;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
for(i=2;i<5;i++)
{
setcolor(y);
rectangle(i,i,getmaxx()-i,getmaxy()-n-i);
setcolor(3);
rectangle(10+i,15+i,30,30);
rectangle(getmaxx()-30,getmaxy()-15-n-i,getmaxx()-10-i,getmaxy()-30-n);
rectangle(10+i,getmaxy()-15-n-i,30,getmaxy()-30-n);
rectangle(getmaxx()-30,15+i,getmaxx()-10-i,30);
} //max x = 639 y max y =479
/* rectangulo de dimensiones (izquierda,arriba,derecha,abajo) */
//closegraph();
}

void menu1(char *a)
{
int gdriver = DETECT, gmode, errorcode;
int i;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
_setcursortype(_NOCURSOR);
cleardevice();
borde(20,2);
settextstyle(DEFAULT_FONT,0,0);
setcolor(3);
outtextxy(getmaxx()-50,getmaxy()-15,"FJL");
circle(getmaxx()-18,getmaxy()-6,6);
outtextxy(getmaxx()-21,getmaxy()-9,"R");
settextstyle(DEFAULT_FONT,0,3);
setcolor(7);
outtextxy(100,100,"PC's EN PARALELO" );
setcolor(1);
settextstyle(DEFAULT_FONT,0,8);
outtextxy(170,200,"PC");
outtextxy(300,200,a);
settextstyle(DEFAULT_FONT,0,0);
setcolor(9);
outtextxy(300,360,"PROFESOR: LUIS ESCOBAR");
outtextxy(300,370,"AYUDANTE: OSCAR ROJAS D.");
outtextxy(300,385,"CREADO POR:");
outtextxy(420,385,"FELIPE GATICA R.");
outtextxy(420,395,"LORETO ARIAS F.");
outtextxy(420,405,"JIMENA MONJES W.");
for(i=1;i<getmaxx()-58;i=i+2)
{
outtextxy(i,getmaxy()-15,"H");
delay(10);
}
closegraph();
}


int menu2()
{
int gdriver = DETECT, gmode, errorcode;
int i;
int op;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
_setcursortype(_NOCURSOR);
cleardevice();
setcolor(BLUE);
setbkcolor(BLACK);
borde(0,9);
for(i=2;i<5;i++)
{
rectangle(230+i,70+i,365-i,102-i);
}
gotoxy(33,6); printf("OPERACIONES");
gotoxy(24,12);printf(" <1> SUMATORIA DE UNA FUNCION");
gotoxy(24,13);printf(" <2> MULTIPLICATORIA DE UNA FUNCION");
gotoxy(24,14);printf(" <3> SERIE DE POTENCIA");
gotoxy(24,15);printf(" <4> FUNCION EXPONENCIAL (SUMATORIA)");
setcolor(RED);
for(i=2;i<5;i++)
{
rectangle(210+i,376+i,380-i,408-i);
}
gotoxy(30,25);printf("<ESC> PARA SALIR");
op=getch();
//closegraph();
return(op);
}

/***********************************************************************/
void sumatoria(int i)
{
line(150,i,135,i+8);
line(135,i+8,145,i+10);
line(145,i+10,135,i+19);
line(135,i+19,152,i+21);
}

void suma()
{
/************************ declaraciones ********************************/
struct time t1,t2;
int gdriver = DETECT, gmode, errorcode;
char i[3],s[3],p[3];
int op=1;
double rr=0,f,n[5],r2;
/******************* Inicializacion del modo grafico *******************/
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
_setcursortype(_NOCURSOR);
/*********************** Inicio de la funcion **************************/
do{
borde(0,3);
sumatoria(50);
outtextxy(140,40,"s");
outtextxy(140,80,"i");
settextstyle(DEFAULT_FONT,0,2);
outtextxy(160,60,"(-1)^i x i");
fflush(stdin);
gotoxy(10,8);printf("Ingrese Limite Inferior (i): ");scanf("%s",i);
gotoxy(10,9);printf("Ingrese Limite Superior (s): ");scanf("%s",s);
sumatoria(160);
settextstyle(DEFAULT_FONT,0,0);
n[0]=atol(i);
n[1]=atol(s);
if(n[0]<=n[1])
{
strcpy(p,"i=");
strcat(p,i);
outtextxy(140,150,s);
outtextxy(133,190,p);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(160,170,"(-1)^i x i");
gettime(&t1);
rr=sum(n[0],n[1]);
gettime(&t2);
calcula(t1,t2,15);
gettime(&t1);
r2=divi(n,49); // aqui se envia la mitad de los datos al puerto paralelo
// y se trabaja la otra mitad!!
gettime(&t2);
calcula(t1,t2,40);
op=0;
gotoxy(45,11);printf("= %.2lf (1 PC)",rr);
gotoxy(45,12);printf("= %.2lf (2 PCs)",r2);
gotoxy(16,20);printf("TIEMPO 1 PC:");
gotoxy(40,20);printf("TIEMPO 2 PC's:");
getch();
}
}while(op!=0);
closegraph();
}

void multipli(int i)
{
line(150,i,150,i+20);
line(165,i,165,i+20);
line(148,i-2,167,i-2);
}

void multi()
{
struct time t1,t2;
int gdriver = DETECT, gmode, errorcode;
char i[3],s[3],p[3];
int op=1;
double rr=1,f,n[5],r2;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
_setcursortype(_NOCURSOR);
do{
cleardevice();
borde(0,3);
multipli(50);
outtextxy(147,38,"s");
outtextxy(147,78,"i");
settextstyle(DEFAULT_FONT,0,2);
outtextxy(172,60,"i");
gotoxy(10,8);printf("Ingrese Limite Inferior (i): ");scanf("%s",i);
gotoxy(10,9);printf("Ingrese Limite Superior (s): ");scanf("%s",s);
multipli(160);
settextstyle(DEFAULT_FONT,0,0);
n[0]=atol(i);
n[1]=atol(s);
if(n[0]<=n[1])
{
strcpy(p,"i=");
strcat(p,i);
outtextxy(147,150,s);
outtextxy(142,190,p);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(170,170,"i");
gettime(&t1);
rr=mu(n[0],n[1]);
gettime(&t2);
calcula(t1,t2,15);
gettime(&t1);
r2=divi(n,50); // aqui se envia la mitad de los datos al puerto paralelo
// y se trabaja la otra mitad!!
gettime(&t2);
calcula(t1,t2,40);
op=0;
gotoxy(45,11);printf("= %.2lf (1 PC)",rr);
gotoxy(45,12);printf("= %.2lf (2 PCs)",r2);
gotoxy(16,20);printf("TIEMPO 1 PC:");
gotoxy(40,20);printf("TIEMPO 2 PC's:");
getch();
}
}while(op!=0);
closegraph();
}

void potencia()
{
int gdriver = DETECT, gmode, errorcode;
double n[5],rr=0,r2;
int op=1;
char i[3],s[3],p[4],a[3],x[3],t[10];
struct time t1,t2;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
_setcursortype(_NOCURSOR);
do{
borde(0,3);
sumatoria(50);
outtextxy(140,40,"s");
outtextxy(140,80,"i");
settextstyle(DEFAULT_FONT,0,2);
outtextxy(160,60,"i x (X - a)^i");
gotoxy(10,8);printf("Ingrese Limite Inferior (i): ");scanf("%s",i);
gotoxy(10,9);printf("Ingrese Limite Superior (s): ");scanf("%s",s);
gotoxy(10,10);printf("Ingrese Valor Para A : ");scanf("%s",a);
gotoxy(10,11);printf("Ingrese Valor Para X : ");scanf("%s",x);
sumatoria(200);
settextstyle(DEFAULT_FONT,0,0);
n[0]=atol(i);
n[1]=atol(s);
n[2]=atol(a);
n[3]=atol(x);
if(n[0]<=n[1])
{
strcpy(t,"i x ");
strcat(t,"(");
strcat(t,x);
strcat(t," - ");
strcat(t,a);
strcat(t,")^i");
strcpy(p,"i=");
strcat(p,i);
outtextxy(140,190,s);
outtextxy(133,230,p);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(160,210,t);
gettime(&t1);
rr=poten(n[0],n[1],n[2],n[3]);
gettime(&t2);
calcula(t1,t2,15);
gettime(&t1);
r2=divi(n,51); // aqui se envia la mitad de los datos al puerto paralelo
// y se trabaja la otra mitad!!
gettime(&t2);
calcula(t1,t2,40);
op=0;
gotoxy(51,13);printf("= %.2lf (1 PC)",rr);
gotoxy(51,14);printf("= %.2lf (2 PCs)",r2);
gotoxy(16,20);printf("TIEMPO 1 PC:");
gotoxy(40,20);printf("TIEMPO 2 PC's:");
getch();
}
}while(op!=0);
closegraph();
}

void exponencial()
{
int gdriver = DETECT, gmode, errorcode;
double n[5],rr=0,f,r2;
int op=1;
char i[3],s[3],p[4],t[10],u[5];
struct time t1,t2;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr();
printf("Error de Grafica : %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
_setcursortype(_NOCURSOR);
do{
fflush(stdin);
borde(0,3);
sumatoria(50);
outtextxy(140,40,"s");
outtextxy(140,80,"i");
settextstyle(DEFAULT_FONT,0,2);
outtextxy(160,55,"(-1)^(i + 1)");
outtextxy(160,65,"-----------");
outtextxy(160,75," i!");
gotoxy(10,8);printf("Ingrese Limite Inferior (i): ");scanf("%s",i);
gotoxy(10,9);printf("Ingrese Limite Superior (s): ");scanf("%s",s);
n[0]=atol(i);
n[1]=atol(s);
sumatoria(200);
if(n[0]<=n[1])
{
strcpy(p,"i=");
strcat(p,i);
strcpy(u,"i");
strcat(u,"!");
settextstyle(DEFAULT_FONT,0,0);
outtextxy(140,190,s);
outtextxy(133,230,p);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(160,210,"(-1)^(i+1)");
outtextxy(160,220,"----------");
outtextxy(195,230,u);
gettime(&t1);
rr=ex(n[0],n[1]);
gettime(&t2);
calcula(t1,t2,15);
gettime(&t1);
r2=divi(n,52); // aqui se envia la mitad de los datos al puerto paralelo
// y se trabaja la otra mitad!!
gettime(&t2);
calcula(t1,t2,40);
op=0;
gotoxy(51,13);printf("= %.2lf (1 PC)",rr);
gotoxy(51,14);printf("= %.2lf (2 PCs)",r2);
gotoxy(16,20);printf("TIEMPO 1 PC:");
gotoxy(40,20);printf("TIEMPO 2 PC's:");
getch();
}
}while(op!=0);
closegraph();
}