aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author[email protected] <[email protected]>2021-11-16 20:52:50 -0800
committer[email protected] <[email protected]>2021-11-16 20:52:50 -0800
commit50e6a2dad5fc51a37c0c5ef29e467265a86aa59f (patch)
treeb7a9d9ddbedfe1dc2a5b9079d0d0b63a85951e12
parentAdd online IDE url (diff)
downloadcst116-lab7-rayyanansari03-50e6a2dad5fc51a37c0c5ef29e467265a86aa59f.tar.xz
cst116-lab7-rayyanansari03-50e6a2dad5fc51a37c0c5ef29e467265a86aa59f.zip
Lab 7 Answers
-rw-r--r--CST116F2021-Lab7/CST116F2021-Lab7.cpp136
1 files changed, 134 insertions, 2 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.cpp b/CST116F2021-Lab7/CST116F2021-Lab7.cpp
index 77b01eb..f34c751 100644
--- a/CST116F2021-Lab7/CST116F2021-Lab7.cpp
+++ b/CST116F2021-Lab7/CST116F2021-Lab7.cpp
@@ -1,11 +1,143 @@
-// CST116F2021-Lab7.cpp : This file contains the 'main' function. Program execution begins and ends there.
+// Lab7Ansari.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
+#include <iomanip>
+#include <cstring>
+#include <fstream>
+#include <string>
+
+using namespace std;
+
+void createStringArray(string strArray[100], int& arrayLen);
+void findStringInArray(string u, string strArray[100], int arrayLen);
int main()
{
- std::cout << "Hello World!\n";
+ string strArray[100];
+ int arrayLen;
+ string findInString;
+
+
+
+
+ createStringArray(strArray, arrayLen);
+
+ cout << "\n Enter the string you would like to find: ";
+ cin >> findInString;
+
+ findStringInArray(findInString, strArray, arrayLen);
+
+
+
+
+
+}
+
+
+void findStringInArray(string u, string strArray[100], int arrayLen) {
+
+ bool found = false;
+ int ulen = u.length();
+
+ for (int i = 0; i < arrayLen; i++) {
+
+ for (int x = 0; x < strArray[i].length() - ulen; x++) {
+
+ cout << strArray[i].substr(x, x + ulen) << "\n";
+
+ if (strArray[i].substr(x, x + ulen) == u.substr(0, ulen)) {
+
+
+
+ found = true;
+
+
+ }
+
+ }
+
+ }
+
+ if (found == true) {
+
+ cout << '\n' << "Substring Found! " << endl;
+
+ }
+ else {
+
+ cout << '\n' << "Substring Not Found! " << endl;
+
+
+ }
+
+
+}
+
+void createStringArray(string strArray[100], int& arrayLen) {
+
+ int option;
+ int loop = 0;
+ do {
+
+ cout << "Please enter 0 to add a value, 1 to print the strings, 2 to remove a string, or any othe rnumber to exit: ";
+ cin >> option;
+ cout << endl;
+ if (option == 0) {
+ string addString;
+ cout << "Enter string you would like to enter: ";
+ cin >> addString;
+ cout << endl;
+ strArray[loop] = addString;
+ loop++;
+
+ }
+
+ else if (option == 2) {
+ int rpos;
+ cout << '\n' << "What number string would you like to remove? : ";
+ cin >> rpos;
+ cout << endl;
+
+ for (int y = 0; y < loop; y++) {
+
+ if (y == rpos - 1) {
+
+ for (int z = rpos - 1; z < loop; z++) {
+
+ strArray[z] = strArray[z + 1];
+
+
+ }
+
+ loop--;
+
+
+ }
+
+ }
+
+
+ }
+ else if (option == 1) {
+
+ for (int i = 0; i < loop; i++) {
+
+ cout << "String " << i + 1 << ": " << strArray[i];
+ cout << endl;
+
+ }
+ }
+
+
+
+
+ } while (option == 0 || option == 1 || option == 2);
+
+ arrayLen = loop;
+
+
+
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu