diff --git a/Project6/Project6.cpp b/Project6/Project6.cpp new file mode 100644 index 0000000..ecb02f2 --- /dev/null +++ b/Project6/Project6.cpp @@ -0,0 +1,100 @@ +// Corey Williams +// COP3530 01Z +// Project 6 + +/* +Create an application that allows user to build a Queue of Circle Elements. +The Queue must be built using a Linked List (i.e., refer to Linked List Implementation, Figure 4.10 pp. 143 - 144 [uses C++ template; Figure 4.13 uses the template]). + +The application must be menu controlled and provide the following. + * Allow insertion of a "Circle" object/structure in the Queue data structures. + * Allow display of all elements from Queue data structure by Invoking a method/function "DisplayQueue" (uses "DeQueue" method). + * Allow for deletion of the Queue +*/ + +using namespace std; + +#include +#include "genQueue.h" +#include "circle.h" +#include + +void enterQueueElements(Queue& q) { //queue is passed in by reference in order to remain persistent between main and function calls + system("cls"); + string r = "0"; //Takes string so that user input can be processed regardless of validity + + //Greeting/instruction text + cout << "1. Enter Queue Elements" << endl; + cout << "=======================" << endl; + cout << "Input a positive number to add a circle with that radius to the queue" + << endl << "or enter q to exit back to the main menu" << endl << endl; + + //Loops until exit condition is input by user + while (r != "q") { + cout << "Input: "; + cin >> r; + + if (r == "q" or r == "Q") { return; } + else { + try { //try block encapsulates attempt to cast string to double + Circle tmp(stod(r)); //instantiates circle with user-input radius + q.enqueue(tmp); //adds circle to queue + cout << "Circle of radius " << r << " added to queue." << endl; + } + catch (...) { //catches when user input is not able to be used as a numeric input + cout << "Not a valid entry, please try again. "; + continue; + } + } + } +} + +void displayQueueElements(Queue q) { //receives a copy of the queue from main so that elements can be dequeued for output while leaving the original queue intact + cout << endl << "Elements:" << endl << endl; + if (q.isEmpty()) { cout << "There are no elements in queue. "; } + while (!q.isEmpty()) { + Circle tmp = q.dequeue(); + cout << "Radius: " << tmp.getRadius() << endl; + cout << "Area: " << tmp.calculateArea() << endl << endl; + } + system("pause"); +} + +void deleteCurrentQueue(Queue& q) { //receives reference to main function's queue and deletes all elements + q.clear(); + cout << endl << endl; + cout << "The queue has been cleared. "; + system("pause"); +} + +int main() +{ + Queue cirQueue; + string menuChoice = "0"; + + //Main Menu - reads string from user and parses for menu selection + //Loops until exit condition is input by user + while (menuChoice != "4") { + menuChoice = "0"; + system("cls"); + + cout << "Main Menu" << endl + << "1. Enter Queue Elements" << endl + << "2. Display Queue Elements" << endl + << "3. Delete Current Queue" << endl + << "4. Exit Program" << endl + << endl << "Choose an option (1-4): "; + cin >> menuChoice; + + if (menuChoice == "1") { enterQueueElements(cirQueue); } + else if (menuChoice == "2") { displayQueueElements(cirQueue); } + else if (menuChoice == "3") { deleteCurrentQueue(cirQueue); } + else if (menuChoice == "4") { return 0; } + else { + cout << endl << "Not a valid entry, please try again. "; + system("pause"); + menuChoice = "0"; + } + } +} + diff --git a/Project6/Project6.sln b/Project6/Project6.sln new file mode 100644 index 0000000..e18c12e --- /dev/null +++ b/Project6/Project6.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}") = "Project6", "Project6.vcxproj", "{8F096234-3F16-4D9F-BB3B-322280A0FBF5}" +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 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Debug|x64.ActiveCfg = Debug|x64 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Debug|x64.Build.0 = Debug|x64 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Debug|x86.ActiveCfg = Debug|Win32 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Debug|x86.Build.0 = Debug|Win32 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Release|x64.ActiveCfg = Release|x64 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Release|x64.Build.0 = Release|x64 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Release|x86.ActiveCfg = Release|Win32 + {8F096234-3F16-4D9F-BB3B-322280A0FBF5}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9E0C321B-244B-4BD3-AC84-2D013DFC75CF} + EndGlobalSection +EndGlobal diff --git a/Project6/Project6.vcxproj b/Project6/Project6.vcxproj new file mode 100644 index 0000000..5a1fdb9 --- /dev/null +++ b/Project6/Project6.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {8f096234-3f16-4d9f-bb3b-322280a0fbf5} + Project6 + 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/Project6/Project6.vcxproj.filters b/Project6/Project6.vcxproj.filters new file mode 100644 index 0000000..5d6ee08 --- /dev/null +++ b/Project6/Project6.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {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 + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Project6/circle.h b/Project6/circle.h new file mode 100644 index 0000000..723635b --- /dev/null +++ b/Project6/circle.h @@ -0,0 +1,34 @@ +#ifndef CIRCLE_HEADER +#define CIRCLE_HEADER + +#define _USE_MATH_DEFINES + +#include + +class Circle { +private: + double radius; + +public: + Circle() { + radius = 0; + } + + Circle(double r) { + radius = r; + } + + double getRadius() { + return radius; + } + + void setRadius(double r) { + radius = r; + } + + double calculateArea() { + return M_PI * radius * radius; + } +}; + +#endif \ No newline at end of file diff --git a/Project6/genQueue.h b/Project6/genQueue.h new file mode 100644 index 0000000..df74529 --- /dev/null +++ b/Project6/genQueue.h @@ -0,0 +1,35 @@ +//********************** genQueue.h ************************* +// generic queue implemented with doubly linked list + +#ifndef DLL_QUEUE +#define DLL_QUEUE + +#include + +template +class Queue { +public: + Queue() { + } + void clear() { + lst.clear(); + } + bool isEmpty() const { + return lst.empty(); + } + T& front() { + return lst.front(); + } + T dequeue() { + T el = lst.front(); + lst.pop_front(); + return el; + } + void enqueue(const T& el) { + lst.push_back(el); + } +private: + list lst; +}; + +#endif diff --git a/Project7/Project7.cpp b/Project7/Project7.cpp new file mode 100644 index 0000000..732b135 --- /dev/null +++ b/Project7/Project7.cpp @@ -0,0 +1,110 @@ +//Corey Williams +//COP3530 01Z +//Project 7 + +/* +Write a C / C++ or Java application that creates a Stack data structure. +The Stack must be built using a Linked List(i.e., refer to Linked List Implementation, Figure 4.5 pp. 137 - 138). +The application also creates a "DisplayStackElement" routine. +The application must be menu driven(with an option to terminate the application) and provide the following features. + - Allow insertion of a "Circle" object / structure in the Stack data structures.The Circle contains a "radius" data member. + The Circle also uses functions / methods "setRadius", "getRadius" and calculateArea(returns a double data type). + - Allow display of an element from Stack data structure by Invoking a method / function "DisplayStackElement" (uses the "Pop" method) + - Allow for deletion of the Stack +*/ + +using namespace std; + +#include +#include "genListStack.h" +#include "circle3.h" +#include + +void displayStackElements() { + +} + +void enterStackElements(LLStack& s) { //stack is passed in by reference in order to remain persistent between main and function calls + system("cls"); + string r = "0"; //Takes string so that user input can be processed regardless of validity + + //Greeting/instruction text + cout << "1. Enter Stack Elements" << endl; + cout << "=======================" << endl; + cout << "Input a positive number to add a circle with that radius to the stack" + << endl << "or enter q to exit back to the main menu" << endl << endl; + + //Loops until exit condition is input by user + while (r != "q") { + cout << "Input: "; + cin >> r; + + if (r == "q" or r == "Q") { return; } + else { + try { //try block encapsulates attempt to cast string to double + Circle tmp(stod(r)); //instantiates circle with user-input radius + s.push(tmp); //adds circle to stack + cout << "Circle of radius " << r << " pushed to stack." << endl; + } + catch (...) { //catches when user input is not able to be used as a numeric input + cout << "Not a valid entry, please try again. "; + continue; + } + } + } +} + +void displayStackElement(LLStack& s) { //pops the top element and prints to screen + cout << endl << "Elements:" << endl; + if (s.isEmpty()) { cout << endl << "There are no elements to display. "; system("pause"); } + string control = "y"; + while (!s.isEmpty() and control!="n" and control !="N") { + Circle tmp = s.pop(); + cout << endl << "Radius: " << tmp.getRadius(); + cout << endl << "Area: " << tmp.calculateArea() << endl << endl; + + cout << "Display another element? y/n: "; + cin >> control; + + if (s.isEmpty()) { cout << endl << "There are no more elements. "; system("pause"); } + } +} + +void deleteCurrentStack(LLStack& s) { //receives reference to main function's queue and deletes all elements + s.clear(); + cout << endl << endl; + cout << "The stack has been cleared. "; + system("pause"); +} + +int main() +{ + LLStack cirStack; + string menuChoice = "0"; + + //Main Menu - reads string from user and parses for menu selection + //Loops until exit condition is input by user + while (menuChoice != "4") { + menuChoice = "0"; + system("cls"); + + cout << "Main Menu" << endl + << "=========" << endl + << "1. Enter Stack Elements" << endl + << "2. Display Top Element" << endl + << "3. Delete Current Stack" << endl + << "4. Exit Program" << endl + << endl << "Choose an option (1-4): "; + cin >> menuChoice; + + if (menuChoice == "1") { enterStackElements(cirStack); } + else if (menuChoice == "2") { displayStackElement(cirStack); } + else if (menuChoice == "3") { deleteCurrentStack(cirStack); } + else if (menuChoice == "4") { return 0; } + else { + cout << endl << "Not a valid entry, please try again. "; + system("pause"); + menuChoice = "0"; + } + } +} \ No newline at end of file diff --git a/Project7/Project7.sln b/Project7/Project7.sln new file mode 100644 index 0000000..27088b2 --- /dev/null +++ b/Project7/Project7.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}") = "Project7", "Project7.vcxproj", "{38E2962A-AB1A-427A-B095-36C8970694F0}" +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 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Debug|x64.ActiveCfg = Debug|x64 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Debug|x64.Build.0 = Debug|x64 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Debug|x86.ActiveCfg = Debug|Win32 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Debug|x86.Build.0 = Debug|Win32 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Release|x64.ActiveCfg = Release|x64 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Release|x64.Build.0 = Release|x64 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Release|x86.ActiveCfg = Release|Win32 + {38E2962A-AB1A-427A-B095-36C8970694F0}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B8C6B9B4-A05D-449C-9C0C-4A77EA20A30B} + EndGlobalSection +EndGlobal diff --git a/Project7/Project7.vcxproj b/Project7/Project7.vcxproj new file mode 100644 index 0000000..422f78b --- /dev/null +++ b/Project7/Project7.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {38e2962a-ab1a-427a-b095-36c8970694f0} + Project7 + 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/Project7/Project7.vcxproj.filters b/Project7/Project7.vcxproj.filters new file mode 100644 index 0000000..d792067 --- /dev/null +++ b/Project7/Project7.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {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 + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Project7/circle3.h b/Project7/circle3.h new file mode 100644 index 0000000..723635b --- /dev/null +++ b/Project7/circle3.h @@ -0,0 +1,34 @@ +#ifndef CIRCLE_HEADER +#define CIRCLE_HEADER + +#define _USE_MATH_DEFINES + +#include + +class Circle { +private: + double radius; + +public: + Circle() { + radius = 0; + } + + Circle(double r) { + radius = r; + } + + double getRadius() { + return radius; + } + + void setRadius(double r) { + radius = r; + } + + double calculateArea() { + return M_PI * radius * radius; + } +}; + +#endif \ No newline at end of file diff --git a/Project7/genListStack.h b/Project7/genListStack.h new file mode 100644 index 0000000..3999478 --- /dev/null +++ b/Project7/genListStack.h @@ -0,0 +1,35 @@ +//********************** genListStack.h ************************* +// generic stack defined as a doubly linked list + +#ifndef LL_STACK +#define LL_STACK + +#include + +template +class LLStack { +public: + LLStack() { + } + void clear() { + lst.clear(); + } + bool isEmpty() const { + return lst.empty(); + } + T& topEl() { + return lst.back(); + } + T pop() { + T el = lst.back(); + lst.pop_back(); + return el; + } + void push(const T& el) { + lst.push_back(el); + } +private: + list lst; +}; + +#endif