aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Ten Eyck <[email protected]>2021-11-16 20:48:42 -0800
committerJoseph Ten Eyck <[email protected]>2021-11-16 20:48:42 -0800
commit24f1c58635a8bb9963e2750729d8b1f5e400fa05 (patch)
tree57e49850b2ba33e851b1f8a84b957d7d3d0614b3
parentAdd online IDE url (diff)
downloadcst116-lab7-josephteneyck-24f1c58635a8bb9963e2750729d8b1f5e400fa05.tar.xz
cst116-lab7-josephteneyck-24f1c58635a8bb9963e2750729d8b1f5e400fa05.zip
Lab 7 homework program complete!HEADmaster
-rw-r--r--CST116F2021-Lab7/CST116F2021-Lab7 - Joseph Ten eyck.cpp20
-rw-r--r--CST116F2021-Lab7/CST116F2021-Lab7.cpp20
-rw-r--r--CST116F2021-Lab7/CST116F2021-Lab7.vcxproj6
-rw-r--r--CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters10
-rw-r--r--CST116F2021-Lab7/Functions.cpp153
-rw-r--r--CST116F2021-Lab7/Header.h21
-rw-r--r--RUNS.txt178
7 files changed, 386 insertions, 22 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7 - Joseph Ten eyck.cpp b/CST116F2021-Lab7/CST116F2021-Lab7 - Joseph Ten eyck.cpp
new file mode 100644
index 0000000..f78c8e7
--- /dev/null
+++ b/CST116F2021-Lab7/CST116F2021-Lab7 - Joseph Ten eyck.cpp
@@ -0,0 +1,20 @@
+//=============================================
+// CODE FOR MODULE 7: LAB 7 PROGRAM IS BELOW
+//=============================================
+
+#include "Header.h"
+
+int main()
+{
+ int menu_choice = 0;
+ int current_place = 1;
+
+ string string_array[MAX_STRINGS];
+
+ do
+ {
+ displayMenu(menu_choice); //displays menu, takes in user menu choice
+
+ processMenuChoice(menu_choice, string_array, current_place); //processes menu choice, calls relevant function
+ } while (menu_choice != 5);
+} \ No newline at end of file
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.cpp b/CST116F2021-Lab7/CST116F2021-Lab7.cpp
deleted file mode 100644
index 77b01eb..0000000
--- a/CST116F2021-Lab7/CST116F2021-Lab7.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// CST116F2021-Lab7.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
-
-#include <iostream>
-
-int main()
-{
- std::cout << "Hello World!\n";
-}
-
-// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
-// Debug program: F5 or Debug > Start Debugging menu
-
-// Tips for Getting Started:
-// 1. Use the Solution Explorer window to add/manage files
-// 2. Use the Team Explorer window to connect to source control
-// 3. Use the Output window to see build output and other messages
-// 4. Use the Error List window to view errors
-// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
-// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj
index 5aec3b1..8dac1ad 100644
--- a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj
+++ b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj
@@ -139,7 +139,11 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="CST116F2021-Lab7.cpp" />
+ <ClCompile Include="CST116F2021-Lab7 - Joseph Ten eyck.cpp" />
+ <ClCompile Include="Functions.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="Header.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters
index e6b507e..7c4359b 100644
--- a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters
+++ b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters
@@ -15,8 +15,16 @@
</Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="CST116F2021-Lab7.cpp">
+ <ClCompile Include="CST116F2021-Lab7 - Joseph Ten eyck.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Functions.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="Header.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/CST116F2021-Lab7/Functions.cpp b/CST116F2021-Lab7/Functions.cpp
new file mode 100644
index 0000000..5e3335e
--- /dev/null
+++ b/CST116F2021-Lab7/Functions.cpp
@@ -0,0 +1,153 @@
+#include "Header.h"
+
+void displayMenu(int& menu_choice) //displays menu, takes in user menu choice
+{
+ do
+ {
+ cout << "\n\t\t==============================";
+ cout << "\n\t\t What would you like to do?";
+ cout << "\n\t\t==============================";
+
+ cout << "\n\n\t1) Add strings to array";
+ cout << "\n\t2) Print array";
+ cout << "\n\t3) Find string or substring in array";
+ cout << "\n\t4) Remove string based on location within array";
+ cout << "\n\t5) Exit";
+
+ cout << "\n\n\t\tMenu choice #: ";
+ cin >> menu_choice;
+
+ if (menu_choice < 1 || menu_choice > 5)
+ {
+ cout << "\n\nError: Invalid menu choice\n";
+ }
+ } while (menu_choice < 1 || menu_choice > 5);
+}
+
+void processMenuChoice(int menu_choice, string string_array[], int& current_place) //processes menu choice, calls relevant function
+{
+ switch (menu_choice)
+ {
+ case 1:
+ {
+ addStrings(string_array, current_place);
+ break;
+ }
+ case 2:
+ {
+ printArray(string_array, current_place);
+ break;
+ }
+ case 3:
+ {
+ findString(string_array, current_place);
+ break;
+ }
+ case 4:
+ {
+ removeString(string_array, current_place);
+ break;
+ }
+ case 5:
+ {
+ cout << "\n\t\t~ Goodbye! ~" << endl;
+ break;
+ }
+ }
+}
+
+void addStrings(string string_array[], int& current_place) //gives user ability to add strings to the array
+{
+ cout << "\n\t---------------------------------------------------------------------------";
+ cout << "\n\t Type a string to be added to the array then press enter to add another.";
+ cout << "\n\t To stop adding strings, type '0' and press enter.";
+ cout << "\n\t---------------------------------------------------------------------------\n";
+
+ cout << "\n\tEnter string: ";
+ cin >> string_array[current_place - 1]; //overwrites "0" that is later entered to stop the loop below
+
+ do //loop for entering strings
+ {
+ cout << "\n\tEnter string: ";
+ cin >> string_array[current_place];
+ current_place++;
+ } while (string_array[current_place - 1] != "0");
+}
+
+void printArray(string string_array[], int& current_place) //prints all strings in the array
+{
+ int count = 0;
+
+ cout << "\n\t---------------------------------------------------------------";
+ cout << "\n\t The current string array (shown with numbers for reference)";
+ cout << "\n\t---------------------------------------------------------------\n";
+
+ do
+ {
+ cout << "\n\t" << count + 1 << ". " << string_array[count];
+ count++;
+ } while (count < current_place - 1); // uses "less than" as to not print the "0" from the last place in the array
+}
+
+void findString(string string_array[], int& current_place) //gives user ability to search for strings or substrings within the array, displays if they are found
+{
+ string subString = "0"; //string or substring we are searching for
+ int i = 0, j = 0, k = 0; //i = letter of substring, j = word in array, k = letter in word in array
+
+ cout << "\n\t---------------------------------------------";
+ cout << "\n\t Enter a string or substring to search for";
+ cout << "\n\t---------------------------------------------\n";
+
+ cout << "\n\tString/substring: ";
+ cin >> subString;
+
+ while (i != subString.size() && j < MAX_STRINGS) //loops while the substring has not been found AND we have not gone through the entire array
+ {
+ i = 0; //resets these values to check the substring against the next word in the testarray
+ k = 0;
+
+ while ((subString[i] != string_array[j][k]) && (k < string_array[j].size())) //searches a single word for a letter from substring
+ k++;
+
+ if (subString[i] == string_array[j][k] && k < string_array[j].size()) //if a substring letter is found....
+ while ((subString[i] == string_array[j][k]) && (i < subString.size())
+ && k < string_array[j].size())
+ {
+ i++; //go to the next substring letter
+ k++; //move to the next teststring word letter
+ }
+ j++; //move to the next word within the testarray
+ }
+
+ if (i == subString.size()) //if i (the place in the substring) has gotten to the end of the substring (all letters found in succession)....
+ cout << "\n\tString/substring '" << subString << "' was found!" << endl;
+
+ else
+ cout << "\n\tString/substring '" << subString << "' was not found." << endl;
+}
+
+void removeString(string string_array[], int& current_place) //gives user ability to remove a string from the array based on string location, displays removed string
+{
+ int to_remove = 0;
+ string removed = "0";
+
+ cout << "\n\t----------------------------------------------------------------";
+ cout << "\n\t Enter the number of a string in the array to remove (1 - 150)";
+ cout << "\n\t----------------------------------------------------------------\n";
+
+ cout << "\n\tIndex number: ";
+ cin >> to_remove;
+
+ to_remove--; //accounts for user entering string number instead of index number
+
+ removed = string_array[to_remove];
+
+ cout << "\n\t\tThe removed string was: '" << removed << "'" << endl;
+
+ for (int i = to_remove; i < MAX_STRINGS - 1; i++) //compresses the array
+ {
+ string_array[i] = string_array[i + 1];
+ }
+
+ current_place--;
+} \ No newline at end of file
diff --git a/CST116F2021-Lab7/Header.h b/CST116F2021-Lab7/Header.h
new file mode 100644
index 0000000..f33faea
--- /dev/null
+++ b/CST116F2021-Lab7/Header.h
@@ -0,0 +1,21 @@
+#include <iostream>
+#include <string>
+#include <cstring>
+#include <iomanip>
+
+using namespace std;
+
+#define MAX_STRINGS 150
+
+
+void displayMenu(int&); //displays menu, takes in user menu choice
+
+void processMenuChoice(int, string[], int&); //processes menu choice, calls relevant function
+
+void addStrings(string[], int&); //gives user ability to add strings to the array
+
+void printArray(string[], int&); //prints all strings in the array
+
+void findString(string[], int&); //gives user ability to search for strings or substrings within the array, displays if they are found
+
+void removeString(string[], int&); //gives user ability to remove a string from the array based on string location, displays removed string \ No newline at end of file
diff --git a/RUNS.txt b/RUNS.txt
new file mode 100644
index 0000000..26f4553
--- /dev/null
+++ b/RUNS.txt
@@ -0,0 +1,178 @@
+////////////////////////////////////
+// BELOW IS A RUN FOR THE PROGRAM
+////////////////////////////////////
+
+
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 1
+
+ ---------------------------------------------------------------------------
+ Type a string to be added to the array then press enter to add another.
+ To stop adding strings, type '0' and press enter.
+ ---------------------------------------------------------------------------
+
+ Enter string: The
+
+ Enter string: rabbit
+
+ Enter string: was
+
+ Enter string: a
+
+ Enter string: bouncy
+
+ Enter string: boy
+
+ Enter string: 0
+
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 2
+
+ ---------------------------------------------------------------
+ The current string array (shown with numbers for reference)
+ ---------------------------------------------------------------
+
+ 1. The
+ 2. rabbit
+ 3. was
+ 4. a
+ 5. bouncy
+ 6. boy
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 3
+
+ ---------------------------------------------
+ Enter a string or substring to search for
+ ---------------------------------------------
+
+ String/substring: unc
+
+ String/substring 'unc' was found!
+
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 3
+
+ ---------------------------------------------
+ Enter a string or substring to search for
+ ---------------------------------------------
+
+ String/substring: me
+
+ String/substring 'me' was not found.
+
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 2
+
+ ---------------------------------------------------------------
+ The current string array (shown with numbers for reference)
+ ---------------------------------------------------------------
+
+ 1. The
+ 2. rabbit
+ 3. was
+ 4. a
+ 5. bouncy
+ 6. boy
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 4
+
+ ----------------------------------------------------------------
+ Enter the number of a string in the array to remove (1 - 150)
+ ----------------------------------------------------------------
+
+ Index number: 5
+
+ The removed string was: 'bouncy'
+
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 2
+
+ ---------------------------------------------------------------
+ The current string array (shown with numbers for reference)
+ ---------------------------------------------------------------
+
+ 1. The
+ 2. rabbit
+ 3. was
+ 4. a
+ 5. boy
+ ==============================
+ What would you like to do?
+ ==============================
+
+ 1) Add strings to array
+ 2) Print array
+ 3) Find string or substring in array
+ 4) Remove string based on location within array
+ 5) Exit
+
+ Menu choice #: 5
+
+ ~ Goodbye! ~
+
+C:\Users\eclip\Source\Repos\cst116-lab7-JosephTenEyck\Debug\CST116F2021-Lab7.exe (process 7732) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .