diff --git a/Project8/Project8.cpp b/Project8/Project8.cpp new file mode 100644 index 0000000..c75dd73 --- /dev/null +++ b/Project8/Project8.cpp @@ -0,0 +1,55 @@ +// Corey Williams +// COP3530 01Z +// Project 8 Recursion + +/* + +Write a C/C++ or Java application that uses a "vector" container to store 10 strings and a recursive function/method +"isPalindrome" (i.e., must be written) to determine whether a string argument is a palindrome. +The application must perform the following. + + - Prompt the user for the 10 strings, storing in a "vector" container + - Uses a loop to call "isPalindrome" passing it one of the strings from the "vector" + - Display message with the string and results of the palindrome test +*/ + +#include +#include +#include + +using namespace std; + +//Takes arguments of string vector by reference and element to check. +void isPalindrome(vector& strVec, vector::iterator i) { + + //Makes copy of vector string element being tested and reverses + string revStr = *i; + reverse(revStr.begin(), revStr.end()); + + //If the reversed string is true, this means the string is a palidrome (same forward and backward). Prints test string and result. + cout << endl << "String:\t" << *i << "\tIs Palindrome: "; + if (*i == revStr) { cout << "TRUE"; } + else { cout << "FALSE"; } + + //increments iterator, tests if there are more elements, and calls self again if there are more elements. + if (++i != strVec.end()) { + isPalindrome(strVec, i); + } +} + +int main() +{ + vector userInputs; + string tmpStr; + + //Collects user inputs into a vector of strings + for (int i = 1; i <= 10; i++) { + cout << "Enter test string " << i << " of 10: "; + cin >> tmpStr; + userInputs.push_back(tmpStr); + } + + //Passes in vector object by reference and iterator pointed to first element. + isPalindrome(userInputs, userInputs.begin()); +} + diff --git a/Project8/Project8.sln b/Project8/Project8.sln new file mode 100644 index 0000000..58bf4c8 --- /dev/null +++ b/Project8/Project8.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project8", "Project8.vcxproj", "{F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Debug|x64.ActiveCfg = Debug|x64 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Debug|x64.Build.0 = Debug|x64 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Debug|x86.ActiveCfg = Debug|Win32 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Debug|x86.Build.0 = Debug|Win32 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Release|x64.ActiveCfg = Release|x64 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Release|x64.Build.0 = Release|x64 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Release|x86.ActiveCfg = Release|Win32 + {F0C14BCC-2208-46B2-85FF-D5CDE83A5E7E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0600E70C-B421-4BE5-B48F-E9ED52D59953} + EndGlobalSection +EndGlobal diff --git a/Project8/Project8.vcxproj b/Project8/Project8.vcxproj new file mode 100644 index 0000000..33139a7 --- /dev/null +++ b/Project8/Project8.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {f0c14bcc-2208-46b2-85ff-d5cde83a5e7e} + Project8 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Project8/Project8.vcxproj.filters b/Project8/Project8.vcxproj.filters new file mode 100644 index 0000000..1838abc --- /dev/null +++ b/Project8/Project8.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file