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. 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. An input file may contain empty lines between expressions, then you will ignore it. • Operators: + -. Parentheses: (, ), { }, [, ]- The output should be exactly matched with the format. 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', '-', '(', )', {, Y, T, and J'. 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 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. 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) a+b-(A+1)+3+B a+b-(A+1)-(-3-B) a+(b-(A+1)+3+B) a+{(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 // valid expression // valid expression // valid expression a+b+c+d+e a-b-c-d-e a-(b-c-d)-e a-{(b-c-d)-e // Error // Empty line will not be counted // Error a-{(b-c-d))-e // Empty line will not be counted // valid expression // Error // Error {a-[(b-c-d)]-e} a-[{(b-c-d})]-e a-{(b-[c-d)}-e] Command line: evalexpr input=input3.txt output=output3.txt Output3.txt Error at: 4 Error at: 5 Error at: 7 Error at: 8 The general call to the executable is as follows: evalexpr input=input1.txt output=output1.txt

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.3: Nested If Statements
Problem 7E
icon
Related questions
Question

c++. output

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.
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.
An input file may contain empty lines between expressions, then you will
ignore it.
Operators: + -.
Parentheses: (, ), {, }, [, ].
The output should be exactly matched with the format.
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, 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 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.
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)
a+b-(A+1)+3+B
a+b-(A+1)-(-3-B)
a+(b-(A+1)+3+B)
a+{(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
// valid expression
// valid expression
// valid expression
// Error
// Empty line will not be counted
// Error
// Empty line will not be counted
// valid expression
// Error
// Error
a+b+c+d+e
a-b-c-d-e
a-(b-c-d)-e
a-{(b-c-d)-e
a-{(b-c-d))-e
{a-[(b-c-d)]-e}
a-{{{b-c-d})]-e
a-{(b-[c-d)}-e]
Command line:
evalexpr input=input3.txt output=output3.txt
Output3.txt
Error at: 4
Error at: 5
Error at: 7
Error at: 8
The general call to the executable is as follows:
evalexpr input=input1.txt output=output1.txt
Transcribed Image Text: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. 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. An input file may contain empty lines between expressions, then you will ignore it. Operators: + -. Parentheses: (, ), {, }, [, ]. The output should be exactly matched with the format. 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, 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 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. 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) a+b-(A+1)+3+B a+b-(A+1)-(-3-B) a+(b-(A+1)+3+B) a+{(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 // valid expression // valid expression // valid expression // Error // Empty line will not be counted // Error // Empty line will not be counted // valid expression // Error // Error a+b+c+d+e a-b-c-d-e a-(b-c-d)-e a-{(b-c-d)-e a-{(b-c-d))-e {a-[(b-c-d)]-e} a-{{{b-c-d})]-e a-{(b-[c-d)}-e] Command line: evalexpr input=input3.txt output=output3.txt Output3.txt Error at: 4 Error at: 5 Error at: 7 Error at: 8 The general call to the executable is as follows: evalexpr input=input1.txt output=output1.txt
Expert Solution
steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr