Project Scientific Calculator by Classes

14
#include <iostream> #include <conio.h> #include <math.h> using namespace std; const double pi=3.141592655358; class boardofcalc { public: void board() { cout<<"what do you want to find ? Enter "<<endl //board of scientifc calculater <<" //////////////////////////////////////"<<endl <<"||| |||"<<endl <<"||| |||"<<endl <<" /////////////////////////////////////"<<endl <<" + "<<"|"<<" - "<<"|"<<" * "<<"|"<<" / "<<"|"<<" 1 "<<"|"<<" 2 "<<"|"<<" 3 "< <"|"<<endl <<"============================"<<endl <<" S "<<"|"<<" C "<<"|"<<" T "<<"|"<<" I "<<"|"<<" 4 "<<"|"<<" 5 "<<"|"<<" 6 "< <"|"<<endl <<"============================"<<endl <<" p "<<"|"<<" s "<<"|"<<" L "<<"|"<<" = "<<"|"<<" 7 "<<"|"<<" 8 "<<"|"<<" 9 "< <"|"<<endl <<"============================"<<endl << " P "<<"|"<<" . "<<"|"<<" 0 "<<"|"<<" = "< <"|" ; } void explain() { cout<<endl<<endl; //explainanntion of operators cout<<"IN ABOVE BOARD........"<<endl <<" + =For three kinds of addition Normal, Complex ,Fraction "<<endl <<" - =For three kinds of subtraction Normal, Complex ,Fraction "<<endl <<" * =For three kinds of multiplication Normal, Complex ,Fraction "<<endl <<" / =For three kinds of division Normal, Complex ,Fraction "<<endl <<" S =Sin of number "<<endl<<" C =Cos of number "<<endl <<" T=Tan of number "<<endl<<"small 'p' =Power of number (Normal and Fraction Nu mbers) "<<endl <<" I=Inverse of Sin Cos and Tan "<<endl<<"small 's' =Square root of number "<<e ndl <<" P=capital 'P' for percentage "<<endl<<" L =For (Natural and Base10 log) "; } }; class calculation : public boardofcalc //In this class calculations of Norm al numbrers are done { private: double num1,num2,num3; public: //////////////////////////////////////////////////////////////////////////////// void addition() //definition of addition function { double number; num3=0; cout<<"enter 1st number = "; //getting input from user cin>>num1; cout<<"enter 2nd number = "; cin>>num2;

Transcript of Project Scientific Calculator by Classes

#include <iostream>#include <conio.h>#include <math.h>using namespace std;const double pi=3.141592655358;class boardofcalc{public:void board(){cout<<"what do you want to find ? Enter "<<endl //board of scientifc calculater <<" //////////////////////////////////////"<<endl<<"||| |||"<<endl<<"||| |||"<<endl <<" /////////////////////////////////////"<<endl<<" + "<<"|"<<" - "<<"|"<<" * "<<"|"<<" / "<<"|"<<" 1 "<<"|"<<" 2 "<<"|"<<" 3 "<<"|"<<endl<<"============================"<<endl<<" S "<<"|"<<" C "<<"|"<<" T "<<"|"<<" I "<<"|"<<" 4 "<<"|"<<" 5 "<<"|"<<" 6 "<<"|"<<endl<<"============================"<<endl<<" p "<<"|"<<" s "<<"|"<<" L "<<"|"<<" = "<<"|"<<" 7 "<<"|"<<" 8 "<<"|"<<" 9 "<<"|"<<endl<<"============================"<<endl<< " P "<<"|"<<" . "<<"|"<<" 0 "<<"|"<<" = "<<"|" ;}void explain(){cout<<endl<<endl; //explainanntion of operatorscout<<"IN ABOVE BOARD........"<<endl<<" + =For three kinds of addition Normal, Complex ,Fraction "<<endl<<" - =For three kinds of subtraction Normal, Complex ,Fraction "<<endl<<" * =For three kinds of multiplication Normal, Complex ,Fraction "<<endl<<" / =For three kinds of division Normal, Complex ,Fraction "<<endl<<" S =Sin of number "<<endl<<" C =Cos of number "<<endl<<" T=Tan of number "<<endl<<"small 'p' =Power of number (Normal and Fraction Numbers) "<<endl<<" I=Inverse of Sin Cos and Tan "<<endl<<"small 's' =Square root of number "<<endl<<" P=capital 'P' for percentage "<<endl<<" L =For (Natural and Base10 log) ";}};class calculation : public boardofcalc //In this class calculations of Normal numbrers are done{private:double num1,num2,num3;public:////////////////////////////////////////////////////////////////////////////////void addition() //definition of addition function{double number;num3=0;cout<<"enter 1st number = "; //getting input from usercin>>num1;cout<<"enter 2nd number = ";cin>>num2;

num3=num1+num2;cout<<"Addition is = "<<num3; //priting resultcout<<endl<<endl;cout<<"how many more numbers you will add to the result = "; //asking for more additioncin>>number;for(int i=1;i<=number;i++){cout<<endl;cout<<"enter number = ";cin>>num1;num3=num3+num1;cout<<"Addition is = "<<num3;}}////////////////////////////////////////////////////////////////////////////////void subtraction() //definition of subtraction function{double number;num3=0;cout<<"enter 1st number = ";cin>>num1; //getting input from usercout<<"enter 2nd number = ";cin>>num2;num3=num1-num2;cout<<"subtraction is = "<<num3;cout<<endl<<endl;cout<<"how many more numbers you will subtract to the result = "; //asking for more subtractioncin>>number;for(int i=1;i<=number;i++){cout<<endl;cout<<"enter number = ";cin>>num1;num3=num3-num1;

cout<<"Subtraction is = "<<num3;

}

}////////////////////////////////////////////////////////////////////////////////void multiply() //definition of multiplication function{double number;num3=1;cout<<"enter 1st number = "; //getting inputcin>>num1;

cout<<"enter 2nd number = ";cin>>num2;

num3=num1*num2;

cout<<"Mutiplication is = "<<num3; //printing result

cout<<endl<<endl;

//telling user that he wants more multiplication with that number or not

cout<<"how many more numbers you will multiply to the result = ";cin>>number; //getting inputfor(int i=1;i<=number;i++){cout<<endl;

cout<<"enter number = ";cin>>num1;

num3=num3*num1;

cout<<"Multiplication is = "<<num3; //printing result

}

}////////////////////////////////////////////////////////////////////////////////void division() //{double number;num3=1;

cout<<"enter 1st number = "; //getting input from usercin>>num1;

cout<<"enter 2nd number = ";cin>>num2;

num3=num1/num2;

cout<<"Division is = "<<num3; //printing result

cout<<endl<<endl;

cout<<"how many more numbers you will division to the result = "; //telling user that he wants more division with that number or notcin>>number;for(int i=1;i<=number;i++){ //getting input from usercout<<endl;

cout<<"enter number = ";cin>>num1; //calculations

num3=num3/num1;

cout<<"Division is = "<<num3; //printing result

}

}////////////////////////////////////////////////////////////////////////////////void power()

{cout<<"enter number = ";cin>>num1; //getting input from user

cout<<"enter power which you wnat = ";cin>>num2;

num3=1;

for(int i=1;i<=num2;i++){num3=num3*num1;}

cout<<"Power is = "<<num3; //printing power of number}////////////////////////////////////////////////////////////////////////////////

void squareroot(){

cout<<"enter number = "; //getting input from usercin>>num1;

num2=sqrt(num1);

cout<<"square root is = "<<num2; //printing square root}

void base10log(){cout<<"enter number = "; //getting input from usercin>>num1;

num2=log10(num1);

cout<<"Answer is = "<<num2; //printing base10 log

}

void naturallog(){cout<<"enter number = "; //getting input from usercin>>num1;

num2=log(num1);

cout<<"Answer is = "<<num2; //printing log}

void percentage(){cout<<"enter number for which you want percentage = ";cin>>num1; //getting input from user

cout<<"enter number in which you want percentage = ";cin>>num2;

num3=(num1*100)/num2;

cout<<"Percentage is = "<<num3; //printing percentage}

};

////////////////////////////////////////////////////////////////////////////////

//END OF CLASS CALCULATIONS CLASS

////////////////////////////////////////////////////////////////////////////////

//BEGINING OF TRIGONOMETRY CLASS

////////////////////////////////////////////////////////////////////////////////

class trignometry{private:

double num1,num2;

public:

////////////////////////////////////////////////////////////////////////////////void fsin() //definition of sin functionn{

cout<<"enter the number for which you want sin = ";cin>>num1;

num2=sin(num1*pi/180.0);

cout<<"sin is = "<<num2;}////////////////////////////////////////////////////////////////////////////////

void fcos() //definition of cos function{cout<<"enter number = ";cin>>num1;

num2=cos(num1*pi/180.0);

cout<<"cos is = "<<num2;}////////////////////////////////////////////////////////////////////////////////void ftan() //definition of tan function{cout<<"enter number = ";cin>>num1;

num2=tan(num1*pi/180);

cout<<"Tan is = "<<num2;}//////////////////////////////////////////////////////////////////////////////// //definition of inverse of sin functionvoid invrsin(){

cout<<"enter number = ";cin>>num1;

num2=asin(num1)*180.0/pi;

cout<<"inverse of sin is = "<<num2;}

////////////////////////////////////////////////////////////////////////////////void invrcos() //definition of inverse of cos function{

cout<<"enter number = ";cin>>num1;

num2=acos(num1)*180.0/pi;

cout<<"inverse of cos is = "<<num2;}

////////////////////////////////////////////////////////////////////////////////

void invrtan() //definition of inverse of tan function{

cout<<"enter number = ";cin>>num1;

num2=atan(num1)*180.0/pi;

cout<<"inverse of tan is = "<<num2;

}////////////////////////////////////////////////////////////////////////////////

};

////////////////////////////////////////////////////////////////////////////////

//END OF CLASS TRIGNOMETRY CLASS

////////////////////////////////////////////////////////////////////////////////

//BEGINING OF CLASS FRACTION CLASS

////////////////////////////////////////////////////////////////////////////////

class fraction{private:double num1,num2,num3,num4,tot1,tot2,tot3,tot4,pow;char ch;public:////////////////////////////////////////////////////////////////////////////////

void fadd() //definition of finding additio of fraction numbers function{cout<<"enter 1st number in (Y/X) form = "; //getting input from usercin>>num1>>ch>>num2;

cout<<"enter 2nd number = ";cin>>num3>>ch>>num4;

tot1=num1*num4; //making calculationtot2=num2*num3;tot3=num2*num4;

tot4=tot1+tot2;

cout<<"Answer is = "<<tot4<<ch<<tot3; //printing Answers}/////////////////////////////////////////////////////////////////////////////////void fsub() //defintion of finding subtraction of fraction number function{cout<<"enter 1st number in (Y/X) form = "; //getting input from usercin>>num1>>ch>>num2;

cout<<"enter 2nd number = ";cin>>num3>>ch>>num4;

tot1=num1*num4; //making calculationtot2=num2*num3;tot3=num2*num4;tot4=tot1-tot2;

cout<<"Answer is = "<<tot4<<ch<<tot3; //printing Answers}////////////////////////////////////////////////////////////////////////////////void fmult() //defintion of finding multiplication of fraction number function{

cout<<"enter 1st number in (Y/X) form = ";cin>>num1>>ch>>num2; //getting input from usercout<<"enter 2nd number = ";cin>>num3>>ch>>num4;

tot1=num1*num3; //printing Answerstot2=num2*num4;

cout<<"Answer is = "<<tot1<<ch<<tot2; //printing Answers

}////////////////////////////////////////////////////////////////////////////////void fdivi() //defintion of finding division of fraction number function{

cout<<"enter 1st fraction number = ";cin>>num1>>ch>>num2; //getting input from user

cout<<"enter 2nd fraction number = ";cin>>num3>>ch>>num4; //printing Answerstot1=num1*num4;tot2=num2*num3;

cout<<"Answer is = "<<tot1<<ch<<tot2; //printing Answers

}////////////////////////////////////////////////////////////////////////////////

void fpower() //defintion of finding power of fraction number function{double i;num3=1;num4=1;

cout<<"enter number in fraction = ";cin>>num1>>ch>>num2; //getting input from user

cout<<"enter power = ";cin>>pow;

for(i=1;i<=pow;i++){num3=num3*num1;} //printing Answers

for(i=1;i<=pow;i++){num4=num4*num2;}

cout<<"power of that is = "<<num3<<ch<<num4; //printing Answers

}////////////////////////////////////////////////////////////////////////////////};////////////////////////////////////////////////////////////////////////////////

//END OF CLASS FRACTION

////////////////////////////////////////////////////////////////////////////////

//BEGINING OF CLASS COMPLEX

////////////////////////////////////////////////////////////////////////////////

class complex{private:double num1,num2,num3,num4,tot1,tot2,tot3,tot4;char ch,i;

public:

void cadd() //definition of funtion of comlex numbers addition{

cout<<"enter complex number in (a+bi) format = "; //getting input in a+bi formcin>>num1>>ch>>num2>>i;

cout<<"enter 2nd number = ";cin>>num3>>ch>>num4>>i;

tot1=num1+num3;tot2=num2+num4;

cout<<"answer is = "<<tot1<<ch<<"("<<tot2<<")"<<i; //printing answer

}////////////////////////////////////////////////////////////////////////////////void csub(){ //definition of complex subtraction functioncout<<"enter 1st complex number = ";cin>>num1>>ch>>num2>>i;

cout<<"enter 2nd complex number = ";cin>>num3>>ch>>num4>>i;

tot1=num1-num3;tot2=num2-num4;

cout<<"answer for subtration is = "<<tot1<<ch<<"("<<tot2<<")"<<i; //printing answer

}

///////////////////////////////////////////////////////////////////////////////void cmult() //definition of complex multiplication function{

cout<<"enter 1st complex number = ";cin>>num1>>ch>>num2>>i; //getting input

cout<<"enter 2nd complex number = ";cin>>num3>>ch>>num4>>i;

tot1=(num1*num3)+(-(num2*num4));tot2=(num1*num4)+(num2*num3);

cout<<"your answer in multipication is = "<<tot1<<ch<<"("<<tot2<<")"<<i;//printing answer

}////////////////////////////////////////////////////////////////////////////////

void cdivi(){ //definition of complex division function

cout<<"enter 1st complex number = ";cin>>num1>>ch>>num2>>i;

cout<<"enter 2nd complex number = ";cin>>num3>>ch>>num4>>i;

tot1=(num1*num3)+(num2*(-num4));tot2=(num1*(-num4))+(num2*num3);tot3=(num3*num3)-(num4*(-num4));

cout<<"your answer in division is = "<<tot1<<ch<<"("<<tot2<<i<<")"<<"/"<<tot3; //printing answer

}

////////////////////////////////////////////////////////////////////////////////};

////////////////////////////////////////////////////////////////////////////////

//END OF CLASS COMPLEX

////////////////////////////////////////////////////////////////////////////////

//BEGINING OF MAIN

////////////////////////////////////////////////////////////////////////////////

main(){calculation c1; //Object of calculation class is createdtrignometry t1; //Object oftrignometry class is createdfraction f1; //object of fraction class is createdcomplex co1; //object of complex class is created

char choice,choice1; //decleration of variableschar ct,ct1,ct2,ct3,ct4,ct5; //ct=choice type////////////////////////////////////////////////////////////////////////////////do //do while loop starts{cout<<endl;c1.board(); //calling to board function of boardofcal classc1.explain(); // calling to explain function of boardofcal classcout<<endl<<"__________________________________________________________"<<endl<<"__________________________________________________________"<<endl<<endl;

cout<<"Enter operator = "; //getting operator from userscin>>choice;////////////////////////////////////////////////////////////////////////////////

if(choice=='+') //checking operator{cout<<"what type of addition do you want N(normal),F(fraction),C(complex) = ";cin>>ct;

if(ct=='N'||ct=='n'){ //calling to addition function of calculation classc1.addition();}

else if(ct=='F'||ct=='f'){f1.fadd(); //calling to addtion function of fraction class}

else if(ct=='C'||ct=='c'){

co1.cadd(); //calling to addition function of comlex class}else{cout<<"invlaid entry!!!!!!!!!!!!!";}}

////////////////////////////////////////////////////////////////////////////////

else if(choice=='-'){cout<<"what type of subtraction do you want N(normal),F(fraction),C(complex) = ";cin>>ct1;if(ct1=='N'||ct1=='n'){ //calling to subtraction function of calculation classc1.subtraction();}

else if(ct1=='F'||ct1=='f'){f1.fsub(); //calling to subtraction function of fraction class}

else if(ct=='C'||ct=='c'){

co1.csub(); //calling to subtraction function of comlex class}}////////////////////////////////////////////////////////////////////////////////

else if(choice=='*'){cout<<"what type of multiplication do you want N(normal)"<<endl<<"F(fraction),C(complex) = ";cin>>ct2;if(ct2=='N'||ct2=='n'){c1.multiply(); //calling to multiplication function

of calculation class}

else if(ct2=='F'||ct2=='f'){f1.fmult(); //calling to multiplication function of fraction class}

else if(ct2=='C'||ct2=='c'){

co1.cmult(); //calling to multiplication function of comlex class}}

////////////////////////////////////////////////////////////////////////////////

else if(choice=='/'){cout<<"what type of division do you want N(normal)"<<endl<<"F(fraction),C(complex) = ";cin>>ct3;

if(ct3=='N'||ct3=='n'){c1.division(); //calling to division function of calculation class}

else if(ct3=='F'||ct3=='f'){f1.fdivi(); //calling to division function of fraction class}

else if(ct3=='C'||ct3=='c'){ //calling to division function of complex classco1.cdivi();}

}

////////////////////////////////////////////////////////////////////////////////

else if(choice=='p'){cout<<"enter what type of numbers power do you want N(normal),"<<endl<<"F(fraction) = ";cin>>ct4;if(ct4=='N'||ct4=='n'){c1.power(); //calling to power function of calculation class}else if(ct4=='F'||ct4=='f')

{f1.fpower(); //calling to power function of fraction class}

}

////////////////////////////////////////////////////////////////////////////////

else if(choice=='s'){c1.squareroot(); //calling to square root function of calculation class}

////////////////////////////////////////////////////////////////////////////////else if(choice=='L'||choice=='l'){

cout<<"what type of log do you want N(Natural log) L(base10 log) = ";cin>>ct5;

if(ct5=='N'){c1.naturallog(); //calling to natural log function of calculatoin class}

else if(ct5=='L'||ct5=='l'){c1.base10log(); //calling to base10 log function of calculatoin class}

}////////////////////////////////////////////////////////////////////////////////else if(choice=='P'){c1.percentage(); //calling to percentage function of calculation class

}

////////////////////////////////////////////////////////////////////////////////else if(choice=='S'){t1.fsin();} //calling to sin function of trignometry class

////////////////////////////////////////////////////////////////////////////////

else if(choice=='C'||choice=='c'){t1.fcos(); //calling to cos function of trignometric class}

////////////////////////////////////////////////////////////////////////////////

else if(choice=='T'||choice=='t'){t1.ftan(); //calling to tan function of trignometric class

}////////////////////////////////////////////////////////////////////////////////

else if(choice=='I'|| choice=='i'){cout<<"For which you want inverse enter S for sine, C for cos, T for tan = ";cin>>ct2;

if(ct2=='S'||ct2=='s' ){ //calling to inverse sin function of trignometry classt1.invrsin();}

else if(ct2=='C'||ct2=='c'){t1.invrcos(); //calling to inverse cos function of trignometric class}

else if(ct2=='T'||ct2=='t'){t1.invrtan(); //calling to inverse tan function of trignometric class}}

////////////////////////////////////////////////////////////////////////////////

cout<<endl<<endl;

////////////////////////////////////////////////////////////////////////////////cout<<"-----------------------------------------------------------------------"<<endl<<endl;cout<<"Do you want more calculations = ";cin>>choice1;

if(choice1!='y'&& choice1!='n'){cout<<"you have entered wrong choice!!!!!!!!!!";}

}while(choice1!='n');

////////////////////////////////////////////////////////////////////////////////getch();return 0;}

////////////////////////////////////////////////////////////////////////////////

// END OF PROGRAM

////////////////////////////////////////////////////////////////////////////////