100 lines
3.6 KiB
C++
100 lines
3.6 KiB
C++
// 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 <iostream>
|
|
#include "genQueue.h"
|
|
#include "circle.h"
|
|
#include <string>
|
|
|
|
void enterQueueElements(Queue<Circle>& 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<Circle> 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<Circle>& 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<Circle> 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";
|
|
}
|
|
}
|
|
}
|
|
|