CST 116 Austin Guertin Module 7: Lab 7 12a #include #include using namespace std; //function to read input void read(string str[], int idx) { getline(cin, str[idx]); } int main() { string str[100]; int choice, size = 0; while (1) { cout << "\nPress 1: To add a string\n"; cout << "Press 2: To print the strings\n"; cout << "Press 3: Exit the program\n\n"; cout << "Enter your choice down below: "; cin >> choice; if (choice == 1) { cin.ignore(80, '\n'); cout << "\nEnter a string: "; read(str, size++); } else if (choice == 2) break; else if (choice == 3) return 0; else cout << "\n\nInvalid input!\n\n"; } cout << endl << "The input strings are: \n\n"; for (int i = 0; i < size; i++) { if (str[i] == "don't print") break; cout << str[i] << endl; } return 0; } 12b #include #include using namespace std; void read(string str[], int idx) { getline(cin, str[idx]); } int main() { string str[100]; int choice, choice2, size = 0; string FindS; while (1) { cout << "\nPress 1: To add a string\n"; cout << "Press 2: To print the strings\n"; cout << "Press 3: Exit the program\n\n"; cout << "Enter your choice down below: "; cin >> choice; if (choice == 1) { cin.ignore(80, '\n'); cout << "\nEnter a string: "; read(str, size++); } else if (choice == 2) break; else if (choice == 3) return 0; else cout << "\n\nInvalid input!\n\n"; } cout << endl << "The input strings are: \n\n"; for (int i = 0; i < size; i++) { if (str[i] == "don't print") break; cout << str[i] << endl; } cout << "Would you like to find a specific string or substring in this array? ('1' for yes or '2' for no)\n"; cin >> choice2; if (choice2 == 1) { cout << "\nWhat is the word you want to look for?\n\n"; cin >> FindS; for (int i = 0; i < size; i++) { size_t found = str[i].find(FindS); if (found != std::string::npos) cout << "\nThe word " << FindS << " starts at position: " << found + 1 << "\n\n"; } return 0; } } 11c #include #include using namespace std; void read(string str[], int idx) { getline(cin, str[idx]); } int main() { string str[100]; int choice, choice2, size = 0; string FindS; int EraseStart=0, EraseAmount=0; while (1) { cout << "\nPress 1: To add a string\n"; cout << "Press 2: To print the strings\n"; cout << "Press 3: Exit the program\n\n"; cout << "Enter your choice down below: "; cin >> choice; if (choice == 1) { cin.ignore(80, '\n'); cout << "\nEnter a string: "; read(str, size++); } else if (choice == 2) break; else if (choice == 3) return 0; else cout << "\n\nInvalid input!\n\n"; } cout << endl << "The input strings are: \n\n"; for (int i = 0; i < size; i++) { if (str[i] == "don't print") break; cout << str[i] << endl; } cout << "Would you like to find a specific string or substring in this array or delete a part of the string? ('1' for yes or '2' for delete or '3' for none)\n"; cin >> choice2; if (choice2 == 1) { cout << "\nWhat is the word you want to look for?\n\n"; cin >> FindS; for (int i = 0; i < size; i++) { size_t found = str[i].find(FindS); if (found != std::string::npos) cout << "\nThe word " << FindS << " starts at position: " << found + 1 << "\n\n"; } return 0; } if (choice2 == 2) { for (int i = 0; i < size; i++) { cout << "\nWhat's the starting position you want to start erasing?\n\n"; cin >> EraseStart; cout << "\nWhat's the amount of characters you want to erase?\n\n"; cin >> EraseAmount; str[i].erase(EraseStart + 1, EraseAmount + 1); cout << "\nYour new sentence is: " << str[i]<<"\n\n"; } } }