diff --git a/FinalExamWorkpad/Exam.cpp b/FinalExamWorkpad/Exam.cpp new file mode 100644 index 0000000..6b98a20 --- /dev/null +++ b/FinalExamWorkpad/Exam.cpp @@ -0,0 +1,4 @@ +int main() { + int* p; + p = new int[10]; +} \ No newline at end of file diff --git a/FinalExamWorkpad/FinalExamWorkpad.sln b/FinalExamWorkpad/FinalExamWorkpad.sln new file mode 100644 index 0000000..1f856ef --- /dev/null +++ b/FinalExamWorkpad/FinalExamWorkpad.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}") = "FinalExamWorkpad", "FinalExamWorkpad.vcxproj", "{63154B5A-677F-444E-B042-3516C281B6F1}" +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 + {63154B5A-677F-444E-B042-3516C281B6F1}.Debug|x64.ActiveCfg = Debug|x64 + {63154B5A-677F-444E-B042-3516C281B6F1}.Debug|x64.Build.0 = Debug|x64 + {63154B5A-677F-444E-B042-3516C281B6F1}.Debug|x86.ActiveCfg = Debug|Win32 + {63154B5A-677F-444E-B042-3516C281B6F1}.Debug|x86.Build.0 = Debug|Win32 + {63154B5A-677F-444E-B042-3516C281B6F1}.Release|x64.ActiveCfg = Release|x64 + {63154B5A-677F-444E-B042-3516C281B6F1}.Release|x64.Build.0 = Release|x64 + {63154B5A-677F-444E-B042-3516C281B6F1}.Release|x86.ActiveCfg = Release|Win32 + {63154B5A-677F-444E-B042-3516C281B6F1}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B4961236-FD1F-447A-8C66-4D8F0EBDF6A1} + EndGlobalSection +EndGlobal diff --git a/FinalExamWorkpad/FinalExamWorkpad.vcxproj b/FinalExamWorkpad/FinalExamWorkpad.vcxproj new file mode 100644 index 0000000..2395add --- /dev/null +++ b/FinalExamWorkpad/FinalExamWorkpad.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {63154b5a-677f-444e-b042-3516c281b6f1} + FinalExamWorkpad + 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/FinalExamWorkpad/FinalExamWorkpad.vcxproj.filters b/FinalExamWorkpad/FinalExamWorkpad.vcxproj.filters new file mode 100644 index 0000000..a3834d7 --- /dev/null +++ b/FinalExamWorkpad/FinalExamWorkpad.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 diff --git a/Project12/Project12.cpp b/Project12/Project12.cpp index 639a3ca..fe46160 100644 --- a/Project12/Project12.cpp +++ b/Project12/Project12.cpp @@ -45,14 +45,14 @@ int main() { vector> relations; - for (int i = 0; i <= nodes; i++) { + for (int i = 0; i < nodes; i++) { relations.push_back({ i }); } cout << "\nEnter the node connections in the format \"X-Y\" where\n" << "X is the source node and Y is the destination node\n"; - cout << "Valid nodes range from 0 to " << nodes << " inclusive.\n" - << "Enter \'q\' to stop edge entry.\n"; + cout << "Valid nodes range from 0 to " << nodes-1 << " inclusive.\n" + << "Enter \'d\' to display current graph or \'q\' to exit.\n"; while (edgeInput != "q") { cout << "\nEdge: "; @@ -64,15 +64,21 @@ int main() { getline(ss, b, '-'); ss.str({}); - try { - relations[stoi(a)].push_back(stoi(b)); + if (edgeInput == "q") break; + else if (edgeInput == "d") { + graph digraph(relations); + cout << "Graph structure is:\n"; + digraph.displayGraph(); + system("pause"); + break; } - catch (...) { - cout << "Invalid entry\n"; + else { + try { + relations[stoi(a)].push_back(stoi(b)); + } + catch (...) { + cout << "Invalid entry\n"; + } } - - - - } } \ No newline at end of file diff --git a/Project12/digraph.h b/Project12/digraph.h index c2c0bdc..5eac55b 100644 --- a/Project12/digraph.h +++ b/Project12/digraph.h @@ -10,18 +10,35 @@ private: int pointNum; vector connectedNodes; - public: - graphNode() { - + graphNode(int id, vector connections) { + pointNum = id; + connectedNodes = connections; } + + graphNode(int id) { + pointNum = id; + } + int getPointNum() { return pointNum; - }; + } + + void setConnectedNodes(vector n) { + connectedNodes = n; + } + vector getConnectedNodes() { return connectedNodes; } + void displayGraphNode() { + cout << pointNum << ": "; + for (auto i = connectedNodes.begin(); i != connectedNodes.end(); i++) { + cout << (*i)->pointNum << " "; + } + cout << endl; + } }; class graph { @@ -29,12 +46,49 @@ private: vector nodesList; public: - void addNewNode(vector n) { + graph(vector>& v) { + for (auto i = v.begin(); i != v.end(); i++) { + vector p = *i; + graphNode tmp(p[0]); + nodesList.push_back(tmp); + } + + for (auto i = v.begin(); i != v.end(); i++) { + addConnections(*i); + } + } + void addConnections(vector& n) { + int num; + vector connects; + + for (auto i = n.begin(); i != n.end(); i++) { + if (i == n.begin()) { + num = *i; + } + else if (*i == num) { + continue; + } + else { + connects.push_back(&nodesList[*i]); + } + } + nodesList[num].setConnectedNodes(connects); } - void removeNode(vector n) { + void addgraphNode(vector& n) { + auto i = nodesList.end(); + int x = i->getPointNum(); + graphNode tmp(x + 1); + + addConnections(n); + } + + void displayGraph() { + for (auto i = nodesList.begin(); i != nodesList.end(); i++) { + (*i).displayGraphNode(); + } } }; diff --git a/Project14/Project14.cpp b/Project14/Project14.cpp new file mode 100644 index 0000000..6ba2211 --- /dev/null +++ b/Project14/Project14.cpp @@ -0,0 +1,54 @@ +// Corey Williams +// COP3530 01Z +// Project 14 + +/* +Write an application in C++ or Java that uses the “Comb Sort” template described in +section 9.1.4, pp. 500-501 to write an application that will sort an array of 50 randomly generated integers. +The application must perform the following. + + Display the unsorted numbers + Display the sorted numbers +*/ + +#include + +using namespace std; + +template +void combsort(T data[], const int n) { + int step = n, j, k; + while ((step = int(step / 1.3)) > 1) // phase 1 + for (j = n - 1; j >= step; j--) { + k = j - step; + if (data[j] < data[k]) + swap(data[j], data[k]); + } + bool again = true; + for (int i = 0; i < n - 1 && again; i++) // phase 2 + for (j = n - 1, again = false; j > i; --j) + if (data[j] < data[j - 1]) { + swap(data[j], data[j - 1]); + again = true; + } +} + +int main() { + int a[50]; + + for (int i = 0; i <= 49; i++) { //step through the array loading with rand integers + a[i] = rand(); + } + + cout << "Unsorted Elements:\n"; //iterate through and print each element of the unsorted array + for (int i = 0; i <= 49; i++) { + cout << a[i] << endl; + } + + combsort(a, 50); + + cout << "\nSorted Elements:\n"; //iterate through and print each element of the sorted array + for (int i = 0; i <= 49; i++) { + cout << a[i] << endl; + } +} \ No newline at end of file diff --git a/Project14/Project14.sln b/Project14/Project14.sln new file mode 100644 index 0000000..81311a9 --- /dev/null +++ b/Project14/Project14.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}") = "Project14", "Project14.vcxproj", "{525680F5-D7E4-46EC-BB9E-A743267FA432}" +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 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Debug|x64.ActiveCfg = Debug|x64 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Debug|x64.Build.0 = Debug|x64 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Debug|x86.ActiveCfg = Debug|Win32 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Debug|x86.Build.0 = Debug|Win32 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Release|x64.ActiveCfg = Release|x64 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Release|x64.Build.0 = Release|x64 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Release|x86.ActiveCfg = Release|Win32 + {525680F5-D7E4-46EC-BB9E-A743267FA432}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4232E4D8-B675-4B30-96C1-D84F1E8BE697} + EndGlobalSection +EndGlobal diff --git a/Project14/Project14.vcxproj b/Project14/Project14.vcxproj new file mode 100644 index 0000000..2d674c7 --- /dev/null +++ b/Project14/Project14.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {525680f5-d7e4-46ec-bb9e-a743267fa432} + Project14 + 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/Project14/Project14.vcxproj.filters b/Project14/Project14.vcxproj.filters new file mode 100644 index 0000000..9b5889c --- /dev/null +++ b/Project14/Project14.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