Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Course Proiect 2: Design A Simple Calculator Problem-Design the DFA machine for

ID: 3734303 • Letter: C

Question

Course Proiect 2: Design A Simple Calculator Problem-Design the DFA machine for a simple calculator, where []"is used for only one operation each time (e,g, [3.1 +4.21% 5, [[3.1+4.21% 5/6)) and 3(B,-x/,[.],0,1,2,3,4,5,6,7,8,9,., Steps of the project: (1) Design a regular expression r for real number expression. A real number can be negative or positive (eg,-2.5 and 0.52). A real number expression is an expression of real numbers four arithmetic operations (e.g. l-3.1+4.2]x-5V6 +7.3/-0.54). (2) Design a DFA for accepting the regular language L). You can first design a NFA and then convert it to a DFA Design a regular grammar to generate the regular language L(r). write a program (using C# ) to implement the DFA, ie., accept the language L(r). The output is "accepted" or "rejected" (3) (4) Requirement for the project report: . A detailed description/instruction for how to use the calculator. . Explanation for (1), (2), (3). Code and test result. The program must have a test interface for a user to give an input (a string for real number expression) and get an output (accept or reject).

Explanation / Answer

You can simply write a code of a calcutor first by swith cases as:-

int a,b;

char ArithmeticOperator;

cin>>a>>b>>ArithmeticOperator;

switch(ArithmeticOperator)

{

case "*":c=a*b;

              break;

case "/"c=a/b;

            break;

case "+":c=a+b;

               break;

case "-":c=a-b;

              break;

}

and then write a code to parse the whole input string and store no of "[" opening brackets seen and then performing operations untill a closing bracket is seen. you can even store this result if an opening bracket is again seen.

best approach will be to use recursive function as this will save you the headache of storing the previously calculated result. The function can be called when and "[" is encountered.