Vous êtes sur la page 1sur 18

TERM PAPER

Of
C++
TOPIC:SCIENTIFIC CALCULTOR







SUBMITTED TO:
MR.Dishant sikka
SUBMITTED BY:
POOJA SHARMA
E1804A05
10803094


ACKNOWLEDGEMENT

As the professional courses do not only required the theoretical knowledge but need to cover
practical aspect too. Universities have started conducting training programs for students. So,
that they get simple view of practical knowledge.
No work of significance can be claimed on a result of individual Efforts and same holds true
further for this project as well, for through it carries my name the energy of many have
contributed in no small measure in completion of this project.
I am very thankful to my friend and our teachers ER. DISHANT SIR who help me to make
this project.




POOJA SHARMA









I NTRODUCTI ON
Scientific calculator is an extension of a mathematician and it has opened up new
possibilitie.Within mathematics. It is a machine though, and it is only capable of doing what
it is programmed to do. Accordingly, this project aims to develop the internal programmed
computational code in the form of a computer program that a scientific calculator could use
to compute functions such as square root, the exponential, and sine functions.1 The idea of
this project assumes that that the programmer has already developed the very basic addition,
Subtraction, multiplication, division and integer splicing2 functions. Then using these basic
functions, the program will then compute other more complicated functions found on a
typical scientific calculator such as the sine and logarithmic functions.
The calculator is an extension of a mathematician and it has opened up new possibilities
Within mathematics. It is a machine though, and it is only capable of doing what it is
Programmed to do. Accordingly, this project aims to develop the internal programmed
computational code in the form of a computer program that a scientific calculator could use
to compute functions such as square root, the exponential, and sine functions.1 The idea of
this project assumes that that the programmer has already developed the very basic addition,
Subtraction, multiplication, division and integer splicing2 functions. Then using these basic
Functions, the program will then compute other more complicated functions found on a
typical scientific calculator such as the sine and logarithmic functions.
With the necessity to conform to reality, there are limitations set upon this calculator and
They are similar to those found in popular calculators such as the Texas Instruments TI-83
Plus.
They are that:
(1) Functions inputs and outputs must be calculated accurately to ten significant figures3,
(2) The absolute values of inputs and outputs, excluding zero, can never be greater than or
equal
to 1 x 10100 or less than or equal to 1 x 10-100.
Similar to these mandatory requirements, there are a few goals that I wish to accomplish
within
the confines of the limitations. They are that:
(1) The code is as easily programmed as possible,
(2) And that the program is to be as efficient as possible at computing the functions.




I chose to work within the C++ language. A few advantages with choosing this
languages are that the code is easily transferred into other programming languages and that it
is universally known. I choose to use a Windows Console application due to its simplicity
and my familiarity with it, but this is a disadvantage because it is not an optimal interface for
a calculator due to its lack of visual resemblance of a handheld calculator.
The interface created for user inputs and outputs was created for basic test purposes only,
and if I had more time, I would have liked to use Visual Basic to create a visual calculator
with buttons that were able to be pressed. Even though the created interface looks
rudimentary, it contains all the possible tasks that the program is able to do. There were other
programming and computations issues that needed to be taken into account as well when
transferring mathematical theory into a working calculator. One issue was the large
difference in computational time. Computing multiplication and division takes significantly
longer time than computing addition and subtraction, and therefore should be avoided
whenever possible. Thus throughout the program there are instances where addition and
subtraction is used to eliminate the need for multiplication. Another issue is that the program
is constantly rounding numbers and thus losing trailing digits. Therefore in some cases it is
very difficult or impossible to adhere to the goals previously described. An example of this is
within the modulo function which cannot be evaluated for relatively large values modulo a
relatively small value.

TESTING FUNGTIONS

A random number generator was created that, based upon a users inputs, creates a
Specified number of random numbers on a given range. To do this, a vector is created with
random integral values between in the interval (1, 215). These values are then divided by 215
and thus randomly distributed in the in the interval (0, 1). Following this, the numbers, under
the same randomization pattern, are spread throughout the user defined interval.
The error estimation functions purpose is to determine how accurate a given function is
based upon the respective C++ built in function. To do this, a vector is created containing a
users defined number of terms, upper bound, lower bound and a function. Given this, the
error estimator function calculates the percent error of each value in the vector by the
equation:
( )( )
( ) ( _ )( ) ( )( )
C Function x
Percent Error x Created Function x C Function x
+ +
+ +
= .
After each value is tested, the percent error of the function at that value is tested to determine
if
the absolute value of the percent error at that point is the maximum percent error of the
values
tested thus far. Once all values in the vector have been tested, the maximum percent error is
outputted and if the result is less than or equal to 1010 then it is determined that the accuracy
is sufficient and complies with the ten significant figure goal.
In theory and through all my testing I have found that the calculations that are outputted
are accurate to the ten significant figure requirement. The times that the program would not
compute to the required accuracy, similar to a calculator, an error should be outputted. An
example of this is sin ((1e50) + 1). This in theory is calculable, but the large number of
significant figure prevents this for happening realistically. In this program there is an error
that is triggered and thus the program is stopped.
The efficiency estimator calculates how efficient a created function is compared to
respective C++ native function. To do this, a vector of random numbers is created based upon
the user defined variables of the number of terms, upper bound, lower bound and a function.
Once this is done, the created function is timed to see how many ticks11 it takes to compute all
of the values in the vector. Following this, a C++ native function is tested to see how long, in
ticks,it takes to compute all the values in the vector.
1 tick = 1/1000 second.

Percentage error(x)=(created function(X)-(c++function)(X)/(c++function)(x)

percent error of the function at that value is tested to determine if
the absolute value of the percent error at that point is the maximum percent error of the
values tested thus far. Once all values in the vector have been tested, the maximum percent
error is
outputted and if the result is less than or equal to 1010 then it is determined that the accuracy
is
sufficient and complies with the ten significant figure goal.


Scientific Calculator
Trigonometric Functions
Function Description Function Description
sin() sine asin() inverse sine
cos() cosine acos() inverse cosine
tan() tangent atan() inverse tangent
cot() cotangent ie cos()/sin() acot() inverse cotanget ie atan(1/x)
sec() secant ie 1/cos() asec() inverse secant ie acos(1/x)
csc() cosecant ie 1/sin() acsc() inverse cosecant ie asin(1/x)

Hyperbolic functions
sinh() hyperbolic sine asinh() inverse hyperbolic sine
cosh() hyperbolic cosine acosh() inverse hyperbolic cosine
tanh() hyperbolic tangent atanh() inverse hyperbolic tangent
coth() hyperbolic cotangent acoth() inverse hyperbolic cotangent
sech() hyperbolic secant asech() inverse hyperbolic secant
csch() hyperbolic cosecant acsch() inverse hyperbolic cosecant

General Functions
sort() square root
abs() absolute value
fact() factorial
floor()
Rounds down to the nearest
integer
ceil() Rounds up to the nearest integer
round()
Rounds to the nearest integer
(0.5+ goes up)


Logarithm functions
log() base 10 logarithm
logb(x,b) base "b" logarithm
ln() natural logarithm exp(x) e to the power x

Functions needing two values
gcd(x,y)
greatest common denominator
of x and y

max(x,y) maximum of x and y
min(x,y) minimum of x and y
angle(x,y) angle of coords x and y
dist(x,y) distance to coords x and y
comb(x,y) combinations of x and y



i The unit Imaginary Number ((-1))
pi The constant (3.141592654...)
e The Euler Constant (2.71828...), the base for the natural logarithm

PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#define sqr(x) (x)*(x)
void main()

{

float a,b,c;
int choice,i;
clrscr();
do
{
clrscr();
cout<<\nSCIENTIFIC CALCULATOR";
cout<<"\nEnter numbers for addition=<<Addition;
cout<<\nEnter numbers for subtraction=<<Subtration;
cout<<\nEnter numbers for multiplication=<<Multiplication;
cout<<\nEnter numbers for division=<<Division;
cout<<\n Enter values for function=<<Sine;
cout<<\n Enter values for function=<<Cosine;
cout<<\n Enter values for function=<<Tan;
cout<<\n Enter values for function=<<Log;
cout<<\n Enter values for function=<<Quadraic Equation Solver;
cout<<\n Enter values for function=<<Simultaneous Equation
Solver;
cout<<\n Enter values for function=<<Power Function(^);
cout<<\n Enter values for function=<<Exponential Power
Function";
cin>>choice
switch(choice)
{



case 1:{
clrscr();
cout<<"\naddition;
cout<<"\nEnter two numbers";
cin>>a>>b;
c=a+b;
cout<<Ans =<<c;
cout<<"Thank You for using this program;
break;
}


case 2: {
clrscr();
cout<<\nsubtraction;
cout<<"\nEnter two numbers;
cin>>a>>b;
c=a-b;
cout<<Ans =<<c;
cout<<"\nThank You for using this program";
break;
}

case 3:{
clrscr();
cout<<\nmultiplication;
cout<<\nEnter two numbers";
cin>>a>>b;
c=a*b;
cout<<\nAns =<< c;
cout<<"\nThank You for using this program\n");
break;
}


case 4:{
clrscr();
cout<<\ndivison;
cout<<"\nEnter two numbers";
cin>>a>>b;
c=a/b;
cout<<"\nAns ="<<c;
cout<<\nThank You for using this program";
break;
}

case 5: {
double a,b,ans;
int ch;
clrscr();
cout<<"\nSINE FUNCTION";
cout<<"\n Press 1 if the angle is in degree";
cout<<"\nPress 2 if the angle is in radians";
cin>>ch;
{
cout<<"\nEnter angle in degree";
cin>>a;
b=(a*22)/(7*180);
}
else if(ch==2)
{
cout<<"\nEnter angle in radians";
cin>>a;
b=a;
}
else
cout<<"\nError!!!";
break;
}
ans = sin(b);
cout<<"\nThe sin() of ="<<a<<ans);
cout<<"\nThank You for using this program";
break;
}


case 6:{
double a,b,ans;
int ch;
clrscr();
cout<<"\nCOSINE FUNCTION";
cout<<"\nPress 1 if the angle is in degree";
cout<<"\nPress 2 if the angle is in radians";
cin>>ch;
if(ch==1)
{



cout<<"\nEnter angle in degree";
cin>>a;
b=(a*22)/(7*180);
}
else if (ch==2)
{
cout<<"\nEnter angle in radians";
cin>>a;
b=a;
}
else
cout<<"\nError!!!";
break;
}
ans = cos(b);
cout<<"\nThe cos() of=<<ans<<a;
cout<<"\nThank You for using this program";
break;
}


case 7:{
doublea,b,ans;
int ch;
clrscr();
cout<<"\nTAN FUNCTION\n\n");
cout<<"\nPress 1 if the angle is in degree;
cout<<"\nPress 2 if the angle is in radians";
cin>>ch;
if(ch==1)
cout<<"\nEnter angle in degree;
cin>>a;
b=(a*22)/(7*180);
}
else

if(ch==2)
{
cout<<"\nEnter angle in radians";
cin>>a;
b=a;
}
else
{
cout<<"\n"Error!!!";
break;
}
ans = tan(b);
cout<<"\nThe tan() of="<<a<<ans;
cout<<"\nThank You for using this program";
break;
}


case8: {
float A,B,C, Delta;
clrscr();
cout<<"\nQUADRATIC EQUATION SOLVER;
cout<<"\n Enter Coefficients;
cout<<"\nA = ";
cin>>A;
cout<<"\nB = ";
cin>>B;
cout<<"\nC = ";
cin>>C;
if(A == 0 && B != 0)
{
cout<<"\nThis equation is a first degree equation";
cout<<"\nThe solution is= "<<-C/B;
}
else if(A == 0 && B == 0)
{
cout<<"\nThis equation has no solution\n");
}
else
{
Delta = sqr(B) - 4*A*C;
if(Delta < 0)
{
cout<<"\nThis equation dont have any real roots\n";

}

else if(Delta == 0)
{
cout<<"\nThis equation have a single root: ",-B/(2*A));
}
else
{
cout<<"\nThis equation have two real roots\n";

float X1 = (-B + sqrt(Delta)) / (2 * A);
float X2 = (-B - sqrt(Delta)) / (2 * A);
cout<<"\nX1 ="X1;
cout<<"\nX2 ="X2;
}
}

cout<<"\nThank You for using this program";
break;

}
case 9: {
double a,ans;
int ch;
clrscr();
cout<<"\nLOGARITHMIC FUNCTIONS\n\n");
cout<<"\n1.Natural Log\n2.Log to the base 10\n");
cin>>ch;
if(ch==1)
{
cout<<"\n "Enter value";
cin>>a;
ans=log(a);
cout<<"\n Log of ="<<a<<ans;
}
else if(ch==2)
{
cout<<"\n Enter value";
cin>>a;
ans=log10(a);
cout<<"\n "Log of to the base 10 is="<<a<<ans;
}
else
{
cout<<"\nError!!!";
break;
}
case 10:{
int a1,a2,b1,b2,c1,c2,c,b3,b4,a3,a4,c3,c4,c5,c6;
int m,n,i,d=1,lcm;
float a,b;
clrscr();
cout<<"\nSIMULTANEOUS EQUATION
SOLVER";
cout<<"\na1;
cin>>a1;
cout<<\nb1;
cin>>b1;
cout<<"\nc1;
cin>>c1;
cout<<"\na2";
cin>>a2;
cout<<"\nb2";
cin>>b2;
cout<<"\nc2";
cin>>c2;
if(a1>a2)
n = a2;
}
else
{
m = a2;
n = a1;
}
for(i=2;i<=n && n!=1;i++)
{
if(m%i==0 && n%i==0)
{
m = m/i;
n = n/i;
d = d*i;
i = 2;
}
}
if(d==1)
{
lcm = m*n;
}
else
{
lcm = d*m*n;
}
b3 = b1*(lcm/a1);
b4 = b2*(lcm/a2);
c3 = c1*(lcm/a1);
c4 = c2*(lcm/a2);
if(a1<0 && a2<0 || a1>0 && a2>0)
{
b = b3-b4;
c = c3-c4;
b = c/b;
}
else
{
b = b3+b4;
c = c3+c4;
b = c/b;
}
if(b1>b2)
{
m = b1;
n = b2;
}
else
{
m = b2;
n = b1;
}
for(i=2;i<=n && n!=1;i++)
{
if(m%i==0 && n%i==0)
{
m=m/i;
n=n/i;
d=d*i;
i=2;
}
}
if(d==1)
{
lcm=m*n;
}
else
{
lcm=d*m*n;
}
a3 = a1*(lcm/b1);
a4 = a2*(lcm/b2);
c5 = c1*(lcm/b1);
c6 = c2*(lcm/b2);

if(b1<0 && b2<0 || b1>0 && b2>0)


{
a = a3-a4;
c = c5-c6;
a = c/a;
}
else
{
a = a3+a4;
c = c5+c6;
a = c/a;
`}
cout<<"\n X ="<<a;
cout<<"\nY ="<<b;
cout<<"\n Thank You for using this program;
break;
}
case 11:{
float m,n,p;
clrscr();
cout<<"\n POWER FUNCTION(^);
cout<<"\n Enter the values of m and n w.r.t to the
equation m^n\n");
cin>>m>>n;
p = pow(m,n);
cout<<"\n raise to = "<<m<<n<<p;
cout<<"\n Thank You for using this program";
break;
}
case 12:{
float r,s;
clrscr();
cout<<"\n EXPONENTIAL FUNCTION;

cout<<"\n Enter value";
cin>>r;
s = exp(r);
cout<<"\n Answer ="<<s;
cout<<"\n Thank You for using this program\n");
break;
}


default:{
cout<<"\n Error!!!";
break;
}

}
cout<<\nEnter 1 to continue\nEnter 0 to exit";
cin>>i;
}while(i==1);

getch();

}

Vous aimerez peut-être aussi