#include<conio.h>
#include<math.h>
#include<stdio.h>
#include<process.h>
#include<graphics.h>
#include<ctype.h>
double rfact(double);
void main()
{
int ch;
int k,n,choice;
float sinx,cosx,tanx,cotx,secx,cosecx;
float x,j,i;
clrscr();
cin>>ch;
if(ch==4444)
{
int gdriver=DETECT,gmode, errorcode;
initgraph(&gdriver,&gmode,"e:\\tc\\bgi");
setbkcolor(LIGHTRED);
settextstyle(7,0,9);
outtextxy(45,160,"..WELCOME!..");//page1
getch();
closegraph();
}
getch();
clrscr();
textcolor(YELLOW+128);
gotoxy(30,12);
cprintf("COMPUTER EXHIBITION\n\r");//page2
textcolor(GREEN);
gotoxy(30,14);
cprintf(" Dhanoop Bhaskar \n\r");
textcolor(BLUE);
gotoxy(30,15);
cprintf(" C2 Batch\n\r");
textcolor(CYAN);
gotoxy(30,16);
cprintf(" CARDINAL .HSS\n\r ");
textcolor(RED+128);
gotoxy(33,19);
cprintf("INSTRUCTIONS:\n\r");
textcolor(YELLOW);
gotoxy(22,20);
cprintf("\(The Scientific Calculator enables to\n\r");
gotoxy(22,21);
cprintf("Find the values of trigonometric funtions\)\n\r ");
textcolor(LIGHTGREEN);
gotoxy(22,22);
cprintf(":Please try to give appropiate values only\n\r ");
gotoxy(22,23);
cprintf(":Follow the instructions given in brackets\n\r");
gotoxy(22,24);
cprintf(":Donot attempt malpractices\n\r");
gotoxy(22,25);
cprintf(":Use only numerical values\n\r");
getch();
do
{
clrscr();
gotoxy(30,9);
textcolor(YELLOW+128) ;textbackground(RED) ;
cprintf(" SCIENTIFIC CALCULATOR \n\r");//page3
textcolor(YELLOW) ;textbackground(BLACK) ;
gotoxy(30,13);
cprintf(" MAIN MENU \n\r" );
gotoxy(30,15);
cprintf("1.SINE: \n\r");
gotoxy(30,16);
cprintf("2.COSINE: \n\r");
gotoxy(30,17);
cprintf("3.TANGENT: \n\r");
gotoxy(30,18);
cprintf("4.COTANGENT: \n\r");
gotoxy(30,19);
cprintf("5.SECANT: \n\r");
gotoxy(30,20);
cprintf("6.COSECANT: \n\r");
gotoxy(30,21);
cprintf("7.EXIT: \n\r");
cout<<"\n Enter your choice ";
cin>>choice;
if(choice<7)
{
cout<<"\n Enter the angle in degrees ";
cout<<"\n (Please enter angle between -360&+360 ) ";
cin>>i;
if(i>360||i<-360)
{
cout<<"\n Sorry!!!!... cannot find the values at present ";
getch();
exit(0);
}
x=i*0.01745;
}
switch(choice)
{
case 1:sinx=0;//sine
for(j=1,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==180||i==360)
cout<<"\n sinx="<<0;
else if(i==90)
cout<<"\n sinx="<<1;
else if(i==270)
cout<<"\n sinx="<<-1;
else
cout<<"\n sin x="<<sinx;
getch();
break;
case 2:cosx=1;//cosine
for(j=2,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==360)
cout<<"\n cosx="<<1;
else if(i==180)
cout<<"\n cosx="<<-1;
else if(i==90||i==270)
cout<<"\n cosx="<<0;
else
cout<<"\n cos x="<<cosx;
getch();
break;
case 3:sinx=0;//tangent
for(j=1,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
cosx=1;
for(j=2,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==90||i==270||cosx==0)
{
cout<<"\n tan x is not defined ";
cout<<"\n\( cosx="<<0<<" appro\)";
}
else if(i==0||i==180||i==360)
cout<<"\n tanx="<<0;
else
{
tanx=sinx/cosx;
cout<<"\n tan x="<<tanx;
getch();}
break;
case 4:sinx=0;//cotangent
for(j=1,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
cosx=1;
for(j=2,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==90||i==180||i==270||i==360||sinx==0)
{
cout<<"\n cot x is not defined ";
cout<<"\n\( sinx="<<0<<" appro\)";
}
else
{
cotx=cosx/sinx;
cout<<"\n cot x="<<cotx;
getch();
}
break;
case 5:cosx=1;//secant
for(j=2,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==90||i==270||cosx==0)
{
cout<<"\n sec x is not defined ";
cout<<"\n\( cosx="<<0<<" appro\)";
}
else if(i==0||i==360)
cout<<"\n secx="<<1;
else if(i==180)
cout<<"\n secx="<<-1;
else
{
secx=1/cosx;
cout<<"\n sec x="<<secx;
getch();
}
break;
case 6:sinx=0;//cosecant
for(j=1,k=1;j<50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==180||i==360||sinx==0)
{
cout<<"\n cosec x is not defined ";
cout<<"\n\( sinx="<<0<<" appro\)";
}
else if(i==90)
cout<<"\n cosecx="<<1;
else if(i==270)
cout<<"\n cosecx="<<-1;
else
{
cosecx=1/sinx;
cout<<"\n cosec x="<<cosecx;
getch();
}
break;
case 7:exit(0);
default:cout<<"\n Invalid choice ";
}
getch();
}while(1);
}
double rfact(double d)
{
if(d<2)
return (1);
else
return (d*rfact(d-1));
}
0 Comments