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 <bits/stdc++.h>
using namespace std;

string get_term(string, int&);
int get_num(string);
int get_exp(string);

int get_num(string str) {
    int num = 0;

    if (str.size() == 0) return 0;

    int i = 0;
    if (str[i] == '(') {
        i++;
        string exp;
        for (int count = 1; count; i++) {
            if (str[i] == '(') count++;
            if (str[i] == ')') count--;
            if (count) exp += str[i];
        }

        num = get_exp(exp + "=");
    } else {
        for (; i < str.size() && '0' <= str[i] && str[i] <= '9'; i++) {
            num = num * 10 + (str[i] - '0');
        }
    }

    for (; i < str.size(); i++) {
        if (str[i] == '*') {
            i++;
            int tmp = 0;
            if (str[i] == '(') {
                i++;
                string exp;
                for (int count = 1; count; i++) {
                    if (str[i] == '(') count++;
                    if (str[i] == ')') count--;
                    if (count) exp += str[i];
                }

                tmp = get_exp(exp + "=");
            } else {
                for (; i < str.size() && '0' <= str[i] && str[i] <= '9'; i++) {
                    tmp = tmp * 10 + (str[i] - '0');
                }
            }
            num *= tmp;
            i--;
        } else {
            i++;
            int tmp = 0;
            if (str[i] == '(') {
                i++;
                string exp;
                for (int count = 1; count; i++) {
                    if (str[i] == '(') count++;
                    if (str[i] == ')') count--;
                    if (count) exp += str[i];
                }

                tmp = get_exp(exp + "=");
            } else {
                for (; i < str.size() && '0' <= str[i] && str[i] <= '9'; i++) {
                    tmp = tmp * 10 + (str[i] - '0');
                }
            }
            num /= tmp;
            i--;
        }
    }

    return num;
}


void solve(string str) {
    cout << get_exp(str) << endl;
}

int main() {
    int N;
    cin >> N;

    while (N--) {
        string str;
        cin >> str;
        solve(str);
    }

    return 0;
}

string get_term(string str, int& i) {
    string init_str;
    for (int count = 0; i < str.size(); i++) {
        if (str[i] == '(') count++;
        if (count > 0 || ('0' <= str[i] && str[i] <= '9') || str[i] == '/' || str[i] == '*') {
            init_str += str[i];
        }
        if (str[i] == ')') count--;

        if (count == 0 && (str[i] == '+'|| str[i] == '-' || str[i] == '=')) {
            break;
        }
    }

    return init_str;
}

int get_exp(string str) {
    int num  = 0;
    int i = 0;

    string init_str = get_term(str, i);
    num = get_num(init_str);

    while (str[i] != '=') {
        if (str[i] == '-') {
            i++;
            string term = get_term(str, i);
            num -= get_num(term);
        } else if (str[i] == '+') {
            i++;
            string term = get_term(str, i);
            num += get_num(term);
        }
    }

    return num;
}

C++: #include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

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

int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

int term(State &begin) {
    int ret = number(begin);

    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= number(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= number(begin);
        } else {
            break;
        }
    }

    return ret;
}

int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }

    return ret;
}


int main(void){
	int N;
    cin >> N;
    cin.ignore()
    for (int i = 0; i < N; i++) {
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);

bool f;

int expression(string s,int& p){
  int res=term(s,p);
  while(p<(int)s.size()){
    if(s[p]=='+'){
      p++;
      res+=term(s,p);
      continue;
    }
    if(s[p]=='-'){
      p++;
      res-=term(s,p);
      continue;
    }
    break;
  }
  return res;
}

int term(string s,int& p){
  int res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='*'){
      p++;
      res*=factor(s,p);
      continue;
    }
    if(s[p]=='/'){
      p++;
      int tmp=factor(s,p);
      if(tmp==0){
	f=1;
	break;
      }
      res/=tmp;
      continue;
    }
    break;
  }
  return res;
}

int factor(string s,int& p){
  int res;
  if(s[p]=='('){
    p++;
    res=expression(s,p);
    p++;
  }else{
    res=number(s,p);
  }
  return res;
}

int number(string s,int& p){
  int res=0;
  while(p<(int)s.size()&&isdigit(s[p]))
    res=res*10+s[p++]-'0';
  return res;
}

signed main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    int p=0;
    cin>>s;s.pop_back();
    cout<<expression(s,p)<<endl;
  }
  return 0;
}

/*
verified on 2017/04/26
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=0109
*/