aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp
diff options
context:
space:
mode:
authorBenjamin Schroeder <[email protected]>2021-11-12 18:17:34 -0800
committerBenjamin Schroeder <[email protected]>2021-11-12 18:17:34 -0800
commitb21aaf4b4e60d28552856ae397535db5d84b999f (patch)
treea47cb6415210b274081c2a555ecc9f2dca427347 /CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp
parentAdd online IDE url (diff)
downloadcst116-lab7-bensprogramma-b21aaf4b4e60d28552856ae397535db5d84b999f.tar.xz
cst116-lab7-bensprogramma-b21aaf4b4e60d28552856ae397535db5d84b999f.zip
.cpp and .txt files
Diffstat (limited to 'CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp')
-rw-r--r--CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp b/CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp
new file mode 100644
index 0000000..a3ea111
--- /dev/null
+++ b/CST116F2021-Lab7/CST116F2021-Lab7_Schroeder.cpp
@@ -0,0 +1,158 @@
+// CST116F2021-Lab7.cpp : This file contains the 'main' function. Program execution begins and ends there
+// ...from : Lab7_Schroeder.cpp
+
+
+#include <iostream>
+#include<iomanip>
+#include<string>
+#define _CRT_SECURE_NO_WARNINGS
+#pragma warning(disable:4996)
+
+using namespace std;
+
+#define ARRAY_SIZE 100
+void menu(int&);
+void readData(int&);
+void printData(int&);
+void findString(int&);
+void deleteString(int&);
+string stringArray[ARRAY_SIZE]{};
+int item = 0;
+
+int main()
+{
+ menu(item);
+
+}
+
+
+void menu(int& item)
+{
+ int menuChoice = 0;
+ cout << "MENU: 1) Add a string 2) Print out 3) Find subString 4) Delete a string 5) Exit ...";
+
+ cin >> menuChoice;
+ if (cin.fail())
+ {
+ menuChoice = 0;
+ cout << "(you have to enter: 1,2,3,4 or 5 (start the program again))";
+ cin >> menuChoice;
+ }
+ else
+ {
+ while ((menuChoice < 1 || menuChoice >5))
+ {
+ cout << "(enter: 1,2,3,4,or 5) ";
+ cin >> menuChoice;
+ }
+ }
+
+
+ switch (menuChoice)
+ {
+ case 1:
+ {
+ readData(item);
+ break;
+ }
+ case 2:
+ {
+ printData(item);
+ break;
+ }
+ case 3:
+ {
+ findString(item);
+ break;
+ }
+ case 4:
+ {
+ deleteString(item);
+ break;
+ }
+ case 5:
+ {
+ cout << "Thankyou, Goodbye!!\n\n";
+ break;
+ }
+
+ }
+}
+
+void readData(int& item)
+{
+
+ string tempString;
+ cout << "Type in your string to add: ";
+ getline(cin >> ws, tempString);
+ stringArray[item] = tempString;
+ item++;
+ menu(item);
+}
+
+void printData(int& item)
+{
+ cout << "\n\nHere are your string entries...\n";
+ for (int i = 0; i < item; i++)
+ {
+ cout << i + 1 << ".\t" << stringArray[i] << "\n";
+ }
+ cout << "\n\n";
+ menu(item);
+}
+
+void findString(int& item)
+{
+ string temp = " ";
+ cout << "Enter the subString you want to search for: ";
+ cin >> temp;
+
+ string subString{ temp };
+
+ for (int k = 0; k <= item - 1; k++)
+ {
+ int i = 0, j = 0;
+ while ((subString[i] != stringArray[k][j]) && (j < stringArray[k].size()))
+ {
+ j++;
+ }
+
+ if (subString[i] == stringArray[k][j])
+ while ((subString[i] == stringArray[k][j]) && (i < subString.size()) && j < stringArray[k].size())
+ {
+ i++;
+ j++;
+ }
+
+ if (i == subString.size())
+ cout << "\tSubstring '" << subString << "' was found in string: " << k + 1 << "\n";
+ else
+ cout << "\t...not found in string: " << k + 1 << "\n";
+ }
+ cout << "\n\n";
+
+ menu(item);
+}
+
+void deleteString(int& item)
+{
+ int temp = 0;
+ cout << "Which string (1 to " << item << ") would you like to delete? ";
+ cin >> temp;
+ int i = temp - 1;
+ stringArray[i] = {};
+ for (i; i <= item - 1; i++)
+ {
+ stringArray[i] = stringArray[i + 1];
+
+ }
+ item--;
+ cout << "\n\n";
+ menu(item);
+
+}
+
+
+
+
+