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++: package practice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	private static final int BIG_NUM  = 2000000000;
	private static final int MOD  = 1000000007;
	private static char[] line;


	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		line = new char[120];
		String input_str;
		int length;

		try {
			int num_eq = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < num_eq; loop++){

				input_str = br.readLine();

				length = 0;
				for(int i = 0; input_str.charAt(i) != '='; i++){
					line[i] = input_str.charAt(i);
					length++;
				}

				System.out.println(calc_E(0,length-1));
			}

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static int calc_E(int left,int right){
		int depth = 0;
		Queue<Integer> Q = new ArrayDeque<Integer>();

		//深さ0の、プラスまたは-を探す
		for(int i = left; i <= right; ){
			if(line[i] == '(')depth++;
			else if(line[i] == ')')depth--;

			if(depth != 0){
				i++;
			}else if(line[i] != '+' && line[i] != '-'){
				i++;
			}else{
				if(line[i] == '+'){
					Q.add(i);
					i++;
				}else{ //line[i] == '-'
					Q.add(i);
					i++;
				}
			}
		}

		if(Q.isEmpty()){ //深さ0の+-がない
			return calc_T(left,right);
		}

		int tmp = calc_E(left,Q.peek()-1),tmp_right;

		if(tmp == BIG_NUM)return BIG_NUM;

		while(!Q.isEmpty()){
			int loc = Q.peek();
			Q.poll();

			if(Q.isEmpty()){
				tmp_right = calc_T(loc+1,right);
			}else{
				tmp_right = calc_T(loc+1,Q.peek()-1);
			}

			if(tmp_right == BIG_NUM){
				return BIG_NUM;
			}

			if(line[loc] == '+'){
				tmp += tmp_right;
			}else{
				tmp -= tmp_right;
			}
		}
		return tmp;
	}

	public static int calc_T(int left,int right){
		int depth = 0;
		Queue<Integer> Q = new ArrayDeque<Integer>();

		//深さ0の、*,/を探す
		for(int i = left; i <= right; ){
			if(line[i] == '(')depth++;
			else if(line[i] == ')')depth--;

			if(depth != 0){
				i++;
			}else if(line[i] != '*' && line[i] != '/'){
				i++;
			}else{
				Q.add(i);
				i++;
			}
		}

		if(Q.isEmpty()){ //深さ0の*,/がない
			return calc_F(left,right);
		}

		int tmp = calc_T(left,Q.peek()-1),tmp_right;

		if(tmp == BIG_NUM)return BIG_NUM;

		while(!Q.isEmpty()){
			int loc = Q.peek();
			Q.poll();

			if(Q.isEmpty()){
				tmp_right = calc_F(loc+1,right);
			}else{
				tmp_right = calc_F(loc+1,Q.peek()-1);
			}

			if(tmp_right == BIG_NUM){
				return BIG_NUM;
			}

			if(line[loc] == '*'){
				tmp *= tmp_right;
			}else{
				tmp /= tmp_right;
			}
		}
		return tmp;
	}
	public static int calc_F(int left,int right){

		if(line[left] >= '0' && line[left] <= '9'){
			return calc_NUM(left,right);

		}else if(line[left] == '('){

			int depth = 0;
			int close_pos = BIG_NUM;

			for(int i = left; i <= right; i++){
				if(line[i] == '(')depth++;
				else if(line[i] == ')'){
					depth--;
					if(depth == 0){
						close_pos = i;
						break;
					}
				}
			}
			if(close_pos == BIG_NUM || close_pos != right)return BIG_NUM;

			return calc_E(left+1,close_pos-1);
		}else{
			return BIG_NUM;
		}
	}
	public static int calc_NUM(int left,int right){

		int ret = 0;
		for(int i = left; i <= right; i++){
			ret = 10*ret+line[i]-'0';
		}
		return ret;
	}
}

C++: #include <iostream>
#include <cctype>
#include <string>
#include <cassert>
enum class Type : char {
	Num, Pos = '+', Neg = '-', Mul = '*', Div = '/', LP = '(', RP = ')', End = '='
};

struct Token {
	Type type;
	double num;
};

class Expression {
public:
	Expression(std::istream *s) :is{ s } {};
	Token &current() {
		return _current;
	}
	Token get() {
		char c;
		if (!((*is).get(c))) return _current = { Type::End };
		switch (c) {
		case '+':
		case '-':
		case '*':
		case '/':
		case '(':
		case ')':return _current = { static_cast<Type>(c) }; break;
		case '=':
		case '\n': return _current = { Type::End }; break;
		default:
			if (isdigit(c)) {
				std::string str;
				str.push_back(c);
				while ((*is).get(c)) {
					if (isdigit(c)) {
						str.push_back(c);
					}
					else {
						(*is).putback(c);
						return _current = { Type::Num, std::stod(str) };
					}
				}
				return _current = { Type::Num, std::stod(str) };
			}
			else throw;
		}
	}
private:
	std::istream *is;
	Token _current{ Type::End };
};
double execute_sub(Expression &, const bool &);
double single_value(Expression &exp, const bool &use_get) {
	double left;
	if (use_get) exp.get();
	switch (exp.current().type) {
	case Type::Num:
		return exp.current().num;
	case Type::Neg:
		return -single_value(exp, true);
	case Type::LP:
		left = execute_sub(exp, true);
		exp.get();
		exp.current() = { Type::Num, left };
		return left;
	default: throw;
	}
}
double execute_pri(Expression &exp, const bool &use_get) {
	if (use_get) exp.get();
	auto left = single_value(exp, false);
	switch (exp.get().type) {
	case Type::Mul:
		return left * execute_pri(exp, true);
	case Type::Div:
		return left / execute_pri(exp, true);
	default:
		return left;
	}
}
double execute_sub(Expression &exp, const bool &use_get) {
	if (use_get) exp.get();
	auto left = execute_pri(exp, false);
	switch (exp.current().type) {
	case Type::Pos:
		return left + execute_sub(exp, true);
	case Type::Neg:
		return left - execute_sub(exp, true);
	default:
		return left;
	}
}
double execute(Expression &exp) {
	exp.get();
	return execute_sub(exp, false);
}
int main() {
	Expression express(&std::cin);
	std::cout << execute(express) << std::endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
using namespace std;

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

int factor(State &begin);

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

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

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

    while(true){
        if(*begin=='*')ret*=factor(++begin);
        else if(*begin=='/')ret/=factor(++begin);
        else break;
    }
    return ret;
}

int expression(State &begin){
    int ret=term(begin);
    while(true){
        if(*begin=='+')ret+=term(++begin);
        else if(*begin=='-')ret-=term(++begin);
        else break;
    }
    return ret;
}

int factor(State &begin){
    if(*begin=='(')return expression(++begin++);
    else  return number(begin);
}

int main(){

    int N;
    cin>>N;
    cin.ignore();
    REP(i,N){

        string s;
        getline(cin,s);
        State begin = s.begin();
        cout<<expression(begin)<<endl;

    }
    return 0;
}