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++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int INF=1e9;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-10;
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003


int dp[353][353]={0};
int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}
int cards[10];
bool ok;
void saiki(int deep){
	if(deep==4){
		ok=true;
		return;
	}
	for(int i=1;i<=7;i++){
		if(cards[i]>0&&cards[i+1]>0&&cards[i+2]>0){
			cards[i]--;
			cards[i+1]--;
			cards[i+2]--;
			saiki(deep+1);
			cards[i]++;
			cards[i+1]++;
			cards[i+2]++;
		}
		for(int i=1;i<=9;i++){
			if(cards[i]>2){
				cards[i]-=3;
				saiki(deep+1);
				cards[i]+=3;
			}
		}
	}
	
}

int main(){
	
	int n;
	cin>>n;
	while(n>0){
		stack<string> a;
	string s;
		cin>>s;
		string tmp="";
		rep(i,s.size()){
			if(s[i]>='0'&&s[i]<='9'){
				tmp+=s[i];
			}
			else{
				if(!a.empty()&&s[i]!='('){
				string o=a.top();
					int k=0;
				if(o=="*"){
					a.pop();
					k=stoi(tmp)*stoi(a.top());
					a.pop();
					tmp=to_string(k);
					
				}
				else if(o=="/"){
					a.pop();
					k=stoi(a.top())/stoi(tmp);
					a.pop();
					tmp=to_string(k);
				
				}
					
					
				}
				if(tmp!=""){
				a.push(tmp);
				tmp="";
				}
					if(s[i]==')'){
						int k=stoi(a.top());
						a.pop();
							while(1){
									if(a.top()=="("){
										a.pop();
										if(!a.empty()){
											if(a.top()=="*"){
											a.pop();
												k=stoi(a.top())*k;
												a.pop();
											}
											else if(a.top()=="/"){
												a.pop();
												k=stoi(a.top())/k;
												a.pop();
											}
												
										}
										a.push(to_string(k));
										break;
									}
										else{
												if(a.top()=="+"){
									a.pop();
									k=k+stoi(a.top());
								}
								else if(a.top()=="-"){
									a.pop();
									k=stoi(a.top())-k;
								}
								a.pop();
										}
							}
								
						
					}
						else if(s[i]!='='){
							
							if(i==0&&s[i]=='-')
								tmp+=s[i];
							else if(s[i+1]=='-'){
								tmp+=s[i+1];
								string c="";
							c+=s[i++];
							a.push(c);
						}
							else{
								string c="";
							c+=s[i];
							a.push(c);
							}
							
						}
					
			}
				
		}
			int ans=stoi(a.top());
			a.pop();
			while(!a.empty()){
				if(a.top()=="+"){
				a.pop();
					ans=ans+stoi(a.top());
				}
				else if(a.top()=="-"){
				a.pop();
					ans=stoi(a.top())-ans;
				}
				a.pop();
				
			}
			cout<<ans<<endl;
			n--;
	}
	
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
#define INF (1<<24)

bool isNum(char ch){return ('0'<=ch&&ch<='9');}

struct calcStr{
  string s;
  int pos,len;

  void init(){ pos=0;len=s.size();}

  int head2Num(){
    if(s[pos]=='('){pos++;return getAns();}
    
    bool f=false;
    if(s[pos]=='-'){f=true;pos++;}
    int res=0;
    while(pos<len){
      if(isNum(s[pos])){
	res*=10;
	res+=(s[pos]-'0');
	pos++;
      }else break;
    }
    if(f)res*=-1;
    return res;
  }
  
  int getNum(){
    int res=head2Num(),num;
    char ch;
    while(s[pos]=='*'||s[pos]=='/'){
      ch=s[pos++];
      num=head2Num();
      if(ch=='*')res*=num;
      else if(ch=='/')res/=num;
    }
    return res;
  }
  
  int getAns(){
    int res=getNum(),num;
    while(1){
      if(s[pos]==')'){pos++;break;}
      if(s[pos]=='=')break;
      char ch=s[pos++];
      num=getNum();
      if(ch=='+')res+=num;
      else if(ch=='-')res-=num;
      else assert(0);
    }
    return res;
  }
};

int main(){
  int Tc;cin>>Tc;
  calcStr a;
  while(Tc--){
    cin>>a.s;
    a.init();
    cout<<a.getAns()<<endl;
  }
  return 0;
}

C++: //https://gist.github.com/draftcode/1357281
#include <string>
#include <cctype>
#include <iostream>
typedef std::string::iterator State;
class ParseError {};

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);
void consume(State &begin, char expected){
	if(*begin == expected){
		begin++;
	}else{
		std::cerr << "Expected '" << expected << "' but got '"<<*begin << "'"<<std::endl;
		std::cerr << "Rest string is '";
		while(*begin){
			std::cerr << *begin++;
		}
		std::cerr<<"'"<<std::endl;
		throw ParseError();
	}
}

int main(void){
	int N;
	std::cin >> N;
	std::cin.ignore();
	while(N--){
		std::string s;
		std::getline(std::cin, s);
		//std::cin>>s;
		State begin = s.begin();
		int ans = expression(begin);
		//consume(begin, '=');
		std::cout << ans << std::endl;
	}
	return 0;
}

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

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

	return ret;
}

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

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

	for(;;){
		if(*begin == '*'){
			begin++;
			ret *= factor(begin);
		}else if(*begin == '/'){
			begin++;
			ret /= factor(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;
}