int main()
{
	maintest();

	bool done = false;
	PostFixEval P;
	string original;

	cout<< "Please type the name of the file to which results are to be written to: ";
	string OutputFileName;
	cin.sync();
	getline(cin, OutputFileName);
	ofstream out;
	out.open(OutputFileName);
	
	if (!out)
	{
		cout<<"Failed to create output file.\n";
	}

	while (!done)
	{
		cout << "Please enter the infix expression, which must be parenthetically balanced and\n"
			<< "must be enclosed in square brackets.The parsing algorithm only works if more\n"
			<< "than one space is left between the characters in the inputted expression.\n"
			<< "The evaluated value for a numeric expression will only be a floating point value." << endl;
		getline(cin, original);


		cout << "Press 2 to print the results to both screen and data file:\n"
			<< "Press 3 to print the results to data file only:\n"
			<< "Press 4 to print the results to screen only:\n";
		int choice;
		cin >> choice;
		P = PostFixEval(original, false);
		P.findValue();

		if (choice == 2){
			P.print(out);
			P.print(cout);
			cout<<"More data? Enter 0 to continue and 1 to exit: ";
			cin >> done;
		}
		else if (choice == 3){
Exemplo n.º 2
0
/*************************************************************
 * Que 4. Infix expression evaluation
 * 
 * Comment    : 1) Convert Infix to postfix expression
 *              2) Eval using postfix evaluation and return 
 * 		   result
  * 
 * Parameters : expression array
 * Returns    : int (eval result)
 *************************************************************/
int  InfixEval(char A[])
{
  //Convert expression to postfix then eval,
  return PostFixEval(InfixToPostFix(A));
}