// // Printer Queue // #include #include using namespace std ; // My Include Files #include "Priority.h" #include "Time.h" #include "PrintJob.h" #include "PrinterQueue.h" // Function Prototypes char GetMenuChoice(void) ; void AddPrintJob(PrinterQueue &) ; void PrintNextJob(PrinterQueue &) ; void PrintQueue(PrinterQueue &) ; void NextToPrint(PrinterQueue &) ; void PrintQueueWithCopyConstructor(PrinterQueue) ; void NextToPrintWithCopyConstructor(PrinterQueue) ; int main(int argc, char * argv[]){ PrinterQueue pq ; char menuChoice = GetMenuChoice() ; while(menuChoice != 'X') { if(menuChoice == '1') AddPrintJob(pq) ; else if(menuChoice == '2') PrintNextJob(pq) ; else if(menuChoice == '3') NextToPrint(pq) ; else if(menuChoice == '4') PrintQueue(pq) ; else if(menuChoice == '5') NextToPrintWithCopyConstructor(pq) ; // copy construtor called else if(menuChoice == '6') PrintQueueWithCopyConstructor(pq) ; // copy constructor called else cout << "Invalid Menu Choice." << endl ; menuChoice = GetMenuChoice() ; } cout << "Goodbye!" << endl ; return 0 ; } // Function Definitions // Pre - None // Post - Displays the Menu & Gets the user's choice & Returns it char GetMenuChoice(void) { char menuChoice[500] ; do { cout << "--------------------" << endl ; cout << "Homework 3 MAIN MENU" << endl ; cout << "--------------------" << endl ; cout << "1 - Send File to Printer Queue" << endl ; cout << "2 - Print Next File" << endl ; cout << "3 - Preview Next File" << endl ; cout << "4 - Show Current Queue Contents" << endl ; cout << "5 - Preview Next File (w/ copy constructor)" << endl ; cout << "6 - Show Current Queue Contents (w/ copy constructor)" << endl ; cout << "X - EXIT PROGRAM" << endl ; cout << "--------------------" << endl ; cout << "Choose an Option (hit enter): " ; cin.getline(menuChoice, 499) ; }while(strlen(menuChoice) != 1) ; return toupper(menuChoice[0]) ; } // Pre - printer queue exists // Post - asks users for and adds new print job void AddPrintJob(PrinterQueue & pq) { // Add a Print Job string File ; char PrintTime[10] ; string NewPrintTime ; int NewPriority ; do{ cout << "File Name (ex: test.txt) : " ; cin >> File ; }while(File.find(".", 0) == string::npos || File.find(".", 0) != File.length()-4 || File.length() < 5) ; cin.get() ; do{ cout << "Print Time (ex: 3:07 PM): " ; cin.getline(PrintTime, 10) ; NewPrintTime = PrintTime ; }while(NewPrintTime.length() < 7 || NewPrintTime.length() > 8 || NewPrintTime.find(":", 0) == string::npos) ; do{ cout << "Priority? (0-LOW,1-MEDIUM,2-HIGH): " ; cin >> NewPriority ; }while(NewPriority != 0 && NewPriority != 1 && NewPriority != 2) ; cin.get() ; PrintJob job(File.substr(0, File.find(".")), File.substr(File.find(".") +1) , NewPrintTime, NewPriority ) ; if(pq.Enqueue(job) == true) { cout << "Job Added Successfully!" << endl ; } else { cout << "Unable to insert job!" << endl ; } } // Pre - printer queue exists // Post - prints / removes print job from queue void PrintNextJob(PrinterQueue & pq) { // Print a Job PrintJob job ; if(pq.Dequeue(job) == true) { cout << "Job Printed: " << job << endl ; } else { cout << "No Jobs to Print!" << endl ; } } // Pre - printer queue exists // Post - prints out entire printer queue void PrintQueue(PrinterQueue & pq) { // Print the Queue cout << "--------------------" << endl ; cout << "Current Queue contents:" << endl ; cout << "--------------------" << endl ; cout << pq << endl ; } // Pre - printer queue exits // Post - prints out next print job that's ready void NextToPrint(PrinterQueue & pq) { // Preview Next Job to print PrintJob job ; if(pq.NextToPrint(job) == true) { cout << "Next Job to Print: " << job << endl ; } else { cout << "No Jobs to Print!" << endl ; } } // Pre - printer queue exists // Post - prints out entire printer queue void PrintQueueWithCopyConstructor(PrinterQueue pq) { // Print the Queue cout << "--------------------" << endl ; cout << "Current Queue contents:" << endl ; cout << "--------------------" << endl ; cout << pq << endl ; } // Pre - printer queue exits // Post - prints out next print job that's ready void NextToPrintWithCopyConstructor(PrinterQueue pq) { // Preview Next Job to print PrintJob job ; if(pq.NextToPrint(job) == true) { cout << "Next Job to Print: " << job << endl ; } else { cout << "No Jobs to Print!" << endl ; } }