Reminder Programming Language: C, C++, C#, Python (Red font indicates the programming language used in this course) Graphic Function Options: Win32 Program, MFC, WinForm, DirectX10 (bold indicates the program graphics category of this course, default is nongraphical interface)Win32 Console Program (Black Box, Text Interface) Win32 Console Program Data structure: basic type, array, linked list, bidirectional linked list, search tree (unbalanced binary tree), balanced binary tree, combination of linked list and balanced binary tree, stack, queue, string, graph (bold body indicates the data structure used in this lesson) C++ Language Items: Library (bold for C++)STLSTL Library Compiler environment: Windows 7 64-bit Flagship Edition ()Download Linux and other environments with caution Integrated development environment: Visual C++ 6.0, DEVC++, CodeBlocks, Visual Studio 2015 can be compiled.(Light blue fonts indicate that they cannot be compiled) Multi-header file compilation: No (all codes are basically contained in one file, if you need to test the function of header file, please refer to relevant literature by yourself) Content description: 1Topics and previews will be displayed on page 2. 2Number of lines of code:175 3The contents shown in the catalogue are basically covered in this article. If there is no content, it will be explained on this page. 4Appendix absolutely contains user's manual and complete source code and detailed annotations. 5If you need to download something else, this article will explain it here. Header files (for example, DirectX needs to be configured separately) 6In addition, due to my limited level, there are inevitably errors and omissions in the compilation. I urge teachers or students to criticize and correct them. Title:Input an expression and calculate the result Table 1 Overall Ideas First, read a string from the screen and store it in str, such as 1/20-5+ ((210*5)+5-10*2) Start adding infix expressions to the string queue: stringQueueMiddle First, retrieve the characters in STR and add them to the end of the strNumber string if they are numbers Second, retrieve the characters in str. If you encounter +-*/, enter the strNumber number and the strSymbol operator. The cycle proceeds until it reaches the end of str. Secondly, the infix expression is transformed into a suffix expression and added to the string queue stringQueueBack. First, add a numeric string directly to the queue when you encounter a number Second, if the stringStack stack is empty, the operator characters are stacked Thirdly, if the stringStack stack is not empty, if the priority of the first operator is less than that of the operator at the top of the stack, then all operators higher than or equal to the first operator on the stack are added to the queue (and then out of the stack), and then lower or lower operators are pushed into the stack. Fourth, if left parentheses are encountered, the stack is directly pressed Fifth, when encountering right parentheses, all operators on the right side of the left parentheses are directly stacked and added to the queue. An example of infix expression to suffix expression in Table 2 For example, 1/20-5+((2-10*5)+5-10*2) StringQueueMiddle (infix expression queue) StringStack (stack) String QueueBack (Suffix expression queue) 1/20-5+((2-10*5)+510*2) / 20-5+((2-10*5)+510*2) 20-5+((2-10*5)+510*2) / - 5+((2-10*5)+5-10*2) 5+((2-10*5)+5-10*2) - + ((2-10*5) +5-10*2) ((2-10*5) +5-10*2) + 1 Enter the team directly with numbers 1 Stack empty, operator on the stack 1 20 Enter the team directly with numbers 1 20 / -Priority is lower than/ 1 20 / 5 - Enter the team directly with numbers 1 20 / 5 - -If the priority is the same as that of the + operator, it will go out of the stack first, and then go into the stack. (2-10*5) +5-10*2) +( 1 20 / 5 - Encounter (, go directly to the stack) 2-10*5)+5-10*2 + (( 1 20 / 5 - Ditto - 10*5) +5-10*2 + (( 1 20 / 5 - 2 10*5) +5-10*2 + ((-) - 1 20 / 5 - 2 *5) +5-10*2 + ((-) - 1 20 / 5 - 2 10 5) +5-10*2) + ((-) * 1 20 / 5 - 2 10 (+5-10*2) + ((-) * 1 20 / 5 - 2 10 5 +5-10*2) +( 120/5 - 2 105*- Because (in the stack, (has the lowest priority) * Priority is higher than -, on the stack Encountered, the first (all previous operators bounced in and out of the queue, and out of the stack) ( 5-10*2) + (+) 120/5 - 2 105*- -10*2) + (+) 120/5 - 2 105* - 5 10*2) + (-) - 120/5 - 2 105* - 5+ *2)
C++ Computational Mathematical Formula (with complete source code and accessories)
Tips: Current document can only be previewed at most page8,If the total number of pages in the document exceeds page 8,please download the document。
Uploaded by admin on 2019-10-15 12:07:25