Sunday, 25 January 2015

Scientific Calculator C++ Project With Documentation


































CONTENTS:
1.   PROBLEM DEFINITION
2.   PROBLEM ANALYSIS
3.   HARDWARE AND SOFTWARE REQUIREMENTS
4.   FUTURE ENHANCEMENT
5.   SOURCE CODE














PROBLEM DEFINITION:
A scientific calculator is a type of electronic calculator, usually but not always handheld, designed to calculate problems in science, engineering, and mathematics. They have almost completely replaced slide rules in almost all traditional applications, and are widely used in both education and professional settings.
In certain contexts such as higher education, scientific calculators have been superseded by graphing calculators, which offer a superset of scientific calculator functionality along with the ability to graph input data and write and store programs for the device. There is also some overlap with the financial calculator market.
Scientific calculators are used widely in any situation where quick access to certain mathematical functions is needed, especially those such as trigonometric functions that were once traditionally looked up in tables; they are also used in situations requiring back-of-the-envelope calculations of very large numbers, as in some aspects of astronomy, physics, and chemistry.
They are very often required for math classes from the junior high school level through college, and are generally either permitted or required on many standardized tests covering math and science subjects; as a result, many are sold into educational markets to cover this demand, and some high-end models include features making it easier to translate the problem on a textbook page into calculator input, from allowing explicit operator precedence using parentheses to providing a method for the user to enter an entire problem in as it is written on the page using simple formatting tools.
            In this project, we to write an interactive program to calculate using  a scientific calculator designed with some 25 functions and consists of a memory to store the values, so that the user can verify it whenever he/she wants. With the help of this program the users can calculate even very complex calculations easily. The users can do as many calculations as they want and store all that in a file. These files can later be retrieved based on a unique number given to the user.

           



Problem Analysis:
We have first defined all the mathematical functions and later split them up in 5 basic sub menus for the user’s easy calculation.
Those 5 sub menus are:
1.    Arithmatic-
Arithmetic menu includes addition of two numbers, subtraction of two numbers, division of two numbers, multiplication of two numbers and inverse of a number.
            Addition:
 Enter the numbers to be added:  2   3
2
3
5

                      
            Subtraction:
Enter the numbers to be subtracted: 7   4
7
4
3



            Multiplication:
Enter the numbers to be multiplied: 12   5
12
5
60

            Division:
Enter the numbers to be divided: 18   6
18
6
3


Inverse of a number:
Enter a number whose inverse is to be found: 7
7
0.14285714285

2.    Exponential-
Exponential menu includes finding the nth root of a number, nth power of a number, antilog of a number to the base 10, anti ln of a number, log of a number to any base to any base.

            nth root: 
Enter the base to which the nth root is to be taken: 4
Enter the exponent: 2
4
2
2
             

            nth power:
            Enter the base to which the nth power is to be taken: 3
Enter the exponent: 2
3
2
9



            Anti logarithm to base 10:
            Enter the number whose anti-logarithm to the base 10 is to be taken: 2
2
100

Anti ln:
Enter the number whose anti-logarithm to the base 'e' is to be taken: 3
3
20.0855369232

            Logarithm to any base:
            Enter the mantissa: 3
Enter the base: 27
3
27
3

3.    Trigonometric-
Trigonometric menu includes finding the SIN of a number, COS of a number, TAN of a number, COT of a number, SEC of a number, COSEC of a number.
            Sine:
            Enter the number whose sine is to be taken(in radians): 1.57
1.57
0.99999968293


Cosine:
            Enter the number whose cosine is to be taken(in radians): 2
2
0.99706973105

            Tangent:
            Enter the number whose tangent is to be taken(in radians): 10
10
0.64836082745

            Cosecant:
            Enter the number whose cosecant is to be taken(in radians): 7

7
1.52210106256

            Secant:
            Enter the number whose secant is to be taken(in radians): 0
0
1


            Cotangent:
            Enter the number whose cotangent is to be taken(in radians): 3.14
1
0.64209261593



4.    Inverse Trigonometric-
Inverse Trigonometric menu includes finding the SIN INVERSE of a number, COS INVERSE of a number, TAN INVERSE of a number, COT INVERSE of a number, SEC INVERSE of a number, COSEC INVERSE of a number.
            Sine inverse:
            Enter a number whose arc sine is to be found out: 1
1
1.57079632679

Cosine inverse:
            Enter a number whose arc cosine is to be found out: 0.5
0.5
1.0471975512

Tangent inverse:
Enter a number whose arc tangent is to be found out: 5
5
1.37340076695


            Cotangent inverse:
            Enter a number whose arc cotangent is to be found out: -1
-1
-0.785398

            Cosecant inverse:
            Enter a number whose arc cosecant is to be found out: 5
5
0.201358


            Secant Inverse:
            Enter a number whose arc secant is to be found out: 3

3
1.230959



5.    Factorial-
Factorial menu includes finding the permutation (nPr) , combination (nCr) and the factorial of a number.
            Factorial:
Enter the number whose factorial is to be found out: 7
7
5040

Permutation:
            Enter a number(n) whose permutations is to be found: 4
Enter 'r': 2
4
2
12


            Combination:
            Enter a number(n) whose combinations is to be found: 8
Enter 'r': 3
8
3
56

The user can use these 5 sub menus and the various sub menus included inside them to perform the calculations and save them in a file based on the unique identification number given to them.
After declaring these functions we accept the choice from the user on which sub menu to open, then we accept the choice from the user to decide what type of calculations are to be performed , then
We accept the data input required for the calculation,perform the calculation and write these answers in a file, which are later opened based on the unique identification number given by the user.













HARDWARE AND SOFTWARE REQUIREMENTS:
TURBO C++
WINDOWS 98 ONWARDS.
INTEL PENTIUM ONWARDS.















FUTURE ENHANCEMENT:
The scientific calculator coded in this project is easily compatible for its future enhancement. It can be upgraded to carry out some more functions like:

   Linear and Root Equation Solver
   Complex Number Math (Polar and Rectangular Format) 
   Decimal to Fraction Conversion 
   Base Conversion Utility
   Interactive Unit Converter
   Calculus functions
   Probability
   Statistics

Graphing of functions can also be included.
  
  
 
  



  
SOURCE CODE:
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<fstream.h>
#include<string.h>                                                                                         
fstream f("db.txt",ios::ate);
ofstream fout("notes1.txt",ios::app);

void nthroot()
{float num;
float n;
cout<<"\nEnter the base to which the nth root is to be taken:\n";
cin>>num;fout<<num;
cout<<"\nEnter the exponent:\n";
cin>>n; fout<<"^(1/"<<n<<") is : ";
cout<<"The nth root is: "<<pow(num,(1/n));
fout<<pow(num,(1/n));}

void nthpower()
{float num; int n;
cout<<"\nEnter the base to which the nth power is to be taken:\n";
cin>>num;fout<<num;
cout<<"\nEnter the exponent:\n";
cin>>n; fout<<"^"<<n<<" is : ";
cout<<"The nth power is: "<<pow(num,n);
fout<<pow(num,n);}
void product()
{
float m,n;
cout<<"\nEnter the numbers to be multiplied:\n";
cin>>m;
cout<<"\n";
cin>>n;
cout<<"\nThe product of the numbers is:"<<m*n;
fout<<m<<"*"<<n<<" = "<<m*n;}
void divide()
{
float m,n;
cout<<"\nEnter the numbers to be divided:\n";
cin>>m;
cout<<"\n";
cin>>n;
cout<<"\nThe quotient is:"<<m/n;
fout<<m<<"/"<<n<<" = "<<m/n;}
void add()
{
float m,n;
cout<<"\nEnter the numbers to be added:\n";
cin>>m;
cout<<"\n";
cin>>n;
cout<<"\nTheir sum is:"<<m+n;
fout<<m<<"+"<<n<<" = "<<m+n;}
void subtract()
{float m,n;
cout<<"\nEnter the numbers to be subtracted:\n";
cin>>m>>n;
cout<<"\nTheir difference is:"<<m-n;
fout<<m<<"-"<<n<<" = "<<m-n;}
void altb()
{
float n;
cout<<"\nEnter the number whose anti-logarithm to the base 10 is to be taken:\n";
cin>>n;
cout<<"\nThe value of anti-logarithm to the base 10 of "<<n<<" is:"<<pow(10,n);
fout<<"antilog of "<<n<<"is : "<<pow(10,n);}
void antiln()
{float n;
cout<<"\nEnter the number whose anti-logarithm to the base 'e' is to be taken:\n";
cin>>n;
cout<<"\nThe value of anti-logarithm to the base 'e' of "<<n<<" is:"<<exp(n);
fout<<"antiln of "<<n<<"is : "<<exp(n);}
void cosine()
{
float n;
cout<<"\nEnter the number whose cosine is to be taken(in radians):\n";
cin>>n;
cout<<"The value of the cosine of angle "<<n<<"radians is: "<<cos(n);
fout<<"cos("<<n<<") is : "<<cos(n);}
void sine()
{
float n;
cout<<"\nEnter the number whose sine is to be taken(in radians):\n";
cin>>n;
cout<<"The value of the sine of angle "<<n<<"radians is: "<<sin(n);
fout<<"sin("<<n<<") is : "<<sin(n);}
void tangent()
{
float n;
cout<<"\nEnter the number whose tangent is to be taken(in radians):\n";
cin>>n;
cout<<"The value of the tangent of angle "<<n<<"radians is: "<<tan(n);
fout<<"tan("<<n<<") is : "<<tan(n);}
void secant()
{
float n;
cout<<"\nEnter the number whose secant is to be taken(in radians):\n";
cin>>n;
cout<<"The value of the secant of angle "<<n<<"radians is: "<<(1/cos(n));
fout<<"sec("<<n<<") is : "<<(1/cos(n));}
void cotangent()
{
float n;
cout<<"\nEnter the number whose cotangent is to be taken(in radians):\n";
cin>>n;
cout<<"The value of the cotangent of angle "<<n<<"radians is: "<<(1/tan(n));
fout<<"cot("<<n<<") is : "<<(1/tan(n));}
void cosecant()
{
float n;
cout<<"\nEnter the number whose cosecant is to be taken(in radians):\n";
cin>>n;
cout<<"The value of the cosecant of angle "<<n<<"radians is: "<<(1/sin(n));
fout<<"cosec("<<n<<") is : "<<(1/sin(n));}
void logbase()
{
float m,n;
cout<<"\nEnter the mantissa: ";
cin>>m;
cout<<"\nEnter the base: ";
cin>>n;
cout<<"The value of logarithm of "<<m<<" to the base "<<n<<" is:"<<(log(m)/log(n));
fout<<"The value of logarithm of "<<m<<" to the base "<<n<<" is:"<<(log(m)/log(n));}
void fact()
{int n;
double f=1.0;
cout<<"\nEnter the number whose factorial is to be found out: ";
cin>>n;
for(int i=1;i<=n;++i)
{f*=i;}
cout<<n<<" factorial is: "<<f;
fout<<n<<" factorial is: "<<f;}
void combination()
{int n,r;
double x;
cout<<"Enter a number(n) whose combinations is to be found:\n";
cin>>n;
cout<<"Enter 'r':\n";
cin>>r;
double f1,f2,f3;f1=f2=f3=1.0;
for(int i=1;i<=n;i++)
{
f1*=i;
}
for(int j=1;j<=r;j++)
{
f2*=j;
}
for(int k=1;k<=(n-r);k++)
{
f3*=k;
}
x=(f1/(f2*f3));
cout<<"\n"<<n<<"C"<<r<<"="<<x;
fout<<"\n"<<n<<"C"<<r<<"="<<x;}
void permutation()
{
int n,r;
double x;
cout<<"Enter a number(n) whose permutations is to be found:\n";
cin>>n;
cout<<"Enter 'r':\n";
cin>>r;
double f1,f2;f1=f2=1.0;
for(int i=1;i<=n;i++)
{
f1*=i;
}
for(i=1;i<=(n-r);i++)
{
f2*=i;
}
x=(f1/f2);
cout<<"\n"<<n<<"P"<<r<<"="<<x;
fout<<"\n"<<n<<"P"<<r<<"="<<x;}
void inverse()
{
float n;
cout<<"Enter a number whose inverse is to be found:\n";
cin>>n;
cout<<"\nThe inverse of the number is:"<<(1/n);
fout<<"\nThe inverse of the number is:"<<(1/n);}
void sininv()
{
float n;
cout<<"Enter a number whose arc sine is to be found out:\n";
cin>>n;
cout<<"The value of arc sine of "<<n<<"is:"<<asin(n);
fout<<"The value of arc sine of "<<n<<"is:"<<asin(n);}
void cosinv()
{
float n;
cout<<"Enter a number whose arc cosine is to be found out:\n";
cin>>n;
cout<<"The value of arc cosine of "<<n<<"is:"<<acos(n);
fout<<"The value of arc cosine of "<<n<<"is:"<<acos(n);}
void taninv()
{
float n;
cout<<"Enter a number whose arc tangent is to be found out:\n";
cin>>n;
cout<<"The value of arc tangent of "<<n<<"is:"<<atan(n);
fout<<"The value of arc tangent of "<<n<<"is:"<<atan(n);}
void cotinv()
{
float n;
cout<<"Enter a number whose arc cotangent is to be found out:\n";
cin>>n;
if(n==0)
{cout<<"the value of arc cotangent of "<<n<<"is: infinite";
fout<<"the value of arc cotangent of "<<n<<"is: infinite";}
else
{cout<<"The value of arc cotangent of "<<n<<"is:"<<atan(1/n);
fout<<"The value of arc cotangent of "<<n<<"is:"<<atan(1/n);}}
void cosecinv()
{
float n;
cout<<"Enter a number whose arc cosecant is to be found out:\n";
cin>>n;
cout<<"The value of arc cosecant of "<<n<<"is:"<<asin(1/n);
fout<<"The value of arc cosecant of "<<n<<"is:"<<asin(1/n);}
void secinv()
{
float n;
cout<<"Enter a number whose arc secant is to be found out:\n";
cin>>n;
cout<<"The value of arc secant of "<<n<<"is:"<<acos(1/n);
fout<<"The value of arc secant of "<<n<<"is:"<<acos(1/n);}
void main()
{clrscr();
char rep='y',xyz1='n';
int n,a[300],m,y,z;
for(int j=0;j<300;++j)
a[j]=0;
int day=0,month=0,year=0;
char name[20],ch[300][20];
cout<<"WELCOME TO SCIENTIFIC CALCULATOR !\n";
while(rep=='y'||xyz1=='y'){
cout<<"\n\n1. sign up   2. log in\n";
cin>>n;
if(n==1)
{
cout<<"\nplease enter your name : ";
gets(name);
f<<name;
lmn:
{cout<<"\nplease enter your date of birth(dd/mm/yyyy) ";
 cin>>day>>month>>year;
 if((day!=0&&day>=1&&day<=31)&&(month!=0&&month>=1&&month<=12)&&(year!=0&&year>=1))
 {
 if((day>=1&&day<=31&&day!=0)||(month>=1&&month<=12&&month!=0)||(year>=1&&year!=0))
 {if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
  {if(day>=1&&day<=31)
    {f<<day<<month<<year;
    }
  }
  if(month==4||month==6||month==9||month==11)
   {if(day>=1&&day<=30)
    {f<<day<<month<<year;
    }
    else
    {cout<<"\nInvalid Date! Please try again\n";
     goto lmn;
    }
   }
  if(month==2)
   {if(day>=1&&day<=28)
    {f<<day<<month<<year;
    }
    else
    {cout<<"\nInvalid Date! Please try again\n";
     goto lmn;
    }
   }
 }
 else
 {cout<<"\nEnter Valid Date ! ";
  goto lmn;
 }
}
else
{cout<<"\nEnter Valid Date ! ";
 goto lmn;
}
}

abc:
cout<<"\nplease enter a desired UN(User Number) which is less than 300 : ";
cin>>m;
f<<m;
for(int i=0;i<300;++i)
{
if((a[i]==m))
{cout<<"\nsorry, not available ,try again ";
goto abc;}
}
strcpy(ch[m],name);
cout<<"\nnow enter your password of high security(digits only) : ";
cin>>a[m];
f<<a[m];
cout<<"\nthis will be your password for further login ";
cout<<"\nsuccessfully registered ";
}
if(n==2)
{cout<<"\nplease enter your UN(User Number) : ";
cin>>y;
cout<<"\nplease enter the password : ";
cin>>z;
if(a[y]==z)
{cout<<"\nwelcome "<<ch[y];
  int ch1,ch2;
cout<<"\nWelcome to the Scify Calculator!\a\n";//Scify – Scientific Calculator
while(rep=='y'||xyz1=='y')
{
cout<<"\nPlease enter the number from the menu to proceed further\n";
cout<<"1.Arithmatics\n";
cout<<"2.Exponential functions\n";
cout<<"3.Trigonometric functions\n";
cout<<"4.Inverse Trigonometric functions\n";
cout<<"5.Factorial related operations\n";
cin>>ch1;
switch(ch1)
{
case 1:
cout<<"\nSelect the number from the following sub-menu to proceed further\n";
cout<<"1.Addition\n";
cout<<"2.Subtraction\n";
cout<<"3.Multiplication\n";
cout<<"4.Division\n";
cout<<"5.Inverse of a number\n";
cin>>ch2;
if(ch2==1)
{add();}
else if(ch2==2)
{subtract();}
else if(ch2==3)
{
product();
}
else if(ch2==4)
{
divide();
}
else if(ch2==5)
inverse();
else
cout<<"\nError!";
break;
case 2:
cout<<"\nSelect the number from the following sub-menu to proceed further\n";
cout<<"1.nth root\n";
cout<<"2.nth power\n";
cout<<"3.Anti logarithm to base 10\n";
cout<<"4.Anti ln\n";
cout<<"5.Logarithm to any base\n";
cin>>ch2;
if(ch2==1)
nthroot();
else if(ch2==2)
nthpower();
else if(ch2==3)
altb();
else if(ch2==4)
antiln();
else if(ch2==5)
logbase();
else
cout<<"\nError!";
break;
case 3:
cout<<"\nSelect the number from the following sub-menu to proceed further\n";
cout<<"1.Sine\n";
cout<<"2.Cosine\n";
cout<<"3.Tangent\n";
cout<<"4.Cosecant\n";
cout<<"5.Secant\n";
cout<<"6.Cotangent\n";
cin>>ch2;
if(ch2==1)
{
sine();
}
else if(ch2==2)
cosine();
else if(ch2==3)
tangent();
else if(ch2==4)
cosecant();
else if(ch2==5)
secant();
else if(ch2==6)
cotangent();
else
cout<<"\nError!";
break;
case 4:
cout<<"\nSelect the number from the following sub-menu to proceed further\n";
cout<<"1.Sine inverse\n";
cout<<"2.Cosine inverse\n";
cout<<"3.Tan inverse\n";
cout<<"4.Cot inverse\n";
cout<<"5.Secant inverse\n";
cout<<"6.Cosecant inverse\n";
cin>>ch2;
if(ch2==1)
sininv();
else if(ch2==2)
cosinv();
else if(ch2==3)
taninv();
else if(ch2==4)
cotinv();
else if(ch2==5)
secinv();
else if(ch2==6)
cosecinv();
else
cout<<"\nError!";
break;
case 5:
cout<<"\nSelect the number from the following sub-menu to proceed further\n";
cout<<"1.Factorial\n";
cout<<"2.Permutation\n";
cout<<"3.Combination\n";
cin>>ch2;
if(ch2==1)
fact();
else if(ch2==2)
permutation();
else if(ch2==3)
combination();
else
cout<<"\nError!";
break;
default:
cout<<"\nInvalid choice selected! Please check your selection.";
}
xyz1='n';
cout<<"\nDo you want to continue(y/n)?";
cin>>rep;
}
fout.close();char d;

ifstream fin("notes1.txt");


{cout<<"\nDo you want to continue with another user? ";
 cin>>xyz1;
 cout<<"\n";
 }
fin.close();}
else
{cout<<"\nyour password doesnt match !!!!!!!!!";}
f.close();
}
}

getch();
}









          
      
  







































Bibiliography:
1.     Google.com
 
For searching various information and exploring new ideas.
2.     Gmail.com and yahoomail.com
                         
For exchanging information between the members of the group.


3.     Sumitha Arora computer science text book

4.     Cplusplus.com

For ideas and details regarding the project.











1 comment: