diff options
Diffstat (limited to 'CST116F2021-Lab7/Functions.cpp')
| -rw-r--r-- | CST116F2021-Lab7/Functions.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
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 |