Professional Documents
Culture Documents
Scientific Calculator
Scientific Calculator
Scientific Calculator
Introduction
Nothing much about to write about this program other than this, that it simply performs arithmetic or scientific calculator calculations depending upon selection from the main menu. I have put those two under different scenarios so that the menu system is less cluttered. This performs all the basic tasks that an ordinary calculator does and an ok-ok scientific calculator does. Just my way of putting this in a different way is reflected.
//Not a Complete Code I'd say, could have added more mysterious feautres if //alotted more time .. // VikaSingh Section:B1805 [AIEEE Batch] #include<iostream.h> #include<dos.h> #include<windows.h> #include<process.h> #include<conio.h> #include<math.h> class simple { float a,b; public: void simple_arith(); void scientific_arith(); void menu(); void getdata() { cout<<"\n-----------------"; cout<<"\nEnter Values .. "; cout<<"\n-----------------"; cout<<"\n\nEnter A: "; cin>>a; cout<<"\nEnter B: "; cin>>b; } int sum() { return(a+b); } int diff() { return(a-b); } int mul() { return(a*b); } float div()
{ return(a/b); } }; void simple :: menu() { clrscr(); int ch; cout<<" \n ||||| CalculaTR Main Menu ||||| "; cout<<"\n\n1.Simple Arithmetic"; cout<<"\n\n2.Scientific Arithmetic"; cout<<"\n\n3.Exit"; cout<<"\n\nEnter your choice[1-3]: "; cin>>ch; switch(ch) { case 1:simple_arith(); break; case 2:cout<<"Still to Program .."; scientific_arith(); break; case 3:cout<<"\nExiting ..."; getch(); exit(0); break; default:cout<<"\n\aInvalid Choice .. Try Again !!"; menu(); break; } } void simple :: simple_arith() { clrscr(); int a,ch; float b; cout<<"||||| Simple Arithmetic Menu |||||"; cout<<"\n\n1.Add"; cout<<"\n\n2.Subtract"; cout<<"\n\n3.Multiply"; cout<<"\n\n4.Divide"; cout<<"\n\n5.Return to Previous Menu"; cout<<"\n\nEnter your choice [1-5]: "; cin>>ch;
switch(ch) { case 1:getdata(); a=sum(); cout<<"\n\nSum = "<<a; getch(); cout<<"\n\nRedirecting to Main Menu .. "; getch(); menu(); break; case 2:getdata(); a=diff(); cout<<"\nDifference = "<<a; getch(); cout<<"\n\nRedirecting to Main Menu .. "; getch(); menu(); break; case 3:getdata(); a=mul(); cout<<"\nMultiplication = "<<a; getch(); cout<<"\n\nRedirecting to Main Menu .. "; getch(); menu(); break; case 4:getdata(); b=div(); cout<<"\nQuotient:"<<b; getch(); cout<<"\n\nRedirecting to Main Menu .. "; getch(); menu(); break; case 5:cout<<"\n\nRedirecting to Previous Menu .."; getch(); menu(); break; default:cout<<"\n\aInvalid .. Try Again .."; getch(); menu(); break; } } void simple :: scientific_arith()
{ clrscr(); int ch; int ang; int x,y; cout<<" ||||| Scientific Arithmetic Menu |||||"; cout<<"\n\n1. sin()"; cout<<"\n2. cos()"; cout<<"\n3. tan()"; cout<<"\n4. log()"; cout<<"\n5. Square Root"; cout<<"\n6. x^y"; cout<<"\n\nEnter your choice: "; cin>>ch; switch(ch) { case 1:cout<<"\nEnter Angle in radians:"; cin>>ang; cout<<"\nSin("<<ang<<")"<<" = "<<sin(ang); cout<<"\n\nRedirecting to Main Menu ..."; sleep(2); menu(); break; case 2:cout<<"\nEnter Angle in radians:"; cin>>ang; cout<<"\nCos("<<ang<<")"<<" = "<<cos(ang); cout<<"\n\nRedirecting to Main Menu ..."; sleep(2); menu(); break; case 3:cout<<"\nEnter Angle in radians:"; cin>>ang; cout<<"\ntan("<<ang<<")"<<" = "<<tan(ang); cout<<"\n\nRedirecting to Main Menu ..."; sleep(2); menu(); break; case 4:cout<<"\nEnter Value:"; cin>>ang; cout<<"\nLog("<<ang<<")"<<" = "<<log(ang); cout<<"\n\nRedirecting to Main Menu ..."; sleep(2); menu(); break; case 5:cout<<"\nEnter Value to find Square Root:";
cin>>ang; cout<<"\nSqrt("<<ang<<")"<<" = "<<sqrt(ang); cout<<"\n\nRedirecting to Main Menu ..."; sleep(2); menu(); break; case 6:cout<<"\nEnter Value for x in x^y: "; cin>>x; cout<<"\nEnter Value for y in x^y: "; cin>>y; cout<<"\n"<<x<<" raised to "<<y<<" = "<<pow(x,y); cout<<"\n\nRedirecting to Main Menu ..."; sleep(2); menu(); break; default:cout<<"\n\aInvalid Selection !!!! Try Again ..."; sleep(2); menu(); break; } } void main() { clrscr(); simple s1; s1.menu(); getch(); }