diff options
| -rw-r--r-- | CST116F2021-Lab7/CST116F2021-Lab7.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.cpp b/CST116F2021-Lab7/CST116F2021-Lab7.cpp index 66296d7..2356ed0 100644 --- a/CST116F2021-Lab7/CST116F2021-Lab7.cpp +++ b/CST116F2021-Lab7/CST116F2021-Lab7.cpp @@ -131,3 +131,86 @@ int main() } 11c + + #include <iostream> +#include <string> + +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"; + } + + } +} |