Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <sstream>
- #include <string>
- #include <cmath>
- #include <vector>
- #include <exception>
- #include <ctime>
- #include <ctype.h>
- using std::cout;
- using std::cin;
- using std::endl;
- using std::string;
- using std::vector;
- using std::stringstream;
- void DrawLine (string Str, int Len = 80)
- {
- int x = 0;
- cout << endl;
- for (int i = 0; i < Len;i++)
- {
- cout << Str[x];
- if (x == Str.size())
- x = 0;
- }
- if (Len != 80)
- cout << endl;
- }
- class Calculator
- {
- private:
- long double Num1;
- long double Num2;
- public:
- void SetVal(int, int);
- long double Add ();
- long double Subtract();
- long double Multiply();
- long double Divide();
- int Mod();
- long double Expon();
- }
- calculator,
- *Calc;
- void Calculator::SetVal(int a, int b)
- {
- Num1 = a;
- Num2 = b;
- }
- long double Calculator::Add()
- {
- return Num1 + Num2;
- }
- long double Calculator::Subtract()
- {
- return Num1-Num2;
- }
- long double Calculator::Multiply()
- {
- return Num1*Num2;
- }
- long double Calculator::Divide ()
- {
- return Num1/Num2;
- }
- int Calculator::Mod()
- {
- return ((int(Num1))% (int(Num2)));
- }
- long double Calculator::Expon()
- {
- int X = 1;
- if (Num2 < 0)
- {
- for (int i = 0; i < int(Num2); i++)
- {
- X *= Num1;
- }
- return X;
- }
- else if (Num2 == 0)
- return 1;
- else if (Num2 < 0)
- {
- Num2 *= (-1);
- for (int i = 0; i < int(Num2); i++)
- {
- X *= Num1;
- }
- X /= X*X;
- return X;
- }
- }
- int main ()
- {
- stringstream Ent1, Ent2, Oper;
- bool Check1 = true;
- bool Check2 = false;
- string Action;
- int x, y;
- string a , b;
- Calc = &calculator;
- cout << "This calculator can calclulate a couple of thing that listed are in the Table shown below.";
- cout << "To tell the computer wha to calculate simply write the Expression.\n";
- cout << "NOTE: 1. Only one operator & two Numbers are allowed in the expression.\n";
- cout << "2. No variables are allowed";
- cout << "What do you want to calculate: ";
- getline (cin, Action);
- for (int i = 0; i < Action.size(); i++)
- {
- if (isdigit(Action[i]) && Check1)
- {
- Ent1 << Action[i];
- }
- else if (!isalnum(Action[i]))
- {
- Oper << Action[i];
- Check1 = false;
- Check2 = true;
- }
- else if (isdigit(Action[i]) && Check2)
- {
- Ent2 << Action[i];
- }
- }
- a = Ent1.str();
- b = Ent2.str();
- x = atoi(a.c_str());
- y = atoi(b.c_str());
- Calc -> SetVal(x,y);
- ;cout << "\n\nPress Enter to exit . . .";
- cin.sync();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement