word memory system

Topic B4: Keyword-based text sorting and retrieval system

1. Subject content and requirements

Topic B4:

(1) Subject content "Memorizing words - personalized memorizing words" is a software for reciting English words. Users can import the thesaurus to be recited according to their own needs, and can edit their own thesaurus. There are two modes to choose from when reciting words: the system can give Chinese prompts, the user can input the corresponding word, or it can output the word for the user to input the Chinese meaning. The system determines whether the meaning of the word is correct. If it is correct, it will improve the familiarity of the word. If it is incorrect, it will give a hint and reduce the familiarity of the word. At the same time, it will classify the words according to the familiarity.

(2) Subject requirements

  1. Basic requirements The code should be able to provide the following basic functions.

(1) User login: · New users can register, and old users log in directly. ·You can just punch the card without reciting the words, and exit the interface directly.

(2) Word Book: ·Store the basic information of words, English, part of speech, Chinese explanation, etc. ·For the convenience of the user, the stored word book can be provided for the user to choose. ·Select the thesaurus to maintain and edit the word book information, and realize the functions of adding, modifying, deleting, and supplementing (words already exist, and new definitions are added).

(3) Word recitation and score statistics: ·According to the task word volume selected by the user, randomly select word previews for word learning. ·There are two modes for word recitation, multiple-choice recitation and spelling word recitation, which supports multiple recitations. ·Classify the word familiarity according to the recitation situation. ·You can check the total number of words of various familiarity levels in the word book.

(4) Word review: ·When the recitation is completely correct, the interface shows that there are no wrong questions and continue to work hard. ·When there is a wrong question, you can choose to repeat the wrong question to strengthen your memory.

(5) You can punch in when you log out of the system, and count the number of days of reciting words.

\2. Extended Requirements

(1) Perform a certain correctness check on the user's input.

(2) It can count the frequency of occurrence of each word and the correct rate of recitation, which can provide a basis for future questions.

[other requirements]

(1) The names of variables and functions conform to the specification.

(2) Detailed comments: each variable requires a comment to explain the purpose; the function has a comment to explain the function, and the parameter and return value should also be explained in the form of comments; the key statement segments require comments to explain.

(3) The level of the program is clear and the readability is strong. (4) Beautiful interface and convenient interaction.

2. Demand analysis

The use of the user class (class user) realizes the registration and login of the account password, and uses the destructor and array to realize the entry, modification and deletion of the part of speech and the definition of the word, as well as the statistics and query of the familiarity of the word. And use multiple user-defined functions to realize the function, the example is as follows:

Figure 2.1 Some user-defined functions

3. Outline Design

Figure 3.1 Flowchart of the word memorization system

Note: After the program completes the user registration, it must output 3. Exit to complete the saving of the user account and password.

First, register and log in the user account and password. After completing the login page, the 7 serial numbers correspond to 7 functions respectively. Users can input the corresponding serial numbers according to their needs to realize the functions.

For functions 1, 2, and 3: the input, modification and deletion of the word book can only be carried out by correctly outputting the corresponding data according to the prompts of the word recitation system.

For the rest of the functions, operate as shown in the figure:

Figure 3.2 Operation instructions of functions 4, 5, and 6

4. Detailed design (part of the core code)

Use of header files

Figure 4.1 The header file used by this function

The #include directive instructs the C preprocessor to browse the specified file as input. The preprocessed output consists of the output already generated, the output generated by the referenced files, and the text output after the #include directive.

Figure 4.2 Calling user-defined functions

Using destructors and arrays to realize the entry, modification and deletion of word parts and definitions, as well as statistics and query of word familiarity. The destructor is automatically called when the object dies. You can define a destructor to do the aftermath when the object dies, such as releasing memory, etc.

The creation of the user class is used to realize the registration and login of the user account and password**…**

Figure 4.3 Use of destructors and constructors

A class is a user-defined type. If a class is to be used in the program, it must be explained in advance, or an existing class must be used.

(classes written by others, classes in the standard library, etc.)

Define user-defined functions

(Seven functions corresponding to the word book retrieval system)

Word book entry, word book modification, word book deletion, recitation, proficiency statistics, proficiency query, return to login

The detailed code is as follows:

The following 1-6 functions are related to ****cout<<cin>>

Use cout<< to output data of various data types, and to display output information (including special symbols) on the screen in various ways.

When using cin to read data from standard input, the commonly used methods are cin>>, cin.get(), cin.getline().

Figure 4.4 Related concepts of cin and cout****

The user-defined function is

It is used to enter words, Chinese meanings and word parts of speech in the word book, corresponding to the function ****1 word book entry

Figure 4.5 Definition of the AddWord function

The user-defined function is

Used to modify words, Chinese meanings and word parts of speech in the word book, corresponding to function 2 word book modification

Continue from above to below

Figure 4.6 Definition of Modify Word function

The user-defined function is

Used to delete the corresponding function of the word in the word book****3 Word book deletion

Figure 4.7 Definition of DeleteWord function

Generate a random number for a question not equal to a specific number

Figure 4.8 Definition of the RandExceptNum function

The most important functions in the word memorization system:

recite function

Corresponding function ****4 recite

Note: Since the code is too long (about three pages or so), most of the analysis is placed in the code as comments

void ReciteWord() {

int dis[100], flag[100];

int num, failnum = 0;

cout << "Please enter the number of this recitation,no more than 100:";

cin >> num;

if (num > 0 && num <= 100) {

​       cout << "The words remembered this time are as follows" << num << "indivual:";

​       for (int i = 0; i < num; i++) {

​           dis[i] = rand() % wlen;

​           cout << i + 1 << "\t\t" << word[dis[i]].getvalue() << "\t\t" << word[dis[i]].getnature() << "\t\t" << word[dis[i]].getmean() << endl;

​       }

​       while (1) {

​           failnum = 0;

​           memset(flag, 0, sizeof(flag));    //The flag array is set to 0 to indicate that the question is incorrect 

​           cout << "Enter 1 to start reciting the selected topic, enter 2 to start spelling recitation, and enter 3 to abandon this recitation:";

​           int tag;

​           cin >> tag;

​           if (tag == 1) {

​              for (int i = 0; i < num; i++) {

​                  int answer = rand() % 2;     //When answer == 1, the answer is B, when equal to 0, the correct item is A 

​                  if (rand() % 2) {

​                     cout << "the first" << i + 1 << "question:" << "Please select the English corresponding to the Chinese meaning:" << word[dis[i]].getmean() << ":\tA ";

​                     if (answer) {

​                         cout << word[RandExceptNum(dis[i])].getvalue() << "\tB " << word[dis[i]].getvalue() << endl;

​                     }

​                     else {

​                         cout << word[dis[i]].getvalue() << "\tB " << word[RandExceptNum(dis[i])].getvalue() << endl;

​                     }

​                  }

​                  else {

​                     cout << "the first" << i + 1 << "question:" << "Please select the Chinese corresponding to the English word:" << word[dis[i]].getvalue() << ":\tA ";

​                     if (answer) {

​                         cout << word[RandExceptNum(dis[i])].getmean() << "\tB " << word[dis[i]].getmean() << endl;

​                     }

​                     else {

​                         cout << word[dis[i]].getmean() << "\tB " << word[RandExceptNum(dis[i])].getmean() << endl;

​                     }

​                  }

​                  string tg;

​                  cin >> tg;

​                  if ((tg[0] == 'A' && !answer) || (tg[0] == 'B' && answer)) {

​                     word[dis[i]].addpro(now_user);

​                     flag[i] = 1;      //The flags array is set to 1 to indicate that the answer is correct 

​                     cout << "correct answer!\n" << endl;

​                  }

​                  else {

​                     word[dis[i]].reducepro(now_user);

​                     failnum++;

​                     cout << "wrong answer!\n" << endl;

​                  }

​              }

​              if (failnum) {

​                  cout << "enter Y/y To strengthen the wrong question:";

​                  string xy;

​                  cin >> xy;

​                  if (xy[0] == 'Y' || xy[0] == 'y') {

​                     for (int i = 0; i < num; i++) {

​                         if (flag[i]) continue;

​                         int answer = rand() % 2;     //When answer == 1, the answer is B, when equal to 0, the correct item is A 

​                         if (rand() % 2) {

​                            cout << "the first" << i + 1 << "question:" << "Please select the English corresponding to the Chinese meaning:" << word[dis[i]].getmean() << ":\tA ";

​                            if (answer) {

​                                cout << word[RandExceptNum(dis[i])].getvalue() << "\tB " << word[dis[i]].getvalue() << endl;

​                            }

​                            else {

​                                cout << word[dis[i]].getvalue() << "\tB " << word[RandExceptNum(dis[i])].getvalue() << endl;

​                            }

​                         }

​                         else {

​                            cout << "the first" << i + 1 << "question:" << "Please select the Chinese corresponding to the English word:" << word[dis[i]].getvalue() << ":\tA ";

​                            if (answer) {

​                                cout << word[RandExceptNum(dis[i])].getmean() << "\tB " << word[dis[i]].getmean() << endl;

​                            }

​                            else {

​                                cout << word[dis[i]].getmean() << "\tB " << word[RandExceptNum(dis[i])].getmean() << endl;

​                            }

​                         }

​                         string tg;

​                         cin >> tg;

​                        if ((tg[0] == 'A' && !answer) || (tg[0] == 'B' && answer)) {

​                            word[dis[i]].addpro(now_user);

​                             cout << "correct answer!\n" << endl;

​                         }

​                         else {

​                            word[dis[i]].reducepro(now_user);

​                            cout << "wrong answer!\n" << endl;

​                         }

​                     }

​                  }

​              }

​              else {

​                  cout << "There is no wrong question, please keep going!" << endl;

​              }

​           }

​           else if (tag == 2) {

​              for (int i = 0; i < num; i++) {

​                  cout << "the first" << i + 1 << "question:" << "Please enter the English corresponding to the Chinese meaning:" << word[dis[i]].getmean() << ":";

​                  string tg;

​                  cin >> tg;

​                  if (tg == word[dis[i]].getvalue()) {

​                     word[dis[i]].addpro(now_user);

​                     flag[i] = 1;

​                     cout << "correct answer!\n" << endl;

​                  }

​                  else {

​                     word[dis[i]].reducepro(now_user);

​                     failnum++;

​                     cout << "wrong answer!\n" << endl;

​                  }

​              }

​              if (failnum) {

​                  cout << "enter Y/y To strengthen the wrong question:";

​                  string xy;

​                  cin >> xy;

​                  if (xy[0] == 'Y' || xy[0] == 'y') {

​                     for (int i = 0; i < num; i++) {

​                         cout << "the first" << i + 1 << "question:" << "Please enter the English corresponding to the Chinese meaning:" << word[dis[i]].getmean() << ":";

​                         string tg;

​                         cin >> tg;

​                         if (tg == word[dis[i]].getvalue()) {

​                            word[dis[i]].addpro(now_user);

​                            cout << "correct answer!\n" << endl;

​                         }

​                         else {

​                            word[dis[i]].reducepro(now_user);

​                            cout << "wrong answer!\n" << endl;

​                         }

​                     }

​                  }

​              }

​              else {

​                  cout << "There is no wrong question, please keep going!" << endl;

​              }

​           }

​           else if (tag == 3) {

​              break;

​           }

​           else {

​              cout << "Your input is incorrect, please try again!" << endl;

​           }

​       }

​    }

}

C/C++ memory partition: stack, heap, global (static, global), constant area (string), program code area

Ordinary properties have the same memory layout as structs.

A class can also be defined first, and then implement the function body through the domain access operator.

The user-defined function is

Used for familiarity statistics, corresponding to function ****5 Proficiency statistics

Figure 4.9 Definition of the ProCalculate function

Compared with the simple code in the previous part, the two for loops used in the definition of the ProCalculate function are used to achieve proficiency statistics, which are more concise and readable for calling while.

The user-defined function is

Used for familiarity query, corresponding to function 6 Familiarity query

Figure 4.10 Definition of the ProSearch function

The definition of the ProSearch function uses the nested use of if{ }else{ for(){} }.

main function

Figure 4.11 Main function (definition of menu bar)

V. Test data and analysis of results

1**, user registration**

Figure 5.1 User registration

Enter 2 to register the account and password. According to the prompt, the user needs to:

1. Enter name (no restrictions)

2. Enter the account you want to register (pure numbers within 9 digits)

3. Enter the password when logging in (pure numbers within 9 digits)

4. Re-enter the confirmation password to take effect

2. User login

Figure 5.2 User login

Enter 1 to log in to the account and password. According to the prompt, the user needs to:

1. Enter the account number

2. enter password

3**, login interface**

Figure 5.3 User login interface

After the login is successful, the interface is entered, and then the user enters the corresponding serial number according to the needs to realize the function

4. Function debugging (using vs2022 compiler)

The above six pictures correspond to the functions respectively

1. Word book entry

2. Modification of the word book

3. Delete the word book

4. Recite

6. Proficiency query

7. Return to login

The above is the result of running all functions.

6. Problems in the debugging process

1. Missing header file #include

Figure 6.1 Missing header file error

Solution: add the header file #include

2. Formal parameters are not compatible

Figure 6.2 Incompatibility error between actual and formal parameters

Solution:

1. Add "const" to the front of the char * defined in the structure, and standardize the type according to the prompts

2. Set the compilation mode to ANSI:

project->Attributes->Project default->character set, then put UNICODE Select multibyte, recompile

This completes the setup and the Error is resolved.

3. Missing Statement

Solution: Complete the statement

4. Missing undefined identifier

Solution: The same can be filled

Seven, curriculum design summary

1. Not skilled enough in the use of classes.

2. The use of user-defined functions is not standardized.

3. Compatibility of actual parameters

4. The maximum number of users of this word memorization system is only 200, and the maximum number of words is 2000, which is the length of the array, which can be changed, and can be defined as a constant later.

5. Use cout to output data of various data types, and display output information (including special symbols) on the screen in various ways.

\6. After the program completes the user registration, it must output 3. Exit to complete the saving of the user account and password

\7. The class can also be defined first, and then implement the function body through the domain access operator.

A class is a user-defined type. If a class is to be used in the program, it must be explained in advance, or an existing class must be used.

(classes written by others, classes in the standard library, etc.)

\8. Use destructors and arrays to realize the entry, modification and deletion of word parts and definitions, as well as statistics and query of word familiarity. The destructor is automatically called when the object dies. You can define a destructor to do the aftermath when the object dies, such as releasing memory, etc.

The most difficult thing to achieve in this code is 4 recitation, which needs to be modified by referring to the relevant blog of CSDN to achieve.

Note: This question uses the vs2022 compiler.

Tags: Front-end Algorithm

Posted by john-formby on Sun, 11 Sep 2022 21:29:45 +0300