Beruflich Dokumente
Kultur Dokumente
In
1
SCIENTIFIC CALCULATOR
2
ACKNOWLEDGMENT
First and the foremost I would like to
thank to my almighty for giving me
courage to
a word of thanks to my teacher, friends
and other sources that gave an unending
support and helped me in numerous ways
from the first stage of my term
assignment conceived.
I would also like to thank my family
members for their whole hearted support
and cooperation.
I duly acknowledge the contribution of
Ms.Sukhdilpreet Kaur for invaluable help.
Coding scientific calculator is an uphill
task and would have not been possible
without proper and timely assistance of
Ms.Sukhdilpreet Kaur.
I would also thanks to all my friends for
forwarding their suggestions to make
necessary modifications.
3
Special thanks to Ms.Sukhdilpreet
Kaur for her able guidance in my
term assignment.
TABLE OF CONTENTS
1. Introduction
2. Basic function
3. Proposed system
i. Description
ii. System requirements
4. System Design
5. Source code
6. Testing
7. Future scope of project
4
INTRODUCTION
Scientific Calculator
The calculator is written in JavaScript and you are welcome to view the
JavaScript source (visible within the HTML page) for personal
educational purposes as long as you recognize that it is copyrighted and
not in the public domain. This calculator is now available as part of
Hummingbird's Enterprise Information Portal. All enquiries regarding
licensing the calculator should be directed to Hummingbird Ltd.
5
Basic Functions
Addition
The addition (sum function) is used by clicking on the "+" button or using the keyboard. The
function results in a+b.
Subtraction
The subtraction (minus function) is used by clicking on the "-" button or using the keyboard. The
function results in a-b.
Multiplication
The multiplication (times function) is used by clicking on the "x" button or using the keyboard
"*" key. The function results in a*b.
Division
The division (divide function) is used by clicking on the "/" button or using the keyboard "/" key.
The function results in a/b.
Sign
The sign key (negative key) is used by clicking on the "(-)" button. The function results in -1*x.
Square
The square function is used by clicking on the "x^2" button or type "^2". The function results in
x*x.
Square Root
The square root function is used by clicking on the "x" button or type "sqrt()". This function
represents x^.5 where the result squared is equal to x.
The raise to the power (y raised to the x function) is used by clicking on the "y^x" button or type
"^".
6
Natural Exponential
The natural exponential (e raised to the x) is used by clicking on the "e^x" button or type
"exp()". The result is e (2.71828...) raised to x.
Logarithm
The logarithm (LOG) is used by clicking on the "LOG" button or type "LOG()".
Natural Logarithm
The Natural logarithm (LN) is used by clicking on the "LN" button or type "LN()".
Inverse
Multiplicative inverse (reciprocal function) is used by pressing the "1/x" button or typing "inv()".
This function is the same as x^-1 or dividing 1 by the number.
Exponent
Numbers with exponents of 10 are displayed with an "e", for example 4.5e+100 or 4.5e-100.
This function represents 10^x. Numbers are automatically displayed in the format when the
number is too large or too small for the display. To enter a number in this format use the
exponent key "EEX". To do this enter the mantissa (the non exponent part) then press "EEX" or
type"e" and then enter the exponent.
Factorial
The Factorial function is used by clicking the "!" button or type "!".
PI
7
PROPOSED SYSTEM
DESCRIPTION
PROBLEM STATEMENT
The system will be user friendly and completely menu driven so that the
users shall have no problem in using all options.
Language: C Language
8
SYSTEM DESIGN
9
START
Enter
Your
Choice?
On Do your any
calculator task
Trignometery(sin,c Inverse(1/
os) x)
Ye
s Do you want
to continue?
No
Switch off
calculator
STOP
10
CODING
#include<string.h>
#include<mouse.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdio.h>
#include<alloc.h>
#define pi 3.1415265
long com(long,int);
long double back(long double),equ(),alg(long double,int);
double ns(long double,int);
int box(int,int,int,int,int);
char *z2;
long double *z1;
int xy1[3];
x=getmaxx();y=getmaxy();
setcolor(BLACK);setfillstyle(1,LIGHTGRAY);
rectangle(20,20,x-20,y-20); //grey calculator body
floodfill(50,50,BLACK);
setcolor(BLUE);setfillstyle(1,BLUE);
rectangle(21,20,x-21,40);
floodfill(25,25,BLUE); /* blue quit rectangle*/
11
setcolor(BLACK);
outtextxy(x/5,8,"Scientific Calculator by-: Akash(02512) & Akhil(02514)");
initmouse();
showmouse();
setmouse(0,0);
setcolor(WHITE);setfillstyle(1,WHITE);
rectangle(30,55,x-30,70); //---white i/o box
floodfill(32,59,WHITE);
/*------------------printing nos.---------------------*/
i=0;
for(x1=40;x1<150;x1+=30)
{ j=0;
for(y1=100;y1<450;y1+=40)
{
box(x1,y1,40,WHITE,BLACK);
setcolor(BLUE);
if(i==1&&j==10)
outtextxy(x1+10,y1+20,no[i+j]);
else
outtextxy(x1+15,y1+20,no[i+j]);
y1+=20; j+=2;
}
i++;
x1+=40;
}
/*---------------------------------------------------------------*/
for(x1;x1<=180;x1+=40)
{ j=0;
for(y1=100;y1<450;y1+=40) /*x1=180*/
{
box(x1,y1,40,WHITE,BLACK);
setcolor(BLUE);
outtextxy(x1+15,y1+20,cal[j]);
y1+=20;
j++;
}
}
x1+=30;
/*-----------------------------------------------------------------*/
12
i=0;
for(x1;x1<501;x1+=30)
{ j=0;
for(y1=100;y1<450;y1+=40)
{
box(x1,y1,70,WHITE,BLACK); /*x1=220*/
setcolor(BLUE);
outtextxy(x1+15,y1+20,sci[i+j]);
y1+=20; j+=3;
}
xy1[i]=x1; /*store X coordinates*/
i++;
x1+=70;
}
/*-----------------------------------------------------------------*/
/*-----------MOUSE PROGRAMMING------------*/
mouse()
{
int button,x,y;
char s[13]={" "};
int x1,y1,i,j,flag=1,l;
long double n,k;
while(!kbhit())
{ Again:
getmouse(&button,&x,&y);
while(button==1)
{
getmouse(&button,&x,&y);
sr=1;
}
13
if(sr==1)
{
i=0;
sr=0;
if(x>=xy1[0]&&x<=(xy1[0]+70)) /*fourth column check*/
{
colm1(n,y);
dpf=0;
strcpy(s," ");
}
if(x>=xy1[1]&&x<=(xy1[1]+70)) /*fifth column check*/
{
colm2(n,y);
dpf=0;
strcpy(s," ");
}
if(x>=xy1[2]&&x<=(xy1[2]+70)) /*sixth column check*/
{
colm3(n,y);
dpf=0;
strcpy(s," ");
}
for(x1=40;x1<150;x1+=30) //1st & 2nd column check
{ j=0; setcolor(DARKGRAY);
for(y1=100;y1<450;y1+=40)
{ if(x>=x1 && y>=y1 && x<=x1+40 && y<=y1+40)
{ box(x1,y1,40,BLACK,WHITE);
delay(200);
box(x1,y1,40,WHITE,BLACK);
if((strcmp(no[i+j],no[11]))==0)
{ if(flag==1)
{ n*=-1; // +/- sign
s[0]='-';
flag=0;
}
else
{ n*=-1;
s[0]=' ';
setcolor(LIGHTGRAY);
setfillstyle(1,WHITE);
floodfill(32,59,LIGHTGRAY);
flag=1;
}
goto NEXT;
if(strlen(s)>=11)
goto Again;
if((strcmp(no[i+j],no[10]))==0)
{
if(dpf==0)
{
strcat(s,no[i+j]); //save no. to string s
dpf=1;
14
}
}
else
strcat(s,no[i+j]); //save no. to string
s
NEXT:
n=_atold(s); //array to long double
setcolor(DARKGRAY);
outtextxy(30,60,s); // display no. in i/o box
goto Again;
}
y1+=20; j+=2;
}
i++;
x1+=40;
}
box(180,400,40,BLACK,WHITE);
delay(200);
box(180,400,40,WHITE,BLACK);
n=pi;
setcolor(DARKGRAY);
15
outtextxy(30,60," 3.1415265");
goto Again;
}
alg(n,y);
strcpy(s," ");
goto Again;
}
}
}
return;
}
16
{ box(180,340,40,BLACK,WHITE);
delay(200);
box(180,340,40,WHITE,BLACK);
z1[i+1]=z2[i]='\0';
equ();
i=0;
return 0;
}
return 0;
}
int i,j;
char ch[50]={" "};
for(i=0;z2[i]!='\0';)
{
if(z2[i]=='/') /*------perform division------*/
{ z1[i]/=z1[i+1];
for(j=i;z2[j]!='\0';j++)
{ z1[j+1]=z1[j+2];
z2[j]=z2[j+1];
}
}
else
i++;
} /*--------------*/
for(i=0;z2[i]!='\0';)
{
if(z2[i]=='*') /*------perform multiplication------*/
{
z1[i]*=z1[i+1];
for(j=i;z2[j]!='\0';j++)
{ z1[j+1]=z1[j+2];
z2[j]=(int)z2[j+1];
}
}
else
i++; /*--------------*/
}
for(i=0;z2[i]!='\0';)
{
if(z2[i]=='+') /*------perform addition------*/
{
if(z2[i-1]=='-')
z1[i+1]*=-1;
z1[i]+=z1[i+1];
for(j=i;z2[j]!='\0';j++)
17
{ z1[j+1]=z1[j+2];
z2[j]=z2[j+1];
}
}
else
i++; /*--------------*/
}
for(i=0;z2[i]!='\0';)
{
if(z2[i]=='-') /*------perform subtraction------*/
{
z1[i]-=z1[i+1];
for(j=i;z2[j]!='\0';j++)
{ z1[j+1]=z1[j+2];
z2[j]=z2[j+1];
}
}
else
i++;
} /*--------------*/
press();
return 0;
}
18
if( y>160 && y<200) // HEX function
{
box(550,160,55,BLACK,WHITE);
delay(200);
box(550,160,55,WHITE,BLACK);
com(n,16);
}
if( y>220 && y<260) // BINARY function
{
box(550,220,55,BLACK,WHITE);
delay(200);
box(550,220,55,WHITE,BLACK);
com(n,2);
}
if( y>280 && y<320) //OCTAL function
{
box(550,280,55,BLACK,WHITE);
delay(200);
box(550,280,55,WHITE,BLACK);
com(n,8);
}
return 0;
}
/*---------common for HEX, BINARY & OCTAL-------------*/
press();
return 0;
}
roots( )
{
float a,b,c,disc,r1,r2,s,x,y;
int k=253;
closegraph();
restorecrtmode();
19
printf("Input values of a, b, c in ax%c+bx+c\n ",k);
scanf("%f%f%f",&a,&b,&c);
disc= b*b-4*a*c;
if(disc<0)
{
printf("\n roots are IMAGINERY \n");
s=-disc;
x=sqrt(s)/(2*a);
y=-b/(2*a);
printf("\n r1=%f+i%f",y,x);
printf("\n r2=%f-i%f",y,x);
}
else
{
r1=(-b+sqrt(disc))/(2.0*a);
r2=(-b-sqrt(disc))/(2.0*a);
printf("\n r1=%f \n r2=%f \n",r1,r2);
}
getch();
return;
}
/*---------------BUTTONS------------------------*/
password()
{
int i,x=270,gm,gd=DETECT;
char ch,pass[10];
initgraph(&gd,&gm,"c:\\tc\\bgi");
rectangle(15,15,615,465);
setcolor(LIGHTBLUE);
setfillstyle(1,LIGHTBLUE);
floodfill(50,50,15);
settextstyle(1,HORIZ_DIR,3);
setcolor(BLACK);
outtextxy(200,50,"Enter the password");
for(i=0;i<=10;i++,x+=10)
{
ch=getch();
if(ch==13)
break;
outtextxy(x,150,"*");
20
sound(300);
delay(50);
nosound();
pass[i]=ch;
}
pass[i]='\0';
if(!strcmp(pass,"as")) //compare entered string with password
return 0;
else
cleardevice();
rectangle(15,15,615,465);
setcolor(LIGHTBLUE);
setfillstyle(1,LIGHTBLUE);
floodfill(50,50,15);
settextstyle(1,HORIZ_DIR,3);
setcolor(RED);
outtextxy(220,50,"Wrong Password");
outtextxy(80,150,"This program will terminate in 5 seconds");
for(i=5;i>=0;i--)
{
setcolor(LIGHTBLUE);
setfillstyle(1,LIGHTBLUE);
bar(300,240,330,300);
setcolor(RED);
outtextxy(310,250,itoa(i,pass,10));
sound(1000*i+500);
delay(300);
nosound();
delay(700);
}
exit(0);
return 0;
}
setcolor(WHITE); setfillstyle(1,WHITE);
bar(30,55,610,70);
21
if(y>=160 && y<=200) // HYPERBOLIC SINE of entered no.
{
box(xy1[0],160,70,BLACK,WHITE);
delay(200);
box(xy1[0],160,70,WHITE,BLACK);
cal=sinh(a);
}
if(y>=220 && y<=260) // EXPONENTIAL of entered no.
{
box(xy1[0],220,70,BLACK,WHITE);
delay(200);
box(xy1[0],220,70,WHITE,BLACK);
cal=exp(a);
}
if(y>=280 && y<=320) // Yth ROOT of entered no.
{
box(xy1[0],280,70,BLACK,WHITE);
delay(200);
box(xy1[0],280,70,WHITE,BLACK);
z2[1]='r';
return 0;
}
if(y>=340 && y<=380) // Yth POWER of entered no.
{
box(xy1[0],340,70,BLACK,WHITE);
delay(200);
box(xy1[0],340,70,WHITE,BLACK);
z2[1]='p';
return 0;
}
if(y>=400 && y<=440) // HYPOTENUSE of entered no.
{
box(xy1[0],400,70,BLACK,WHITE);
delay(200);
box(xy1[0],400,70,WHITE,BLACK);
z2[1]='h';
return 0;
}
setcolor(DARKGRAY);
gcvt(cal,10,str);
outtextxy(35,60,str);
press();
return(0);
}
setcolor(WHITE); setfillstyle(1,WHITE);
bar(30,55,610,70);
22
if(y>=100 && y<=140) // COSINE of entered no.
{
box(xy1[1],100,70,BLACK,WHITE);
delay(200);
box(xy1[1],100,70,WHITE,BLACK);
cal=cos(a);
}
if(y>=160 &&y<=200) // HYPERBOLIC COSINE of entered no.
{
box(xy1[1],160,70,BLACK,WHITE);
delay(200);
box(xy1[1],160,70,WHITE,BLACK);
cal=cosh(a);
}
if(y>=220 && y<=260) // NATURAL LOG of entered no.
{
box(xy1[1],220,70,BLACK,WHITE);
delay(200);
box(xy1[1],220,70,WHITE,BLACK);
cal=log(a);
}
if(y>=280 && y<=320) // INVERSE of entered no.
{
box(xy1[1],280,70,BLACK,WHITE);
delay(200);
box(xy1[1],280,70,WHITE,BLACK);
cal=1/a;
}
if(y>=340 && y<=380) // SQRT of entered no.
{
box(xy1[1],340,70,BLACK,WHITE);
delay(200);
box(xy1[1],340,70,WHITE,BLACK);
cal=sqrt(a);
}
if(y>=400 && y<=440) // QUADRATIC EQN.
{
box(xy1[1],400,70,BLACK,WHITE);
delay(200);
box(xy1[1],400,70,WHITE,BLACK);
roots();
draw();
return 0;
}
setcolor(DARKGRAY);
gcvt(cal,10,str);
outtextxy(35,60,str);
press();
return 0;
}
23
{
double cal;
char *str;
setcolor(WHITE); setfillstyle(1,WHITE);
bar(30,55,610,70);
press();
return(0);
24
}
press()
{
int x;
x=getmaxx();
setcolor(BLACK);
setfillstyle(1,RED);
bar(21,20,x-21,40);
floodfill(25,25,BLACK); /* blue rectangle*/
setcolor(WHITE);
outtextxy(x-250,27,"Press Any Key To Continue"); /*---Continue---*/
getch();
setcolor(LIGHTGRAY);
setfillstyle(1,WHITE);
floodfill(32,59,LIGHTGRAY);
setcolor(BLACK);setfillstyle(1,BLUE);
rectangle(21,20,x-21,40);
floodfill(25,25,BLACK); /* blue rectangle*/
setcolor(WHITE);
outtextxy(x-220,27,"Press Any Key To Quit."); /*---Quit---*/
}
/*-----------------------END--------------------------------------*/
25
APPLICATIONS
In most countries, students use calculators for schoolwork.
There was some initial resistance to the idea out of fear that
basic arithmetic skills would suffer. There remains disagreement
about the importance of the ability to perform calculations "in
the head", with some curricula restricting calculator use until a
certain level of proficiency has been obtained, while others
concentrate more on teaching estimation techniques and
problem-solving. Research suggests that inadequate guidance in
the use of calculating tools can restrict the kind of mathematical
thinking that students engage in. Others have argued that
calculator use can even cause core mathematical skills to
atrophy, or that such use can prevent understanding of advanced
algebraic concepts.
There are other concerns - for example, that a pupil could use
the calculator in the wrong fashion but believe the answer
because that was the result given. Teachers try to combat this by
encouraging the student to make an estimate of the result
manually and ensuring it roughly agrees with the calculated
result. Also, it is possible for a child to type in −1 × −1 and
obtain the correct answer '1' without realizing the principle
involved. In this sense, the calculator becomes a crutch rather
than a learning tool, and it can slow down students in exam
26
conditions as they check even the most trivial result on a
calculator.
TESTING
Testing is the major control measure used during software development.
Its basic function is to detect errors in the software. During requirement
analysis and design, the output is a document that is usually textual and
no executable. After the coding phase, computer programs are available
that can be executed for testing purpose. This implies that testing not
only, has to uncover errors introduced during coding, but also errors
introduced during previous phase. Thus the goal of testing is to uncover
the requirements, design and coding errors in the programs. The
27
Sourcecode declared above for the program of Scientific Calculator has
been tested and it has been found that the above source code is okay and
correct.The program involves many type of conversions. These
conversions has to done carefully
REFERENCES
28
29