Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Needed header files
- #include <iostream> // Console I/O
- #include <string> // String support
- #include <windows.h> // Sleep statement
- using namespace std; // So I don't have to type std::
- class App // Application functions
- {
- public:
- float getValue() // Get a number from user
- {
- float num;
- cout << "Enter a number..." << endl;
- cin >> num;
- cout << "\n";
- return num;
- }
- string getOp() // Get the operation from user
- {
- string op;
- cout << "What operation do you want to perform?" << endl;
- cin >> op;
- cout << "\n";
- return op;
- }
- };
- class Math // Math operations
- {
- public:
- float Add(float a, float b)
- {
- return a + b;
- }
- float Subtract(float a, float b)
- {
- return a - b;
- }
- float Multiply(float a, float b)
- {
- return a * b;
- }
- float Divide(float a, float b)
- {
- return a / b;
- }
- };
- int main()
- {
- try // For errors
- {
- App App; // App class object
- Math Math; // Math class object
- cout << "Welcome to cCalc.\n" << "by: Brendan Gowen\n" << "http://www.github.com/thatoneguy107\n\n";
- // Numbers for calculation
- float x = App.getValue();
- float y = App.getValue();
- string operation = App.getOp();
- if (operation == "add")
- {
- cout << "The answer is: " << Math.Add(x, y);
- }
- cout << "The answer is: " << Math.Add(x, y);
- }
- if (operation == "subtract")
- {
- cout << "The answer is: " << Math.Subtract(x, y);
- }
- if (operation == "multiply")
- {
- cout << "The answer is: " << Math.Multiply(x, y);
- }
- if (operation == "divide")
- {
- cout << "The answer is: " << Math.Divide(x, y);
- }
- Sleep(3000); // Allow user to see output
- return 0;
- }
- catch(...) // Unexpected exception handling
- {
- cout << "Unexpected error." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement