diff options
| author | James Lawrance <[email protected]> | 2021-11-12 12:10:08 -0800 |
|---|---|---|
| committer | James Lawrance <[email protected]> | 2021-11-12 12:10:08 -0800 |
| commit | bd0aaa8aec690233421775b156b7ccd151ee3947 (patch) | |
| tree | f87f99d24fba0bb13ece594c06af06a27684272e | |
| parent | Add online IDE url (diff) | |
| download | archived-cst116-lab7-jemersonlawrance-bd0aaa8aec690233421775b156b7ccd151ee3947.tar.xz archived-cst116-lab7-jemersonlawrance-bd0aaa8aec690233421775b156b7ccd151ee3947.zip | |
11b complete
| -rw-r--r-- | CST116F2021-Lab7/CST116F2021-Lab7.cpp | 55 | ||||
| -rw-r--r-- | CST116F2021-Lab7/CST116F2021-Lab7.vcxproj | 7 | ||||
| -rw-r--r-- | CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters | 13 | ||||
| -rw-r--r-- | CST116F2021-Lab7/Functions.cpp | 109 | ||||
| -rw-r--r-- | CST116F2021-Lab7/Header.h | 14 | ||||
| -rw-r--r-- | CST116F2021-Lab7/Output.txt | 70 |
6 files changed, 252 insertions, 16 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.cpp b/CST116F2021-Lab7/CST116F2021-Lab7.cpp index 77b01eb..c03ef4e 100644 --- a/CST116F2021-Lab7/CST116F2021-Lab7.cpp +++ b/CST116F2021-Lab7/CST116F2021-Lab7.cpp @@ -1,20 +1,43 @@ -// CST116F2021-Lab7.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +#include "Header.h" -#include <iostream> +//12a +//int main() +//{ + //initializations +// string strData[100]; +// int cnt = 1; + //title and prompt +// cout << setw(65) << "--String Reader--\n" +// << endl; + +// cout << "You can enter up to one hundred strings. When finished entering, please type \"done,\" and your strings will display.\n"; + + //get string data +// getStringData(strData, cnt); + + //display +// displayStrings(strData, cnt); +//} + +//12b 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 + //initializations + string strData[100]; + + //title and start prompt + cout << setw(65) << "--String Reader--\n" + << endl; + + cout << "You can enter up to one hundred strings. When finished entering, please type \"done,\" and your strings will display.\n"; + + //get string data + getStringData(strData); + + //display + displayStrings(strData); + + //find string + findString(strData); +}
\ No newline at end of file diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj index 5aec3b1..a789c19 100644 --- a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj +++ b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj @@ -140,6 +140,13 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="CST116F2021-Lab7.cpp" /> + <ClCompile Include="Functions.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Header.h" /> + </ItemGroup> + <ItemGroup> + <Text Include="Output.txt" /> </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..e00b1b6 100644 --- a/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters +++ b/CST116F2021-Lab7/CST116F2021-Lab7.vcxproj.filters @@ -18,5 +18,18 @@ <ClCompile Include="CST116F2021-Lab7.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> + <ItemGroup> + <Text Include="Output.txt"> + <Filter>Source Files</Filter> + </Text> </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..de7de7f --- /dev/null +++ b/CST116F2021-Lab7/Functions.cpp @@ -0,0 +1,109 @@ +#include "Header.h" + +//getStringData definition +int getStringData(string data[]) +{ + int cntGen = 0; + + while (cntGen < 99) + { + cout << "Enter string #" << cntGen+1 << ": "; + cin >> data[cntGen]; + if (data[cntGen] == "done") + { + data[cntGen] = "\0"; + return 1; + } + + cntGen++; + } +} + +//displayStrings definition +int displayStrings(string data[]) +{ + //initializations + int cntGen = 1; + + cout << endl; + + while (cntGen < 100) + { + cout << setw(10 + (data[cntGen - 1].size())) << data[cntGen - 1] + << setw(20) << right << data[cntGen] + << endl; + + cntGen = cntGen + 2; + + if (data[cntGen - 1] == "done") + { + return 1; + } + else if (data[cntGen] == "\0" || data[cntGen] == "done") + { + cout << setw(20) << right << data[cntGen - 1]; + return 1; + } + } +} + + +//prints out "match found" each time a letter of the user string is found. +//once a match for the first letter is found, then it moves onto the next, printing "match found" for each match +void findString(string data[]) +{ + //initializations + int cntData = 0; + int cntDataChar; + int cntUserChar; + + string user; + + //prompt + cout << "\nEnter something to find whether it exists as a string or substring in the display: "; + cin >> user; + + cout << endl; + //calculate matches needed + int match = user.size(); + + //check + while (data[cntData] != "\0") + { + //reset individual character counters and matches + cntDataChar = 0; + cntUserChar = 0; + match = user.size(); + + while (cntDataChar < data[cntData].size() && (cntUserChar < user.size() && cntDataChar < data[cntData].size())) + { + + while (cntUserChar < user.size() && cntDataChar < data[cntData].size()) + { + if (user[cntUserChar] == data[cntData][cntDataChar]) + { + if ((user[cntUserChar + 1] != data[cntData][cntDataChar + 1]) && (match < user.size() && match != 1)) + { + cntDataChar++; + break; + } + else + { + match--; + cntUserChar++; + } + if (match == 0) + { + cout << "\n\"" << user << "\" has been found in the display" + << endl; + exit(0); + } + } + cntDataChar++; + } + } + cntData++; + } + + cout << "\n\"" << user << "\" has not been found in the display"; +}
\ No newline at end of file diff --git a/CST116F2021-Lab7/Header.h b/CST116F2021-Lab7/Header.h new file mode 100644 index 0000000..a29e4fd --- /dev/null +++ b/CST116F2021-Lab7/Header.h @@ -0,0 +1,14 @@ +#pragma once + +#include <iostream> +#include <cstring> +#include <iomanip> + +using namespace std; + +//getStringData prototype +int getStringData(string data[]); +//displayStrings prototype +int displayStrings(string data[]); +//findString prototype +void findString(string data[]);
\ No newline at end of file diff --git a/CST116F2021-Lab7/Output.txt b/CST116F2021-Lab7/Output.txt new file mode 100644 index 0000000..e65ca29 --- /dev/null +++ b/CST116F2021-Lab7/Output.txt @@ -0,0 +1,70 @@ +James Lawrance Lab 7 +--------------------- + +11a - +output 1 - + --String Reader-- + +You can enter up to one hundred strings. When finished entering, please type "done," and your strings will display. +Enter string #1: Mint +Enter string #2: Caramel +Enter string #3: Raspberry +Enter string #4: Peppermint +Enter string #5: Watermelon +Enter string #6: Strawberry +Enter string #7: Toffee +Enter string #8: Cherry +Enter string #9: done + + Mint Caramel + Raspberry Peppermint + Watermelon Strawberry + Toffee Cherry + +11b - +output 1 - + + --String Reader-- + +You can enter up to one hundred strings. When finished entering, please type "done," and your strings will display. +Enter string #1: a +Enter string #2: aaawaaa +Enter string #3: done + + a aaawaaa + +Enter something to find whether it exists as a string or substring in the display: w + + +"w" has been found in the display + +output 2 - + + --String Reader-- + +You can enter up to one hundred strings. When finished entering, please type "done," and your strings will display. +Enter string #1: sgsongaeorgn +Enter string #2: done + + sgsongaeorgn + +Enter something to find whether it exists as a string or substring in the display: weather + + +"weather" has not been found in the display + +output 3 - + + --String Reader-- + +You can enter up to one hundred strings. When finished entering, please type "done," and your strings will display. +Enter string #1: Austria +Enter string #2: Australia +Enter string #3: done + + Austria Australia + +Enter something to find whether it exists as a string or substring in the display: stralia + + +"stralia" has been found in the display
\ No newline at end of file |