Calculator++, Now Available for download on SourceForge!

Status
Not open for further replies.
Welp, Back to the drawing boards.

I'm also looking for suggestions on additional functions. so suggest some.
 
UPDATE:
I Noticed that my cout was getting a little big so I replaced it with an fstream so the list of of functions pops up in notepad. However whenever i compile it notepad doesn't pop up. Could someone paste this into their compiler and tell me if this works for them, and point out any bugs if any.
Thanks,
eXtensible

Code:
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <fstream>



using namespace std;
int main()
{
     int WhichFunction;
     bool user_quit;
     
     user_quit = false;
     
     do
       {
ofstream file;
file.open("Functions.txt");
file << "What would you like to do ? " << endl << "HINT: 1 = Add, 2 = Subtract, 3 = Multiply, 4 = Divide, 5 = Sqr. Root," << endl << "6 = Exponents, 7 = Pythagorean Theorum, 8 = Sine, 9 = Cosine, 10 = Tangent," << endl << "11 = Circumference, 12 = Area of Circles, 13 = Natural Logarithms, 14 = Area of Squares,15 = Area of Triangles, 16 = Perimeter of Squares, 17 = Absolute Value," << endl << "18 = Volume of Cubes, Rect. Prisms, 19 = Volume of Cylinders," << endl << "20 = Volume of Tri. Prisms, 21 = Round Down, 22 = Round Up, 23 = Cube Root," << endl << "24 = Density, 25 = Volume of Pyramids, 26 = Celsius to Fahrenheit," << endl << "27 = MPH to MPS, 28 = MPH to FPS, 29 = KPH to MPH, 30 = Common Logarithms," << endl << "31 = Volume of Cones, 99 = Quit" << endl;
file.close();
    
cin >> WhichFunction;
    switch(WhichFunction){
      
case 1:
           double a;
           cout << "Enter the first number: ";
           cin >> a;
           double b;
           cout << "Enter the second number: ";
           cin >> b;
           double c; 
           c = a + b;
           cout << "Calculating: " << c << endl;
           break;
      
case 2:
          double aa;
          cout << "Enter the first number: ";
          cin >> aa;
          double bb;
          cout << "Enter the second number: ";
          cin >> bb;
          double cc;
          cc = aa - bb;
          cout << "Calculating: " << cc << endl;
          break;
      
case 3:
          double a3;
          cout << "Enter the first number: ";
          cin >> a3;
          double b3;
          cout << "Enter the second number: ";
          cin >> b3;
          double c3;
          c3 = a3 * b3;
          cout << "Calculating: " << c3 << endl;
          break;
      
case 4:
          double a4;
          cout << "Enter the first number: ";
          cin >> a4;
          double b4;
          cout << "Enter the second number: ";
          cin >> b4;
          double c4;
          c4 = a4 / b4;
          
if(b4 > 0){
          cout << "Calculating: " << c4 << endl;  
          }
          
if(b4 <= 0){
          cout << "You Cannot Divide by Zero " << endl;
          system("PAUSE");
          return 0;      
          }
          break;
      
case 5:
           double a5;
           cout << "Enter Your Number: ";
           cin >> a5;
           double b5;
           b5 = sqrt(a5);
           cout << "Calculating: " << b5 << endl;
           break;
      
case 6:
           
           double a6,b6;
           cout << "Enter your Number: ";
           cin >> a6;
           cout << "Enter the Exponent: ";
           cin >> b6;
           double c6;
           c6 = pow(a6,b6);
           cout << "Calculating: " << c6 << endl;
           break;
      case 7:
           double a7;
           double b7;
           double c7;
           double x7;
           cout << "-----------------------" << endl;
           cout << " Pythagorean Theorem" << endl;
           cout << "-----------------------"  << endl;
           cout << "   ." << endl;
           cout << "   .  . " << endl;
           cout << " a .     . c" << endl;
           cout << "   .       . "<< endl;
           cout << "   .         ."<< endl;
           cout << "   ............."<< endl;
           cout << "        b      "<< endl;
           cout << endl;
           cout << "How to: " << endl;
           cout << endl;
           cout << "When asked for your missing variable type press '0' and then enter." << endl;
           cout << endl;
           cout << "Equation: a(sqaured) + b(square) = c(squared)" << endl;
           cout << endl;
           cout << "Please input your 'a' variable: ";
           cin >> a7;
           cout << "Please input your 'b' variable: ";
           cin >> b7;
           cout << "Please input your 'c' variable: ";
           cin >> c7;
          
 if (c7 == 0)
           {
           x7 = (a7*a7) + (b7*b7);
           cout << "Your missing length is " << sqrt(x7) << endl;
           }
          
 if (a7 == 0)
           {
           x7 = (c7*c7) - (b7*b7);
           cout << "Your missing length is " << sqrt(x7) << endl;
            }
           
 if (b7 == 0)
            {
            x7 = (c7*c7) - (a7*a7);
            cout << "Your missing length is " << sqrt(x7) << endl;
            }
            break;
      
case 8:
          double a8;
          cout << "Enter your Number: ";
          cin >> a8;
          cout << "The sine of your number is: " << sin(a8) << endl;
          break;
     
case 9:
          double a9;
          cout << "Enter your Number: ";
          cin >> a9;
          cout << "The Cosine of your Number is: " << cos(a9) << endl; 
          cout << "Would You Like to Run The Function Again?" << endl << "If YES Type 1, If NO Type 0" << endl;
          break;
     
case 10:
          double a10;
          cout << "Enter Your Number: ";
          cin >> a10;
          cout << "The Tangent of your Number is: " << tan(a10) << endl;
          break;
     
case 11:               
          double diameter;
          cout << "Enter Your Diameter: ";
          cin >> diameter;
          double circumference;
          circumference = diameter * 3.14;
          cout << "The circumference of your circle is: " << circumference <<  endl;
          break;
     
case 12:
          double radius;
          cout << "Enter Your Radius: ";
          cin >> radius;
          double area;
          area = 3.14 * pow(radius,2);
          cout << "Your Area Is: " << area << endl;
          break;
     
case 13:
          double a13;
          cout << "Enter your Number: ";
          cin >> a13;
          double b13;
          b13 = log(a13);
          cout << "Calculating: " << b13 << endl;
          break;
     
case 14:
          double base;
          double height;
          double area2;
          cout << "Enter the Base: ";
          cin >> base;
          cout << "Enter the Height: ";
          cin >> height;
          area = base * height;
          cout << "Calculating: " << area << endl;
          break;
     
case 15:
          double base2;
          double height2;
          double area3;
          cout << "Enter the Base: ";
          cin >> base2;
          cout << "Enter the Height: ";
          cin >> height2;
          area3 = (base2 * height2) / 2;
          cout << "Calculating: " << area3 << endl;
          break;
     
case 16:
          double side1;
          double side2;
          double side3;
          double side4;
          double perimeter;
          cout << "Enter the length of your first side: ";
          cin >> side1;
          cout << "Enter the length of your second side: ";
          cin >> side2;
          cout << "Enter the length of your third side: ";
          cin >> side3;
          cout << "Enter the length of your fourth side: ";
          cin >> side4;
          perimeter = side1 + side2 + side3 + side4;
          cout << "Calculating: " << perimeter << endl;
          break;
     
case 17:
          double a17;
          double b17;
          cout << "Enter Your Number: ";
          cin >> a17;
          b17 = fabs(a17);
          cout << "Calculating: " << b17 << endl;
          break;
     
case 18:
          double base3;
          double width;
          double height3;
          double volume;
          cout << "Enter Your Base: ";
          cin >> base3;
          cout << "Enter Your Width: ";
          cin >> width;
          cout << "Enter Your Height: ";
          cin >> height3;
          volume = base3 * width * height3;
          cout << "Calculating: " << volume << endl;
          break;
     
case 19:
          double radius2;
          double area4;
          double height4;
          double volume2;
          cout << "Enter Your Radius: ";
          cin >> radius2;
          area4 = pow(radius2,2);
          cout << "Enter your Height: ";
          cin >> height4;
          volume2 = area4 * height4;
          cout << "Calculating: " << volume2 << endl;
          break;
     
case 20:
          double base4;
          double height5;
          double height6;
          double area5;
          double volume3;
          cout << "Enter Your Base: ";
          cin >> base4;
          cout << "Enter Your Height: ";
          cin >> height5;
          area5 = base4 * height5;
          cout << "Enter Your Second Height: ";
          cin >> height6;
          volume3 = height6 * area5;
          cout << "Calculating: " << volume3 << endl;
          break;
     
case 21:
          double a21;
          double b21;
          cout << "Enter Your Number: ";
          cin >> a21;
          b21 = floor(a21);
          cout << "Calculating: " << b21 << endl;
          break;
     
case 22:
          double a22;
          double b22;
          cout << "Enter Your Number: ";
          cin >> a22;
          b22 = ceil(a22);
          cout << "Calculating: " << b22 << endl;
          break;
     
case 23:
          double val;
          cout << "Enter Your Number: ";
          
if (cin >> val){
          cout << "Cube Root of " << val << ": " << pow(abs(val), 1.0 / 3.0) << endl;        
          }
          break;
     
case 24:
          double mass;
          double volume4;
          double density;
          cout << "Enter The Mass of Your Object: ";
          cin >> mass;
          cout << "Enter The Volume of Your Object: ";
          cin >> volume4;
          density = mass / volume4;
          cout << "Calculating: " << density << " g/cm3, g/ml " << endl;
          break;
     
case 25: 
          double width25;
          double height25;
          double height25b;
          double volume25;
          cout << "Enter The Width of the Base: ";
          cin >> width25;
          cout << "Enter The Height of the Base: ";
          cin >> height25;
          cout << "Enter The Height of The Pyramid: ";
          cin >> height25b;
          volume25 = ((width25 * height25) *height25b) / 2;
          cout << "Calculating: " << volume25 << endl;
          break;
case 26:
          double fahrenheit;
          double celsius;
          cout << "Enter the Temperature in celsius: ";
          cin >> celsius;
          fahrenheit = (9/5) * celsius + 32;
          cout << "The Temperature in fahrenheit is: " << fahrenheit << endl;
          break;
case 27:
          double mph;
          double mps;
          cout << "Enter The Speed in Miles Per Hour: ";
          cin >> mph;
          mps = mph * 0.44704;
          cout << "The Speed in Meters Per Second Is: " << mps << endl;
          break;
case 28:
          double mph2;
          double fps;
          cout << "Enter The Speed in Miles Per Hour: ";
          cin >> mph2;
          fps = mph2 * 1.46666666666667;
          cout << "The Speed in Feet Per Second Is: " << fps << endl;
          break;
case 29:
          double kph;
          double mph3;
          cout << "Enter The Speed in Kilometers Per Hour: ";
          cin >> kph;
          mph3 = kph * 1.60934400061;
          cout << "The Speed in Miles Per Hour Is: " << mph3 << endl;
          break;
case 30:
          double a30;
          double b30;
          b30 = log10(a30);
          cout << "Enter Your Number: ";
          cin >> a30;
          cout << b30 << endl;
          break;
case 31:
          double base31;
          double radius31;
          double height31;
          double volume31;
          cout << "Enter Your Radius: ";
          cin >> radius31;
          base31 = pow(radius31,2) * 3.14;
          cout << "Enter Your Height: ";
          cin >> height31;
          volume31 = (base31 * height31) / 3;
          cout << "Calculating: " << volume31 << endl;
          break;
case 99:
          user_quit = true;
          break;
               
default:
          cout << "An Error Has Occured, Please try again. " << endl;
          break;
          }
          } 
          while (!user_quit);

    system("PAUSE");
    return EXIT_SUCCESS;
}
and to the people who suggested functions, thanks.
 
Why would you expect notepad to pop up? All your code does is write your Function list to a file called functions.txt. You would need to add additional code to invoke notepad but I personally don't see any advantage to it. What you might do is make your function list multi-lined or even make sub menus with like functions grouped together.
 
I personally don't think it's a good idea but if you wanted to invoke notepad.exe from within your program you could try the system function: system

BTW, if you go that method, you would only need to write the Functions.txt file once, after that you would only need to display it.
 
I would strongly suggest not saving (or writing) anything to file.
1) Users will not expect a calculator application to write anything to their filesystem, this on it's own is a good reason not to do it
2) If the calculator is invoked in a different directory, it will write a new Functions.txt
3) If the calculator is invoked in a diectory where the user does not have write permissions (or is mounted read-only), it will crash

Invoking notepad from your calculator is an even worse idea.
 
ok, So I Downloaded something called MathGL to Help me with functions using graphs. However I'm not sure how to start using it. Can anyone direct me to any tutorials for using MathGl.
Thanks,
eXtensible
 
Status
Not open for further replies.
Back
Top Bottom