1 /* Roy Keene 2 CS 2314 3 Section 04 4 Lab 04 5 17 Sept 02 6 queue.h 7 8 Fully tested configurations: 9 *MSVC++ 6.0 i386 Windows XP 10 Sun Workshop 6.0 sun4u Solaris 11 Intel 6.0 i386 Linux 12 g++ 3.0.3 sun4u Solaris 13 g++ 3.0.2 ip27 IRIX 14 g++ 2.95.4 i386 FreeBSD 15 g++ 2.95.4 alpha Linux 16 g++ 2.95.4 sun4u Linux 17 g++ 2.95.4 powerpc Linux 18 g++ 2.95.4 armv4l Linux 19 g++ 2.96 i386 Linux 20 g++ 2.95.3 i386 Linux 21 g++ 2.95.3 sun4u Solaris 22 c++ 2.95.2 powerpc MacOS X 23 g++ 2.95.2 i386 Linux 24 g++ 2.8.1 sun4u Solaris 25 */ 26 27 #include <iostream> 28 #include <string> 29 30 using namespace std; 31 #include "queue.h" 32 33 char Menu(void) { 34 string userinput; 35 int x; 36 37 while (1) { 38 cout << " MENU\n"; 39 cout << " number | description\n"; 40 cout << " 1 | Check out a movie\n"; 41 cout << " 2 | Return a movie\n"; 42 cout << " 3 | View movie status\n"; 43 cout << " 4 | Exit\n"; 44 cout << "Choice> "; 45 cout.flush(); 46 cin >> userinput; 47 x=userinput[0]-'0'; 48 if (x<1 || x>4) { 49 cout << "Invalid choice.\n"; 50 } else { 51 break; 52 } 53 } 54 return(x); 55 } 56 57 int main(void) { 58 QueType<string> MovieQueue; 59 char MovieName[1024]; 60 char choice; 61 int MovieCount=0, i; 62 63 while (1) { 64 choice=Menu(); 65 switch (choice) { 66 case 1: 67 cout << "Enter the movie title> "; 68 cout.flush(); 69 cin.ignore(); 70 cin.getline(MovieName, sizeof(MovieName), '\n'); 71 MovieQueue.Enqueue(MovieName); 72 if (MovieCount<3) { 73 cout << "You have checked out \"" << MovieName << "\", it is being sent immediately.\n"; 74 } else { 75 cout << "You already have 3 movies checked out, as soon as one is returned \"" << MovieName << "\", will be sent.\n"; 76 } 77 MovieCount++; 78 break; 79 case 2: 80 if (MovieCount==0) { 81 cout << "You have no movies checked out!\n"; 82 break; 83 } 84 MovieCount--; 85 cout << "You have returned \"" << MovieQueue.Front() << "\"\n"; 86 MovieQueue.Dequeue(); 87 break; 88 case 3: 89 if (MovieCount==0) { 90 cout << "You have no movies checked out!\n"; 91 break; 92 } 93 MovieQueue.Next(1); 94 cout << "Currently checked out movies:\n"; 95 for (i=0;i<( (MovieCount<3)?MovieCount:3 );i++) { 96 cout << " \"" << MovieQueue.Next(0) << "\"\n"; 97 } 98 if (MovieCount>3) { 99 cout << "Next movie to be sent:\n"; 100 cout << " \"" << MovieQueue.Next(0) << "\"\n"; 101 } 102 break; 103 case 4: 104 return(0); 105 break; 106 } 107 } 108 return(0); 109 } |