05-24-2010, 02:43 AM
Hi guys i have made a scientific calculator and just felt like sharing it with my mates.So here it goes.Its really simple programming and I have not used the concept of classes etc.Please let me know if you like it
Code:
#include <iostream.h>
#include<math.h>
#include <stdio.h>
#include<conio.h>
# define sqr(x) (x)*(x)
void main()
{
float a,b,c;
int choice, i;
clrscr();
do
{
cout<<"\n\n\nScientific calculator\n\n\n";
cout<<"\n\nEnter \n\n1.ADDITION\n\n 2.SUBTRACTION\n\n 3.MULTIPLICATION\n\n 4.DIVISION\n\n 5.SIN\n\n 6.COSINE \n\n 7.TAN\n\n 8.LOG\n\n 9.QUADRATIC EQUATUION SOLVER\n\n 10.POWER FUNCTION \n\n 11.EXPONENTIAL FUNCTION \n\n 12.PERCENTAGE \n\n 13.FACTORIAL";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\n\nADDITION";
cout<<"\n\nENTER TWO NUMBERS";
cin>>a>>b;
c=a+b;
cout<<"\n\nANSWER IS "<<c;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 2:
{
cout<<"\n\nSUBTRACTION";
cout<<"\n\nENTER TWO NUMBERS";
cin>>a>>b;
c=a-b;
cout<<"\n\nANSWER IS "<<c;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 3:
{
cout<<"\n\nMULTIPLICATION";
cout<<"\n\nENTER TWO NUMBERS";
cin>>a>>b;
c=a*b;
cout<<"\n\nANSWER IS "<<c;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 4:
{
cout<<"\n\nDIVISION";
cout<<"\n\nENTER TWO NUMBERS";
cin>>a>>b;
c=a/b;
cout<<"\n\nANSWER IS "<<c;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 5:
{
double a,b,ans;
int ch;
clrscr();
cout<<"\n\nSIN FUNCTION";
cout<<"\n\n PRESS 1 IF THE ANGLE IS IN DEGREES";
cout<<"\n\n PRESS 2 IF THE ANGLE IS IN RADIANS";
cin>>ch;
if (ch==1)
{
cout<<"\n\nENTER THE ANGLE IN DEGREES";
cin>>a;
b=(a*22)/(7*180);
}
else if (ch==2)
{
cout<<"\n\nENTER THE ANGLE IN RADIANS";
cin>>a;
b=a;
}
else
{
cout<<"\n\nERROR";
break;
}
ans=sin(b);
cout<<"\n\nTHE SIN OF "<<a<<"IS "<<ans;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 6:
{
double a,b,ans;
int ch;
clrscr();
cout<<"\n\nCOSINE FUNCTION";
cout<<"\n\n PRESS 1 IF THE ANGLE IS IN DEGREES";
cout<<"\n\n PRESS 2 IF THE ANGLE IS IN RADIANS";
cin>>ch;
if (ch==1)
{
cout<<"\n\nENTER THE ANGLE IN DEGREES";
cin>>a;
b=(a*22)/(7*180);
}
else if (ch==2)
{
cout<<"\n\nENTER THE ANGLE IN RADIANS";
cin>>a;
b=a;
}
else
{
cout<<"\n\nERROR";
break;
}
ans=cos(b);
cout<<"\n\nTHE COSINE OF "<<a<<"IS "<<ans;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 7:
{
double a,b,ans;
int ch;
clrscr();
cout<<"\n\nTAN FUNCTION";
cout<<"\n\n PRESS 1 IF THE ANGLE IS IN DEGREES";
cout<<"\n\n PRESS 2 IF THE ANGLE IS IN RADIANS";
cin>>ch;
if (ch==1)
{
cout<<"\n\nENTER THE ANGLE IN DEGREES";
cin>>a;
b=(a*22)/(7*180);
}
else if (ch==2)
{
cout<<"\n\nENTER THE ANGLE IN RADIANS";
cin>>a;
b=a;
}
else
{
cout<<"\n\nERROR";
break;
}
ans=tan(b);
cout<<"\n\nTHE TAN OF "<<a<<"IS "<<ans;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 9:
{
float A,B,C,delta;
clrscr();
cout<<"\nQUADRATIC EQUATION SOLVER";
cout<<"\nENTER COEFFICIENTS";
cout<<"A ";
cin>>A;
cout<<"B ";
cin>>B;
cout<<"C ";
cin>>C;
if (A==0 && B!=0)
{
cout<<"\n\nTHIS IS A FIRST DEGREE EQUATION";
cout<<"\n\nTHE SOLUTION IS "<<-C/B;
}
else if(A==0&&B==0)
{
cout<<"\n\nTHIS EQUATION HAS NO SOLUTION";
}
else
{
delta=sqr(B)-4*A*C;
if (delta<0)
{
cout<<"\n\nTHIS EQUATION HAS NO REAL ROOTS";
}
else if(delta==0)
{
cout<<"\n\nTHIS EQUATION HAS DOUBLE ROOTS ";
cout<<"\n\nAND THE ROOTS ARE : "<<-B/2*A;
}
else
{
cout<<"\n\nTHIS EQUATION HAS TWO REAL ROOTS";
float X1 =(-B+sqrt(delta))/(2*A);
float X2 =(-B-sqrt(delta))/(2*A);
cout<<" X1 ="<<X1;
cout<<" X2 ="<<X2;
}
}
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 8:
{
cout<<"\n\nLOG";
double a,ans;
int ch;
cout<<"\n1.NATURAL LOG \n2.LOG TO THE BASE 10";
cin>>ch;
if(ch==1)
{
cout<<"\n\nENTER VALUE ";
cin>>a;
ans=log(a);
cout<<"\n\nTHE VALUE OF THE LOG IS "<<ans;
}
if (ch==2)
{
cout<<"\n\nENTER VALUE ";
cin>>a;
ans=log10(a);
cout<<"\n\nTHE VALUE OF THE LOG TO THE BASE 10 IS "<<ans;
}
else
{
cout<<"\n\nERROR!!";
}
break;
}
case 10:
{
float m,n,p;
clrscr();
cout<<"\n\nPOWER FUNCTION";
cout<<"\n\nENTER THE VALUES OF m AND n W.R.T THE EQUATION m^n ";
cin>>m>>n;
p=pow(m,n);
cout<<"\n\nTHE ANSWER IS "<<p;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 11:
{
float r,s;
clrscr();
cout<<"\n\nEXPONENTIAL FUNCTION";
cout<<"\n\nENTER VALUE";
cin>>r;
s=exp(r);
cout<<"\n\nTHE ANSWER IS "<<s;
cout<<"\n\nTHANK YOU COME AGAIN";
break;
}
case 12:
{
float x,y,z;
cout<<"\n\nPERCENTAGE";
cout<<"\n\nPLEASE ENTER THE VALUES OF X AND Y W.R.T THE EQUATION (X/Y)*100 ";
cin>>x>>y;
z=x/y*100;
cout<<"\n\nTHE ANSWER IS "<<z;
cout<<"THANK YOU COME AGAIN";
break;
}
case 13:
{
int u,v,fact;
cout<<"\n\nFACTORIAL";
cout<<"\n\nENTER THE NUMBER ";
cin>>u;
fact=1;
for (v=u;v>=1;v--)
fact=fact*v;
cout<<"\n\nTHE ANSWER IS "<<fact;
break;
}
default:
{
cout<<"\n\nERROR!!";
break;
}
}cout<<"\n\nENTER 1 TO CONTINUE.0 TO EXIT";
cin>>i;
}
while (i==1);
getch();
}