diff options
| author | austinsworld15 <[email protected]> | 2021-11-15 17:14:44 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-15 17:14:44 -0800 |
| commit | 18d96963f11379a2913d2f5df17307f04efebafa (patch) | |
| tree | dc0f2827cb6c9c5f12fe39c476e045f5bd4ee37c | |
| parent | Update CST116F2021-Lab7.cpp (diff) | |
| download | cst116-lab7-austinsworld15-18d96963f11379a2913d2f5df17307f04efebafa.tar.xz cst116-lab7-austinsworld15-18d96963f11379a2913d2f5df17307f04efebafa.zip | |
Update CST116F2021-Lab7.cpp
| -rw-r--r-- | CST116F2021-Lab7/CST116F2021-Lab7.cpp | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.cpp b/CST116F2021-Lab7/CST116F2021-Lab7.cpp index c55ee7c..66296d7 100644 --- a/CST116F2021-Lab7/CST116F2021-Lab7.cpp +++ b/CST116F2021-Lab7/CST116F2021-Lab7.cpp @@ -63,6 +63,71 @@ int main() 12b - + #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; + + 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 |