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 <string>
#include <stack>
#include <cstdlib>
using namespace std;

int main() {
	/*const*/ string s;
	stack<int> num;
	stack<int> mar;
	int n1, n2;
	cin >> s;
	for ( int i = 0; i < 100; i++ ) {
		if ( s.substr( i, 1 ) == "+" ) {
			if ( mar.top() == 0 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 + n2 );
				mar.pop();
			} else if ( mar.top() == 1 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 - n2 );
				mar.pop();
			}
			mar.push(0);
		} else if ( s.substr( i, 1 ) == "-" ) {
			mar.push(1);
			if ( mar.top() == 0 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 + n2 );
				mar.pop();
			} else if ( mar.top() == 1 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 - n2 );
				mar.pop();
			}
		} else if ( s.substr( i, 1 ) == "*" ) mar.push(2);
		else if ( s.substr( i, 1 ) == "/" ) mar.push(3);
		else if ( s.substr( i, 1 ) == "(" ) mar.push(4);
		else if ( s.substr( i, 1 ) == ")" ) {
			if ( mar.top() == 0 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 + n2 );
				mar.pop();
			} else if ( mar.top() == 1 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 - n2 );
				mar.pop();
			}
				mar.pop();
		} else if ( s.substr( i, 1 ) == "=" ) {
			if ( mar.top() == 0 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 + n2 );
				mar.pop();
			} else if ( mar.top() == 1 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 - n2 );
				mar.pop();
			}
			cout << num.top();
			break;
		} else {
			n2 = atoi( s.c_str() );
			if ( mar.top() == 2 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 * n2 );
				mar.pop();
			} else if ( mar.top() == 3 ) {
				n1 = num.top();
				num.pop();
				num.push( n1 / n2 );
				mar.pop();
			} else 
				num.push( n2 );
		}
	}		
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int mul10 (int x, int y) {
    int ret = 1;
    for (int i = 0; i < x; i++) {
        ret *= 10;
    }
    ret *= y;
    return ret;
}

int cal (char sym, int x, int y) {
    if (sym == '+') {
        return x + y;
    } else if (sym == '*') {
        return x * y;
    } else if (sym == '-') {
        return x - y;
    } else if (sym == '/') {
        return x / y;
    }
}
int depth_parentheses (string str) {
    int count = 0;
    int count_max = 0;
    rep(i, str.length()) {
        if (str[i] == '(') count++;
        else if (str[i] == ')') count--;
        count_max = max(count_max, count);
    }
    return count_max;
}

int findL_parentheses (string str, int depth) {
    int L = 0;
    rep(i, str.length()) {
        if (str[i] == '(') L++;
        else if (str[i] == ')') L--;
        if (L == depth) {
            return i;
        }
    }
}

int findL_parentheses (string str) {
    int L = 0;
    int depth = depth_parentheses(str);
    rep(i, str.length()) {
        if (str[i] == '(') L++;
        else if (str[i] == ')') L--;
        if (L == depth) {
            return i;
        }
    }
}

int findR_parentheses (string str) {
    int R;
    int L = findL_parentheses(str);
    for (int i = L+1; i < str.length(); i++) {
        R = i;
        if (str[i] == ')') break;
    }
    return R;
}

int findR_parentheses (string str, int L) {
    int R;
    if (L == 0) L = findL_parentheses(str);
    for (int i = L+1; i < str.length(); i++) {
        R = i;
        if (str[i] == ')') break;
    }
    return R;
}
string takeout_parentheses (string str) {
    string ret;
    int depth = depth_parentheses(str);
    int L = findL_parentheses(str, depth);
    int R = findR_parentheses(str, L);
    //dump(depth);
    //dump(L);
    //dump(R);
    stringstream str_tmp;
    for (int i = L+1; i < R; i++) str_tmp << str[i];
    ret = str_tmp.str();
    return ret;
}

int find_muldiv (string str) {
    int sym = 1;
    while (str[sym] >= '0' && str[sym] <= '9' || str[sym] == '+' || str[sym] == '-') sym++;
    return sym;
}
int find_addsub (string str) {
    int sym = 1;
    while (str[sym] >= '0' && str[sym] <= '9') sym++;
    return sym;
}

string cal_mul (string str, int sym) {
    //cout << str << endl;
    if (sym == str.length()) return str;

    int L = 1, R = 1;
    int sumL = 0, sumR = 0;
    while (str[sym-L] >= '0' && str[sym-L] <= '9') {
        sumL += mul10(L-1, (str[sym-L] - '0'));
        L++;
    }
    if (str[0] == '-') sumL = -sumL; 
    while (str[sym+R] >= '0' && str[sym+R] <= '9') {
        R++;
    }
    rep(i ,R-1) {
        sumR += mul10(i, str[sym+R-i-1] - '0');
    }
    //dump(sumL);
    //dump(sumR);
    stringstream str_tmp;
    if (str[0] == '-') rep(i, sym-L) str_tmp << str[i+1];
    else rep(i, sym-L+1) str_tmp << str[i];
    str_tmp << cal(str[sym], sumL, sumR);
    for(int i = sym+R; i < str.length(); i++) str_tmp << str[i];
    str = str_tmp.str();
    //cout << str << endl;
    return str;
}

string cal_all (string str) {
    string prev = str;
    while(true){
        str = cal_mul(str, find_muldiv(str));
        if ( prev == str ) break;
        else prev = str;
    }
    while(true){
        str = cal_mul(str, find_addsub(str));
        if ( prev == str ) break;
        else prev = str;
    }
    return str;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    rep(i ,n){
        string str; cin >> str;
        str.erase( --str.end() );

        //?????£?????????????¨??????????
        while(depth_parentheses(str) > 0){
            string sube = takeout_parentheses(str);
            sube = cal_all(sube);

            int L = findL_parentheses(str);
            int R = findR_parentheses(str);
            stringstream str_tmp;
            rep(i, L) str_tmp << str[i];
            str_tmp << sube;
            for (int i = R+1; i < str.length(); i++) {
                str_tmp << str[i];
            }
            str = str_tmp.str();
            //cout << str << endl;
        }

        //?????£?????????????????¶?????§?¨??????????
        string prev = str;
        str = cal_all(str);
        //?????????????????????
        int ans = stoi(str);
        cout << ans << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long Int;
typedef string::const_iterator Iter;

Int eval(const string&);
Int expr(Iter&);
Int term(Iter&);
Int factor(Iter&);
Int number(Iter&);

Int eval(const string &s){
	Iter it = s.begin();
	return expr(it);
}

Int expr(Iter &it){
	Int res = term(it);
	while (true){
		if (*it == '+'){
			++it;
			res += term(it);
		}
		else if (*it == '-'){
			++it;
			res -= term(it);
		}
		else return res;
	}
}

Int term(Iter &it){
	Int res = factor(it);
	while (true){
		if (*it == '*'){
			++it;
			res *= term(it);
		}
		else if (*it == '/'){
			++it;
			res /= term(it);
		}
		else return res;
	}
}

Int factor(Iter &it){
	if (*it == '('){
		++it;
		Int res = expr(it);
		++it;
		return res;
	}
	else return number(it);
}

Int number(Iter &it){
	Int res = 0;
	while (isdigit(*it)){
		res = res * 10 + (*it - '0');
		++it;
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++){
		string s;
		getline(cin, s);
		s.resize(s.size() - 1);
		cout << eval(s) << endl;
	}
}