Ad
Code
Diff
  • #include <ostream>
    #include <cmath>
    using namespace std;
    
    string calculator(int a, char op, int b) {
        stringstream s;
        switch (op) {
            case '+': {s<<a+b; return s.str();}
            case '-': {s<<a-b; return s.str();}
            case '*': {s<<a*b; return s.str();}
            case '/': {b != 0 ? s<<a/b : s<<"Invalid Input!"; return s.str();}
            case '%': {s<<a%b; return s.str();}
            case '^': {s<<pow((float)a, b); return s.str();}
            default: return "Invalid Input!";
        }
    }
    
    • #include <ostream>
    • #include <cmath>
    • using namespace std;
    • string calculator(int a, char op, int b) {
    • stringstream s;
    • switch (op) {
    • case '+': {s<<a+b; return s.str();}
    • case '-': {s<<a-b; return s.str();}
    • case '*': {s<<a*b; return s.str();}
    • case '/': {b != 0 ? s<<a/b : s<<"Invalid Input!"; return s.str();}
    • case '%': {s<<a%b; return s.str();}
    • case '^': {s<<pow((float)a, b); return s.str();}
    • default: return "Invalid Input!";
    • }
    • }

Inlined

Code
Diff
  • inline float AreaOfTriangle(float w, float h) {return w * h / 2;} //inlined
    • float AreaOfTriangle(float w, float h) {return (w * h) / 2;} //Get one-lined
    • inline float AreaOfTriangle(float w, float h) {return w * h / 2;} //inlined