Question: C++. instructions are to use a stack. the format of the main function is provided. argument manager header file is not needed to be coded.



C++. instructions are to use a stack. the format of the main function is provided. argument manager header file is not needed to be coded. just used for input/command/outputting to files.
COSC2430 HW5: Stack & Queue Problem 1. Introduction You need to create a C++ program that can evaluate a list of arithmetic expressions whether they are valid. You also need to compare them if they are similar 2. Program and input specification You will get a list of expressions in an input file. Each line will be considered as a single expression. You need to check whether the expression is valid or not. An expression will be invalid if opening and ending parenthesis don't match. If you don't get any invalid expression, then you need to check the similarity among all expressions. Expressions will be similar, if we place values to the variables then all expressions will generate the same result. Assumptions The input file is a small plain text file; no need to handle binary files. Each input file may contain maximum 1000 expressions. In an expression, only unit digits (0-9) will be used. Variables can be only (a-z, and A-Z), and it is always a single character There will be no space in an expression. . e An input file may contain empty lines between expressions, then you will ignore it. Operators: Parentheses: (), L I L1. The output should be exactly matched with the format. The main C++ program will become the executable to be tested by the TAs. The Result file should be written to another text file (output file), provided with the Command line. Notice the input and output files are specified in the command line, not inside the C++ code. Notice also the quotes in the program call, to avoid Unix/Windows gets confused. 3. Input and Output The input file is a regular text file, where each line is terminated with a n' character Each line will contain an arithmetic expression. 1. Expressions consist of numbers (0-9), lowercase alphabets (a-z), uppercase alphabets (A-Z), '+', -, ('. T,I,T, T, and T'. An operand (numbers, and alphabets) will not appear the second time in a single expression. 2. If an expression is not valid, the output will be "Error at:"+expression number. Note, in "Error at:", there is a space after the colon(:) 3. If Expressions are similar, then the output will be "Yes", otherwise "No" All records should be orocessed sequentially from beginning to end. Note that 3. If Expressions are similar, then the output will be "Yes, otherwise "No" All records should be processed sequentially from beginning to end. Note that, input and output, all are case sensitive. Please, see examples to be clarified about the format and expression number 4. Program Execution: The general call to the executable is as follows: evalexpr "input-input1.txt;output-output1.txt" You can call the example with another command line type evalexpr input-input1.txt output-output1.txt 5. Examples Example 1 of input and output, Input1.txt a+b-A-1+3+B a+b-1+3+B-A +(a+b-A-1+3+B) at(b-(A+1)+3+B) a+b-A+2+B Command line: evalexpr input-input1.txt output-output1.txt Output1.txt Yes Example 2 of input and output, Input2.txt A+B+5+6+a A-B+5+6+a Command line: evalexpr input-input2.txt output-output2.txt Output2.txt No Example 3 of input and output, Input3.txt a+b+c+d+e a-b-c-d-e a-(b-c-d)-e a-((b-c-d)-e // valid expression // valid expression // valid expression // Error 1 2 #include "ArgumentManager.h" int main(int argc, char *argv[) 4 5 6 7 8 9 10 ArgumentManager am(argc, argv); string input am.get('' input"): string command-am.get( "command") string output -am.get("output"); ifstream ifs(input); ifstream cmd (command) ofstream out(output); 12 COSC2430 HW5: Stack & Queue Problem 1. Introduction You need to create a C++ program that can evaluate a list of arithmetic expressions whether they are valid. You also need to compare them if they are similar 2. Program and input specification You will get a list of expressions in an input file. Each line will be considered as a single expression. You need to check whether the expression is valid or not. An expression will be invalid if opening and ending parenthesis don't match. If you don't get any invalid expression, then you need to check the similarity among all expressions. Expressions will be similar, if we place values to the variables then all expressions will generate the same result. Assumptions The input file is a small plain text file; no need to handle binary files. Each input file may contain maximum 1000 expressions. In an expression, only unit digits (0-9) will be used. Variables can be only (a-z, and A-Z), and it is always a single character There will be no space in an expression. . e An input file may contain empty lines between expressions, then you will ignore it. Operators: Parentheses: (), L I L1. The output should be exactly matched with the format. The main C++ program will become the executable to be tested by the TAs. The Result file should be written to another text file (output file), provided with the Command line. Notice the input and output files are specified in the command line, not inside the C++ code. Notice also the quotes in the program call, to avoid Unix/Windows gets confused. 3. Input and Output The input file is a regular text file, where each line is terminated with a n' character Each line will contain an arithmetic expression. 1. Expressions consist of numbers (0-9), lowercase alphabets (a-z), uppercase alphabets (A-Z), '+', -, ('. T,I,T, T, and T'. An operand (numbers, and alphabets) will not appear the second time in a single expression. 2. If an expression is not valid, the output will be "Error at:"+expression number. Note, in "Error at:", there is a space after the colon(:) 3. If Expressions are similar, then the output will be "Yes", otherwise "No" All records should be orocessed sequentially from beginning to end. Note that 3. If Expressions are similar, then the output will be "Yes, otherwise "No" All records should be processed sequentially from beginning to end. Note that, input and output, all are case sensitive. Please, see examples to be clarified about the format and expression number 4. Program Execution: The general call to the executable is as follows: evalexpr "input-input1.txt;output-output1.txt" You can call the example with another command line type evalexpr input-input1.txt output-output1.txt 5. Examples Example 1 of input and output, Input1.txt a+b-A-1+3+B a+b-1+3+B-A +(a+b-A-1+3+B) at(b-(A+1)+3+B) a+b-A+2+B Command line: evalexpr input-input1.txt output-output1.txt Output1.txt Yes Example 2 of input and output, Input2.txt A+B+5+6+a A-B+5+6+a Command line: evalexpr input-input2.txt output-output2.txt Output2.txt No Example 3 of input and output, Input3.txt a+b+c+d+e a-b-c-d-e a-(b-c-d)-e a-((b-c-d)-e // valid expression // valid expression // valid expression // Error 1 2 #include "ArgumentManager.h" int main(int argc, char *argv[) 4 5 6 7 8 9 10 ArgumentManager am(argc, argv); string input am.get('' input"): string command-am.get( "command") string output -am.get("output"); ifstream ifs(input); ifstream cmd (command) ofstream out(output); 12
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
