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 <cctype>
#include <cassert>
#include <cstddef>

using namespace std;


// ?????????????§?????§£???????????????????????¨???????????????
class MathExpress
{
private:
    string m_express;
    size_t m_cur = 0;

public:
    MathExpress(string str) : m_express(str) 
    {
        m_express.resize(m_express.size() - 1);
    }

    int digit(); // ???????????°???
    int number(); // ??°??????????????°????????´???
    int term();
    int factor(); 
    int expression();
};


int MathExpress::digit()
{
    assert(isdigit(m_express.at(m_cur)));

    int n = m_express.at(m_cur) - '0';

    m_cur += 1;

    //cout << "digit: " << n << endl;

    return n;
}


int MathExpress::number()
{
    int num = digit();

    while ( m_cur < m_express.size() && isdigit(m_express.at(m_cur)) )
    {
        num = num * 10 + digit();
    }

    //cout << "number: " << num << endl;

    return num;
}


int MathExpress::term()
{
    int left = factor();

    while (m_cur < m_express.size() 
         && (m_express.at(m_cur) == '*' || m_express.at(m_cur) == '/'))
    {
        char op = m_express.at(m_cur++);

        //cout << op << endl;

        int right = number();

        switch (op) {
            case '*':
                left *= right;
                break;
            case '/':
                left /= right;
                break;
            default:
                break;
        }

    }

    //cout << "term: " << left << endl;

    return left;
}


int MathExpress::expression()
{
    int left = term();

    while (m_cur < m_express.size() 
         && (m_express.at(m_cur) = '+' || m_express.at(m_cur) == '-'))
    {
        //cout << m_cur << " " << m_express.at(m_cur) << endl;
        char op = m_express.at(m_cur);

        m_cur += 1;

        //cout << op << endl;
        //cout << "hoge" << endl;

        int right = term();

        //cout << "hoge" << endl;

        switch (op) {
            case '+':
                //cout << "hoge" << endl;
                left += right;
                break;
            case '-':
                left -= right;
                break;
            default:
                //cout << "hoge" << endl;
                break;
        }

        //cout << "left : right = " << left << " " << right << endl;
    }

    return left;
}


int MathExpress::factor()
{
    if (m_express.at(m_cur) != '(') return number();

    m_cur += 1;

    int exp = expression();

    assert (m_express.at(m_cur) == ')');

    m_cur += 1;

    return exp;
}


int main()
{
    int data_num;
    
    cin >> data_num;
    
    cin.clear();

    string val; 
    for (int i = 0; i < data_num; ++i) {
        cin >> val;

        MathExpress mathexp(val);
        cout << mathexp.expression() << endl;
    }
    
    return 0;
}

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

typedef std::stringstream sst;

int ToInt(std::string str){
	int i;
	sst ss;
	ss<<str;
	ss>>i;
	return i;
}
std::string ToStr(int i){
	std::string str;
	sst ss;
	ss<<i;
	ss>>str;
	return str;
}

std::string SubStr(std::string str,int x,int y){
	return str.substr(x,y-x+1);
}
int Third(std::string str){
	int fres,Ans;
	while( ( fres=str.find_first_of("+-") ) != std::string::npos && fres!=0 ){
		int aRes;
		
		if( (aRes=str.find_first_of("+-",fres+2)) == std::string::npos )
			aRes=str.size()-1;
		else --aRes;
		
		if( str[fres] =='+' ){
			Ans=ToInt(SubStr(str,0,fres-1))+ToInt(SubStr(str,fres+1,aRes));
			str.replace(0,SubStr(str,0,aRes).size(),ToStr(Ans).c_str());
		}else{
			Ans=ToInt(SubStr(str,0,fres-1))-ToInt(SubStr(str,fres+1,aRes));
			str.replace(0,SubStr(str,0,aRes).size(),ToStr(Ans).c_str());
		}
	}
	return ToInt(str);
}

int Second(std::string str){
	int fres,Ans;
	while( ( fres=str.find_first_of("*/") ) != std::string::npos ){
		int bRes,aRes;
		if( (bRes=str.find_last_of("+-",fres)) == std::string::npos  || bRes==0 )
			bRes=0;
		else ++bRes;
		
		if( (aRes=str.find_first_of("+-*/",fres+2)) == std::string::npos )
			aRes=str.size()-1;
		else --aRes;
		
		if( str[fres] =='*' ){
			Ans=ToInt(SubStr(str,bRes,fres-1))*ToInt(SubStr(str,fres+1,aRes));
			str.replace(bRes,SubStr(str,bRes,aRes).size(),ToStr(Ans).c_str());
		}else{
			Ans=ToInt(SubStr(str,bRes,fres-1))/ToInt(SubStr(str,fres+1,aRes));
			str.replace(bRes,SubStr(str,bRes,aRes).size(),ToStr(Ans).c_str());
		}
	}
	Ans=Third(str);
	return Ans;
}

int First(std::string str){
	int fres;
	while( (fres = str.find(")") ) != std::string::npos ){
		int rfres=str.rfind("(",fres);
		std::string Next=SubStr(str,rfres+1,fres-1);
		int cRes=Second(Next);
		str.replace(rfres,Next.size()+2,ToStr(cRes).c_str());
	}
	int lRes = Second(str);
	
	return lRes;
}

int main(){
	int n;
  std::string str;
	std::cin>>n;
	while( n-- ){
		std::cin>>str;
	  std::cout<<First(str)<<std::endl;
	}
}

C++: n=int(input())
for i in range(n):
	a=input()
	b=""
	for i in a:
		b+=i
		if i=='/':b+='/'
	print(int(eval(b[:len(b)-1])))

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

typedef string::const_iterator State;

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

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 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 factor(State &begin){
	int ret;
	if(*begin == '('){
		++begin;
		ret = expression(begin);
		++begin;
	}
	else{
		ret = number(begin);
	}
	return ret;
}

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


int main(){
	int n;
	string q;
	cin >> n;
	cin.ignore();
	for(int i(0);i < n;++i){
		getline(cin, q);
		State begin = q.begin();
		cout << expression(begin) << endl;
	}
    return 0;
}

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

typedef int 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);
		cout << eval(s) << endl;
	}
}