Go: package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;

int calculation( int a, int b, char c )
{
    if( c == '+' )
        return a + b;
    else if( c == '-' )
        return a - b;
    else if( c == '*' )
        return a * b;
    else if( c == '/' )
        return a / b;
    else
        return a;
}

int main()
{
    int n;
    vector<int> d, p;
    vector<char> f;
    string str;


    cin >> n;

    for( int k = 0; k < n; k++ )
    {
        cin >> str;

        for( int i = 0; d.size(); i++ )
        {
            d.pop_back();
            p.pop_back();
            f.pop_back();
        }

        int plus = 0;
        for( int i = 0; i < str.size(); i++ )
        {
            int a = str[i] - '0', j = i;
            while( 0 <= a && a < 10 )
            {
                j++;
                a = str[j] - '0';
            }
            int sum = 0, mul = 1;
            for( int s = 0; s < j - i; s++ )
            {
                sum += ( str[j-(s+1)] - '0' ) * mul;
                mul *= 10;
            }
            if( 0 <= str[i] - '0' && str[i] - '0' < 10 )
            {
                d.push_back(sum);
                while( mul != 1 )
                {
                    i++;
                    mul /= 10;
                }
                i--;
            }
            else
            {
                if( str[i] == '+' || str[i] == '-' )
                    p.push_back( plus + 1 );
                else if( str[i] == '*' || str[i] == '/' )
                    p.push_back( plus + 2 );
                else if( str[i] == '(' )
                    plus += 3;
                else if( str[i] == '=' )
                    p.push_back(0);
                else
                    plus -= 3;
                if( str[i] != '(' && str[i] != ')' )
                    f.push_back(str[i]);
            }
        }

        // for( int i = 0; i < d.size(); i++ )
        //     cout << d[i] << " ";
        // cout << endl;

        // for( int i = 0; i < p.size(); i++ )
        //     cout << p[i] << " ";
        // cout << endl;

        // for( int i = 0; i < f.size(); i++ )
        //     cout << f[i] << " ";
        // cout << endl;

        while( f[0] != '=' )
        {
            for( int i = 0; i < p.size() - 1; i++ )
            {
                if( p[i] > p[i+1] )
                {
                    d[i] = calculation( d[i], d[i+1], f[i] );
                    f[i] = f[i+1];
                    p[i] = p[i+1];

                    int s = i;
                    while( s + 2 < p.size() )
                    {
                        d[s+1] = d[s+2];
                        f[s+1] = f[s+2];
                        p[s+1] = p[s+2];
                        s++;
                    }
                }
            }
        }
        cout << d[0] << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cctype>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>

int apply(int lhs, char op, int rhs) {
  switch (op) {
  case '+': return lhs+rhs;
  case '-': return lhs-rhs;
  case '*': return lhs*rhs;
  case '/': return lhs/rhs;
  }
  assert(false);
}

int parse(const std::string &s, size_t &i, size_t preced=0) {
  const std::vector<std::string> ops={"+-", "*/"};
  if (preced == ops.size()) {
    if (s[i] == '(') {
      int res=parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (isdigit(s[i])) {
      int res=s[i]-'0';
      while (++i < s.length() && isdigit(s[i]))
        res = res*10+s[i]-'0';
      return res;
    }
    assert(false);
  }
  int res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    int tmp=parse(s, ++i, preced+1);
    res = apply(res, op, tmp);
  }
  return res;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i=0; i<n; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string s=buf;
    size_t j=0;
    printf("%d\n", parse(s, j));
  }
}

C++: #include <iostream>
#include <string>
#include <cctype>
#include <sstream>

using namespace std;

typedef string::const_iterator Cursor;
class ParseError{};

// <四則演算の式> ::= <乗算除算の式> (+ or -) <乗算除算の式> (+ or -) ...
// <乗算除算の式> ::= <括弧か数> (* or /) <括弧か数> (* or /) ...
// <括弧か数>     ::= '(' <四則演算の式> ')' or <数>
// <数>           ::= (0|1|2|3|4|5|6|7|8|9)+

int expression(Cursor&);
int term(Cursor&);
int factor(Cursor&);
int number(Cursor&);

// <四則演算の式> ::= <乗算除算の式> (+ or -) <乗算除算の式> (+ or -) ...
int expression(Cursor &c){
    int ret = term(c);
    while(*c == '+' or *c == '-'){
        if(*c == '+'){
            c++;
            ret += term(c);
        }else{
            c++;
            ret -= term(c);
        }
    }
    return ret;
}

// <乗算除算の式> ::= <括弧か数> (* or /) <括弧か数> (* or /) ...
int term(Cursor &c){
    int ret = factor(c);
    while(*c == '*' or *c == '/'){
        if(*c == '*'){
            c++;
            ret *= term(c);
        }else{
            c++;
            ret /= term(c);
        }
    }
    return ret;
}

// <括弧か数>     ::= '(' <四則演算の式> ')' or <数>
int factor(Cursor &c){
    if(*c == '('){
        c++;
        int ret = expression(c);
        // ')'
        c++;
        return ret;
    }else{
        return number(c);
    }
}

// <数>           ::= (0|1|2|3|4|5|6|7|8|9)+
int number(Cursor &c){
    stringstream ss;
    while(isdigit(*c)){
        ss << *c;
        c++;
    }
    int ret;
    ss >> ret;
    return ret;
}

int main(){
    int test_case;
    cin >> test_case;
    cin.ignore();
    for(int i=0;i<test_case;i++){
        string s;
        getline(cin,s);
        string inp = s.substr(0,s.size()-1);
        Cursor c = inp.begin();
        cout << expression(c) << endl;
    }
    return 0;
}