Word storage, lookup, replacement and deletion

xiaoxiao2021-04-09  412

#include

#include

Using namespace std;

Void DataInput (char ** a); // data input module

INT Datasearch (char * a, char ** b); // Word Finding Module

Void DataReplace (Char * A, Char * B, Char ** C, INT D); // Word Replacement Module

Void DataShow (char ** a); // Data View Module

INT number; // Total number of words stored

int main ()

{

Int key; // Control various functions with a digital

INT N; // Replace or delete the number of words

Char * word1 = new char [50]; // Find words

Char * word2 = new char [50]; // Replace the word

COUT << "Please enter the number of words stored:";

CIN >> Number; // ******** This allows letters here to crash ******* Can join the detection input function to improve

Char ** p = new char * [number]; // 2D pointer points to stored data

For (int i = 0; i

p [i] = new char [50]; // The maximum length of each word is

DataInput (p);

While (Key! = 5) // Key to exit the program for 5

{

Cout << "Please select the action: / n" << "All replacement; (2) All deletion; (3) Find; (4) View the current state; (5) Exit; / n";

CIN >> KEY;

IF (Key == 1)

{

Cout << "needs to be replaced with:";

CIN >> WORD2;

While (cin.get ()! = '/ n') // Avoid input and jumps that enters multiple spaces

;

For (int i = 0; i

STRCPY (P [I], Word2);

COUT << "/ n All replacements! / n / n";

}

ELSE IF (key == 2)

{

Cout << "Do you want to delete all? Enter y to determine, the other key cancels;

CHAR TEMP;

CIN >> TEMP;

While (cin.get ()! = '/ n')

;

IF (Temp == 'Y' || TEMP == 'Y')

{

STRCPY (Word2, ");

For (int i = 0; i

STRCPY (P [I], Word2);

COUT << "/ n All delete completed! / n";

}

Cout << Endl;

}

Else IF (key == 3)

{

WHILE (key == 3) // Find the loop again

{

Cout << "Please enter the word you want to find:";

CIN >> Word1;

Int result = Datasearch (Word1, P);

COUT << "/ nCrecain found" << result << "one of the same words / N / N";

IF (Result! = 0)

{

Cout << "Please select an action: / n" << "(1) Replace; (2) delete; (3) lookup; (4) View the current state; (5) Exit; / n";

CIN >> KEY;

IF (Key == 1)

{

Cout << "/ N wants to replace several?"

CIN >> N;

While (n> result)

{

Cout << "Input error, currently only find" << Result << "alternative words, please re-enter:";

CIN >> N;

While (cin.get ()! = '/ n')

;

}

Cout << "/ n To replace:";

CIN >> WORD2;

While (cin.get ()! = '/ n')

;

DataReplace (Word1, Word2, P, N);

}

ELSE IF (key == 2)

{

Cout << "/ N want to delete a few?"

CIN >> N;

While (n> result)

{

Cout << "/ N input error, currently only finding" << result << "can delete words, please re-enter:";

CIN >> N;

While (cin.get ()! = '/ n')

;

}

STRCPY (Word2, ");

DataReplace (Word1, Word2, P, N);

}

Else IF (key == 3)

Key = 3; // Continue to find

Else IF (key == 4)

{

Cout << "/ n The current stored data is as follows: / n";

DataShow (P);

}

Else IF (key == 5)

Key = 5; // Exit system

}

ELSE // Find results, jump out of the loop

Break;

}

}

Else IF (key == 4)

{

Cout << "/ n The current stored data is as follows: / n";

DataShow (P);

}

Else IF (key == 5)

Key = 5; // Exit system

}

Cout << "/ n / n program end, thank you! ^ o ^ / n";

Delete [] Word1;

Delete [] Word2;

Delete [] P;

Return 0;

}

Void DataInput (char ** a)

{

Cout << "/ n input word: / n" by one by one;

For (int i = 0; i

{

COUT << "#" << i 1 << ":"

CIN >> A [I];

While (cin.get ()! = '/ n') // Avoid input and jumps that enters multiple spaces

;

}

Cout << "/ n word input is completed! / n / n";

}

INT Datasearch (char * a, char ** b)

{

INT count = 0; // Record the number of words that conform to the requirements

For (int i = 0; i

{

IF (strcmp (a, b [i]) == 0)

COUNT ;

}

Return count;

}

Void DataReplace (Char * A, Char * B, Char ** C, INT D)

{

INT TEMP = D; // Statistical replacement number

For (int i = 0; i

{

IF (strcmp (a, c [i]) == 0)

{

STRCPY (C [I], B);

TEMP -;

}

IF (Temp == 0)

Break;

}

Cout << "/ n operation complete! / n / N";

}

Void DataShow (char ** a)

{

For (int i = 0; i

{

COUT << a [i] << "

IF ((i 1)% 5 == 0)

Cout << Endl;

}

Cout << Endl;

}

转载请注明原文地址:https://www.9cbs.com/read-133098.html

New Post(0)