Simple Scientific Calculator Using C++

Simple Scientific Calculator Using C++ 


Scientific Calculator Using  OOP


========================================================================


#include<iostream>
#include<math.h>
using namespace std;
class trignometric
{
private:
int key,n,n1,power;
float res,number;
public:
 int fun()
 { while(1)
  {

cout<<"\t\t\tMain Menu\n\n\n";
cout<<"Enter 1: To Find COS\n";
cout<<"Enter 2: To Find SIN\n";
cout<<"Enter 3: To Find TAN\n";
cout<<"Enter 4: To Find COT\n";
cout<<"Enter 5: To Find Sec\n";
cout<<"Enter 6: To Find Cosec\n";
cout<<"Enter 7: Exit\n";
cin>>key;
if (key==1)
{
cout<<"Enter Number to Find cos\n";
cin>>number;
res=cos(number/57.29);
cout<<res<<endl;
}
if(key==2)
{
cout<<"Enter Number to Find SIN\n";
cin>>number;
res=sin(number/57.29);
cout<<res<<endl;
}
if(key==3)
{
cout<<"Enter Number to find TAN\n";
cin>>number;
res=tan(number/57.29);
cout<<res<<endl;
}
if(key==4)
{
cout<<"Enter Number to Find cot\n";
cin>>number;
res=1/tan(number/57.29);
cout<<res<<endl;
}
if(key==5)
{
cout<<"Enter Number to Find Sec\n";
cin>>number;
res=1/cos(number/57.29);
cout<<res<<endl;
}
if(key==6)
{
cout<<"Enter Number to Find Cosec\n";
cin>>number;
res=1/sin(number/57.29);
cout<<res<<endl;
   }
if(key==7)
{
cout<<"Bye";
break;
}
 }
 }
int fun1()
{
 while(1)
 {
cout<<"\t\t\tMain Menu\n\n\n";
  cout<<"Press 1: For Addition\n";
cout<<"Press 2: For Multiplication\n";
cout<<"Press 3: For Subtraction\n";
cout<<"Press 4: For Division\n";
cout<<"Press 5: To Exit\n";
cin>>key;
   if(key==1)
{
cout<<"How Many Numbers You Want To ADD\n";
cin>>n;
cout<<"Enter Your Numbers\n";
for(int i=1;i<=n;i++)
{
cin>>number;
res=res+number;

}
cout<<res<<endl;
}

  if(key==2)
{
    res=1;
cout<<"How Many Numbers You Want To Multiply\n";
cin>>n;
cout<<"Enter Your Numbers\n";
for(int i=1;i<=n;i++)
{
cin>>number;
res=res*number;

}
cout<<res<<endl;
}

  if(key==3)
{
cout<<"How Many Numbers You Want To Subtract\n";
cin>>n;
cout<<"Enter Your Numbers\n";
for(int i=1;i<=n;i++)
{
cin>>number;
if(i==1)
{
res=number;
}
else
res=res-number;
}
cout<<res<<endl;
}
  if(key==4)
{
      res=0;
cout<<"Enter Two Numbers To Divide\n";
cin>>n>>n1;
if(n1==0)
{
cout<<"Inf"<<endl;
}
else
{
res=n/n1;
cout<<res<<endl;
}
}
if(key==5)
{
cout<<"Exit";
break;
 }
 }
}

int fun2()
{
 while(1)
 {

cout<<"\n\n\t\t\tMain Menu\n\n\n";
  cout<<"Press 1: To Find Power\n";
cout<<"Press 2: To Find Log\n";
cout<<"Press 3: To Find Sqaure Root\n";
cout<<"Press 4: To Exit\n";
cin>>key;
if(key==1)
{
cout<<"Enter Number To Find Power\n";
cin>>number;
cout<<"Enter Power \n";
cin>>power;
res=pow(number,power);
cout<<res;
}

if(key==2)
{
cout<<"Enter Number To Find Log\n";
cin>>number;
res=log(number);
cout<<res;
}
 
  if(key==3)
  {
  cout<<"Enter Number To Find Sqaure Root\n";
cin>>number;
res=sqrt(number);
cout<<res;
}

if(key==4)
{
cout<<"Bye";
break;
   }
 }
}
};
 main()
 {
trignometric obj;
int num;
while(1)
{
cout<<"\t\t\tMain Menu\n\n";
       cout<<"Press :1 For trignometric Functions \n";
cout<<"Press :2 For Normal Mathematics \n";
cout<<"Press :3 For Other Operation\n";
cin>>num;

if(num==1 || num==2 || num==3 )
{
if(num==1)
{
  obj.fun();
}
if(num==2)
{
  obj.fun1();
   }
if(num==3)
{
  obj.fun2();
}
}
  }

 }

======================================================================== 


OutPut:







SHARE
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment