MFC porting for arithmetic problems

Source: Internet
Author: User

MFC porting for arithmetic problems

This implementation combines the two programs written last week and uses MFC to provide a graphical interface. There was not much difficulty in the matter, but because of my initial thinking I designed a relatively complex UI, so I added a lot of questions that needed extra consideration. So let's first talk about my UI design ideas.

Graphical interface Design

     

The graphical interface design is shown above. The user can choose to generate the number of calculation, the user input the corresponding number, you need to click Generate calculation. You can display up to 5 formulas at a time in the graphical interface, and the user can enter the answers to these 5 equations separately. If the number of calculations is more than 5, the user can turn the page by clicking the Flip button on the left and right sides. Of course, the left and right pages do not affect the user's previous input results. After the user answer input is finished, click Submit results, the system will automatically judge the answer to each question, the results of each question will be displayed on the right side of the title two edit control. This includes the correct and correct user answers, as well as the standard answer. At the same time, the system will also be counted the whole round answer the total wrong and wrong situation, and display the results.

Issues to be considered in the design

Since this implementation does not involve the design of the new algorithm, it simply writes the code of the associated MFC control. So the details are not detailed here. I'm just going to talk about some of the issues I've encountered in my implementation and the corresponding workarounds.

1, Char turn CString

Because the operation of the characters in the console program version is char*, and in MFC, the operation of the characters in edit control is CString, so the need to convert, the solution is to modify the function, The steps to manipulate char in all functions in the console version are modified to operate on CString, and the CString operation is similar to the string operation, and the modification process is quite smooth.

2. Storage expression

In the console version, each user who generates an expression enters an answer and then immediately makes a right-and-wrong judgment. In this case, you don't need to store the expression and the result, just add it on the correct accumulator or error accumulator. And because of the design of the MFC version, we have to save the calculations that have been generated in history, as well as the results of user input. So the solution to this change is to add a new structure array to hold the history of the calculation, when the user needs to see the previous calculation, click the page button to view. The structure is defined as follows:

1 structproblem{2 CString prob;3 CString ans_usr_input;4 num Usrans;5 num ans;6     BOOLHave_judge;7     BOOLjudge;8 problem ()9     {TenProb =""; OneAns_usr_input =""; AHave_judge =false; -Judge =false; -     } the};

Where: Prob for the four expression, ans_usr_input for the user input of the answer (directly read from edit control), Usrans for the user answer to the results of the calculation format (num is a struct, defined with the definition of the console program), ANS is the standard answer, Hava_judge is used to mark whether this question has been sentenced, judge for this question the correctness of the user.

We define an array to store all the generated topics problem pro[maxp][5];.

Summarize

In the entire implementation process there are many other trivial small problems, the solution of the idea is also more like, just realize the code to write more, here I will not repeat. Overall this time the implementation of a relatively hasty, although the implementation of the function, but the robustness is not considered very thoughtful, there are still some known bugs are not resolved. At the same time, this version of the program does not support the user to limit the parentheses, whether to support the multiplication method. The space for improvement is still very large. However, this version also has some improvements in the console version, first of all support the graphical interface operation, the second can support users to look back to the topic has been done, if the previous answer is not satisfied can also be modified.

MFC porting for arithmetic problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.