Está en la página 1de 22

T ERM PAPER

OF
CSE-202

TOPIC:- SCIENTIFIC CALCULATOR

SUBMITTED BY
SUBMITTED TO
NAME- BITTU KUMAR LECT. CHETNA MAM
SECTION-E2801 (DEPT. OF COMPUTER SC.)
ROLL NO. – A05
REGISTRATION NO. -10808479

1
ACKNOWLEDGEMENT

As usual a large number of people deserve my thanks for the help


they provided me for the preparation of this term paper.

First of all I would like to thank my teacher Lect. Chetna mam for her
support during the preparation of this topic. I am very thankful for her
guidance.

I would also like to thank my friends for the encouragement and


information about the topic they provided to me during my efforts to
prepare this topic.

At last but not the least I would like to thank seniors for providing me
their experience and being with me during my work.

2
TABLE OF CONTENT:-

1.1 Introduction
1.2 Logic of the programme

1.2.1 Creating the standard calculator


1.2.2 Creating the scientific calculator

1.3 Control diagrame


1.4 Output screen
1.5 Source code of scientific calculator
1.6 Refernces

3
1.1 INTRODUCTION:-
Accordingly, this project aims to develop source code in the form of a computer
program i.e c++ that a scientific calculator could use to compute functions
such as square root, the exponential, and sine functions and etc. The idea of this
project that

1. Since all the mathematical function such as sin function, cos function,
logarithm function are define in the library function of <math.h>, thus we
have return the value of the function to call function.

2. For menu deriven programme, here we have to use switch-case statement.


3. In this programme ,there are two type of calculator,

a). Standard calculator.


b). Scientific calculator.

4. The standard calculator contain simple function such as addition ,


substraction etc. whereas the scientific calculator contain function sin ,
cosin, tan, exponential function etc.

The code of the calculator application mainly comprise of two classes standard
calculator and scientific calculator. The standard calculator class helps to
perform stanandard calculation. The scientific calculator class in the other hand,
helps to perform scientific calculations. Both classes contain static function so
a to ensure that these function can be called in the main function through class
name.

1.2 LOGIC OF THE PROGRAMME:-


1.2.1. CREATING THE STANDARD CALCULATOR :-

The standard class aims at performing specific task related to standard


calculation. These task are:-

1. Adding two number


2. Substracting the second number from the first number.
3. Multiplying two number
4. Dividing first number from second.
5. Modulus of first number by second number.

4
To perform the above mentioned task, the standard calculator class implements
the following member function.

FUNCTION DESCRIPTION

Addition returns the addition of two input number.


Substraction returns the substraction of two number.
Multiplication returns the multiplication of two number.
Division returns the output obtained after performing
operation on the input number

1.2.2 CREATING SCIENTIFIC CALCULATOR:-

You have to need to creat scientific calculator class to perform task related to
scientific calculations. Which include finding square or cube etc.
The scientific calculator perform following task.

1. Determine the square of the number.


2. Determine the square root of the number
3. Determine the first number power of the second number
4. Determine the factorial of a number
5. Determine the sin, cos and tan value of the number.
6. Determine the logarithm, natural logarithm and exponential of the
number.

To perform the above mentioned task in scientific calculator implements the


following member function.

FUNCTION DESCRIPTION

Square accept a number and returns the square of the number


Squae root accept a number and returns the square root of number
Cube accept two number and returns the first power to 2nd num.
Fact returns a factorial of an input number.
Sin_fun returns the sin value of an input number.
Cos_fun return the cos value of an input number.
Tan_fun return the tan value of an input number
Log_fun return the log value of an input number
Log10_fun return the log10 value of an input number.
Exp_fun return the exp value of an input number.

5
1.3 CONTROL DIAGRAM
This diagram tells the interconnection between various menus and sub-menus.

Standard calculator

Frontscreen Main Menu

Scientific calculato

This shows the transfer of control between various menus and sub menus

1.4.OUTPUT SCREEN
6
1.4.1. Main Screen:-
Choose the type of calculator

1.4.2 Scientific calculator screen:-


In scientific calculator, choose the type of function.

1.4.3. Result screen:-

7
Find your answere

1.5. SOURCE CODE OF SCIENTIFIC


CALCULATOR IN C++:-

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define new_calc 1
#define old_calc 0
class stand_calc
{
public:
static double addition(double,double);
static double substract(double,double);
static double multiplication(double,double);
static double division(double,double *);
static double modulus(double *,double *);
};
class scien_calc
{
public:
static double square(double);
static double cube(double);
8
static double power(double,double);
static double sq_root(double);
static double sin_fun(double);
static double cos_fun(double);
static double tan_fun(double);
static long int fact(double);
static double log_fun(double);
static double log10_fun(double);
static double exp_fun(double);
static double sqrt_fun(double);
};
double stand_calc::addition(double a,double b)
{
return(a+b);
}
double stand_calc::substract(double a,double b)
{
return(a-b);
}
double stand_calc::multiplication(double a,double b)
{
return(a*b);
}
double stand_calc::division(double a,double *b)
{
while(*b==0)
{
cout<<"\n cannot divide by zero";
cout<<"\n enter the second number again ";
cin>>*b;
}
return(a/(*b));
}
double stand_calc::modulus(double *a,double *b)
{
while(*b==0)
{
cout<<"\ncannot divid by zero.";
cout<<"\nenter the second nuber again";
cout<<*b;
}
int x=(int)*a;
int y=(int)*b;

9
if(*a-x>0||*b-y>0)
cout<<"\nconverting decimal nuber into an integer to perform modulus";
*a=x;
*b=y;
return(x%y);
}
double scien_calc::square(double x)
{
return(pow(x,2));
}
double scien_calc::cube(double x)
{
return(pow(x,3));
}
double scien_calc::power(double x,double y)
{
return(pow(x,y));
}
long int scien_calc::fact(double x)
{
int n=(int)x;
long int f=1;
while(n>1)
{
f*=n;
n--;
}
return f;
}
double scien_calc::sin_fun(double x)
{
return(sin(x));
}
double scien_calc::cos_fun(double x)
{
return(cos(x));
}
double scien_calc::tan_fun(double x)
{
return(tan(x));
}
double scien_calc::log_fun(double x)
{

10
return(log(x));
}
double scien_calc::log10_fun(double x)
{
return(log10(x));
}
double scien_calc::exp_fun(double x)
{
return(exp(x));
}
double scien_calc::sqrt_fun(double x)
{
return(sqrt(x));
}
void main()
{
double num1,num2,num3,temp;
int choice1=0,choice2,flag;
do
{
clrscr();
cout<<"==================type of
calculator======================";
cout<<"\n1\tStandard calculator \n2\tScientific calculator\n3\tQuit";
cout<<"\n choose type of the calculator";
cin>>choice1;
flag=new_calc;
switch(choice1)
{
case 1:
do
{
clrscr();
cout<<"====================standard
calculator=====================";
cout<<"\n1\taddition\n2\tsubstraction\n3\tmultiplication\n4\tdivision\n5\tmo
dulus\n6\treturn to previous menu\n7\tquit";
if(flag==old_calc)
cout<<"\n8\tclear memory";
cout<<"\nchoose type of the calculation:";

cin>>choice2;
switch(choice2)

11
{
case 1:
if(flag==new_calc)
{
cout<<"enter the first number:";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nfirst number is "<<num1<<endl;
}
cout<<"enter the second number:";
cin>>num2;
num3=stand_calc::addition(num1,num2);
cout<<"\naddition of "<<num1<<"+"<<num2<<"="<<num3;
cout<<"\npress any key to continue...................";
getch();
temp=num3;
flag=old_calc;
break;
case 2:
if(flag==new_calc)
{
cout<<"enter the first number";
cin>>num1 ;
}
else
{
num1=temp;
cout<<"\nfirst number is"<<num1<<endl;
}
cout<<"enter second number:";
cin>>num2;
num3=stand_calc::substract(num1,num2);
cout<<"\nsubstraction of "<<num2<<"-"<<num1<<"="<<num3;

cout<<"\npress any key to continue..................";


getch();
temp=num3;
flag=old_calc;
break;
case 3:

12
if(flag==new_calc)
{
cout<<"enter first number:";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nfirst number is"<<num1<<endl;
}
cout<<"\nenter the second number:";
cin>>num2;
num3=stand_calc::multiplication(num1,num2);
cout<<"\nmultiplication"<<num1<<"*"<<num2<<"="<<num3;
cout<<"\npress any key to contionue.................";
getch();
temp=num3;
flag=old_calc;
break;
case 4:
if(flag==new_calc)
{
cout<<"enter first number:";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nfirst nuber is"<<num1<<endl;
}
cout<<"enter second number";
cin>>num2;
num3=stand_calc::division(num1,&num2);
cout<<"\ndivision of"<<"num1"<<"by"<<num2<<"="<<num3;
cout<<"\npress any key to continue..............";
getch();
temp=num3;
flag=old_calc;
break;
case 5:
if(flag==new_calc)
{
cout<<"enter the first number:";

13
cin>>num1;
}
else
{
num1=temp;
cout<<"\nfirst number is"<<num1<<endl;
}
cout<<"enter the second number:";
cin>>num2;
num3=stand_calc::modulus(&num1,&num2);
cout<<"\nmodulus of "<<num1<<"by "<<num2<<"is"<<num3;
cout<<"press any key to continue...............";
getch();
temp=num3;
flag=old_calc;
break;
case 6:
cout<<"\nreturning to previous menu";
cout<<"\npress any key to continue................";
getch();
break;
case 7:
cout<<"\n quitting.................";
cout<<"\npress any key to continue...........";
getch();
exit(0);
case 8:
if(flag==new_calc)
{
cout<<"\ninvalid choice";
cout<<"\npress any key to continue............";
getch();
}
else
{
temp=0;
flag=new_calc;
}
break;
default:
cout<<"\ninvalid choice";
cout<<"\npress any key to continue..............";
getch();

14
break;
}
}
while(choice2!=6);
break;
case 2:
do
{
clrscr();
cout<<"=============Scientific calculator===============";
cout<<"\n1\tsquare\n2\tsquare
root\n3\tcube\n4\tpower\n5\tfactorial\n6\tsin\n7\tcos\n8\ttan\n9\tlogrithm\n1
0\tnatural logrithm\n11\texponential\n12\treturn to previous
menu\n13\tquit";
if(flag==old_calc)
cout<<"\n14\tclear memory";
cout<<"\n choose type of the calculation :";
cin>>choice2;
switch(choice2)
{
case 1:
if(flag==new_calc)
{
cout<<"enter number to find square :";
cin>>num1;
}
else
{
num1=temp;
cout<<"\n number is "<<num1<<endl;
}
num3=scien_calc::square(num1);
cout<<"\nsquare of "<<num1<<"="<<num3;
cout<<"\npress any key to continue.............";
getch();
temp=num3;
flag=old_calc;
break;
case 2:
if(flag==new_calc)
{
cout<<"enter number to find square root :";
cin>>num1;

15
}
else
{
num1=temp;
cout<<"\n number ="<<num1<<endl;
}
num3=scien_calc::sqrt_fun(num1);
cout<<"\nsquare of "<<num1<<"="<<num3;
cout<<"\npress any key to continue.............";
getch();
temp=num3;
flag=old_calc;
break;
case 3:
if(flag==new_calc)
{
cout<<"enter to find cube";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nnumber is "<<num1<<endl;
}
num3=scien_calc::cube(num1);
cout<<"\ncube of"<<num1<<"="<<num3;
cout<<"\npress any key to continue..........";
getch();
temp=num3;
flag=old_calc;
break;
case 4:
if(flag==new_calc)
{
cout<<"enter the first number of base to find power";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nfirst number is"<<num1<<endl;
}
cout<<"enter the second number for for to find power:";

16
cin>>num2;
num3=scien_calc::power(num1,num2);
cout<<"\n"<<num1<<"^"<<num2<<"="<<num3;
cout<<"\npress any key to continue............";
getch();
temp=num3;
flag=old_calc;
break;
case 5:
if(flag==new_calc)
{
cout<<"enter number to find factorial:";
cin>>num1;
}
else
{
num1=temp;
cout<<"\n number to find factorial is"<<num1<<endl;
}
long int num4=scien_calc::fact(num1);
cout<<"\nfactorial of"<<num1<<" = "<<num4;
cout<<"\npress any key to continue...............";
getch();
temp=num4;
flag=old_calc;
break;
case 6:
if(flag==new_calc)
{
cout<<"enter SIN ";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nnumber for sin value is"<<num1<<endl;
}
num3=scien_calc::sin_fun(num1);
cout<<"\nSIN"<<num1<<" = "<<num3;
cout<<"\npress any key to continue..............";
getch();
temp=num3;
flag=old_calc;

17
break;
case 7:
if(flag==new_calc)
{
cout<<"\nenter COS ";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nnumber for cos value"<<num1<<endl;
}
num3=scien_calc::cos_fun(num1);
cout<<"\nCOS "<<num1<<"="<<num3;
cout<<"\npress any key to continue................";
getch();
temp=num3;
flag=old_calc;
break;
case 8:
if(flag==new_calc)
{
cout<<"enter TAN ";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nnumber for tan value"<<num1<<endl;
}
num3=scien_calc::tan_fun(num1);
cout<<"\nTAN "<<num1<<"="<<num3;
cout<<"\npress any key to continue..............";
getch();
temp=num3;
flag=old_calc;
break;
case 9:
if(flag==new_calc)
{
cout<<"enter LOG :";
cin>>num1;
}

18
else
{
num1=temp;
cout<<"\nnumber for log value"<<num1<<endl;
}
num3=scien_calc::log_fun(num1);
cout<<"\nLOG "<<num1<<"="<<num3;
cout<<"\npress any key to continue.................";
getch();
temp=num3;
flag=old_calc;
break;
case 10:
if(flag==new_calc)
{
cout<<"enter LOG10 :";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nnumber for natural log value"<<num1<<endl;
}
num3=scien_calc::log10_fun(num1);
cout<<"\nLOG10 "<<num1<<"="<<num3;
cout<<"\npress any key to continue.................";
getch();
temp=num3;
flag=old_calc;
break;
case 11:
if(flag==new_calc)
{
cout<<"enter e^ :";
cin>>num1;
}
else
{
num1=temp;
cout<<"\nnumber for exponential value"<<num1<<endl;
}
num3=scien_calc::exp_fun(num1);
cout<<"\ne^"<<num1<<"="<<num3;

19
cout<<"\npress any key to continue.................";
getch();
temp=num3;
flag=old_calc;
break;
case 12:
cout<<"\nreturning to previous menu";
cout<<"\npress any key to continue.............";
getch();
break;
case 13:
cout<<"\nQuitting..............";
cout<<"\npress any key to continue...............";
getch();
exit(0);
case 14:
if(flag==new_calc)
{
cout<<"\ninvalid choice";
cout<<"\npress any key to continue.................";
getch();
}
else
{
temp=0;
flag=new_calc;
}
break;
default:
cout<<"invalid choice";
cout<<"press any key to continue...............";
getch();
break;
}
}
while(choice2!=13);
break;
case3:
cout<<"\nQuitting..............";
cout<<"\npress any key to continue.............";
getch();
break;
default:

20
cout<<"\ninvalid choice";
cout<<"\n press any key to continue.............";
getch();
break;
}
}while(choice1!=3);
}

1.6 REFERENCES:-

BOOK:-
A) Object oriented programe with c++----- E. balaguruswami
B) Let us c++------------------------------------Yaswant kanitker

WEBSITE:-
A). http://www.scribd.com/doc/22517879/Scientific-Calculator

21
22

También podría gustarte