1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include "header.h"
int main()
{
int choice = 0; //Variable declaration for switch choice.
int route_choice = 0; //Variable for selecting a simulated.
bool exit = false; //Variable declaration for exit condition.
Route to_add; //Setup an instance of the first route.
Queue my_route; //Implement a Queue
Queue my_route2; //Implement second route.
Stack route_back; //Implement a Stack.
Stack route_back2; //Implement second return.
char name[100]; //Variable declaration for route_name
char notes[100]; //Variable declaration for route_notes
char traffic[100]; //Variable declaration for traffic_notes
int length = 0; //Variable declaration for route length.
do{ //Begin do-while loop for switch.
welcome(); //Display welcome message.
menu(); //Display main menu.
cin >> choice; //Prompt user for switch choice.
cin.ignore(100,'\n'); //Clear input buffer.
switch(choice) //Begin switch.
{
default: //Set default condition for invalid choice.
cout << "Invalid choice." << endl;
break;
case 1: //Create a primary route.
do{if(my_route.isFull()) //If the route is full, break.
{cout << "There is no more room." << endl; break;}
if(my_route.isFull()) //If route is full, break.
{
cout << "There is no more room." << endl;
return 0;
}
//Receive input from user. Store into static temporary.
cout << "Enter route name/desc:" << endl;
cin.get(name, 100); cin.ignore(100,'\n');
cout << "Enter route length in miles:" << endl;
cin >> length; cin.ignore(100,'\n');
cout << "Enter typical route traffic:" << endl;
cin.get(traffic, 100); cin.ignore(100,'\n');
cout << "Enter any route notes:" << endl;
cin.get(notes, 100); cin.ignore(100,'\n');
//Fill 'to_add' with data in create_route function.
to_add.create_route(name,notes,traffic,length);
//Enqueue 'to_add', adding it to the end of the queue.
my_route.enQueue(to_add);
//Push 'to_add', adding it to the top of the stack.;
route_back.push(to_add);
}while(again()); //Prompt user to enter another leg of the route.
break;
case 2: //Create a secondary route.
do{if(my_route2.isFull()) //If the route is full, break.
{cout << "There is no more room." << endl; break;}
if(my_route2.isFull()) //If route is full, break.
{
cout << "There is no more room." << endl;
return 0;
}
//Receive input from user. Store into static temporary.
cout << "Enter route name/desc:" << endl;
cin.get(name, 100); cin.ignore(100,'\n');
cout << "Enter route length in miles:" << endl;
cin >> length; cin.ignore(100,'\n');
cout << "Enter typical route traffic:" << endl;
cin.get(traffic, 100); cin.ignore(100,'\n');
cout << "Enter any route notes:" << endl;
cin.get(notes, 100); cin.ignore(100,'\n');
//Fill 'to_add' with data in create_route function.
to_add.create_route(name,notes,traffic,length);
//Enqueue 'to_add', adding it to the end of the queue.
my_route2.enQueue(to_add);
//Push 'to_add', adding it to the top of the stack.;
route_back2.push(to_add);
}while(again()); //Prompt user to enter another leg of the route.
break;
case 3: //Display the primary route.
if(my_route.isEmpty()) //If the route is empty, break.
{cout << "There is no primary route." << endl;break;}
cout << "Displaying the primary route:" << endl;
my_route.display(); //Output the queue.
break;
case 4:
if(my_route2.isEmpty()) //If the route is empty, break.
{cout << "There is no alternate route." << endl;break;}
cout << "Displaying the alternate route:" << endl;
my_route2.display(); //Output the queue.
break;
case 5:
if(route_back.isEmpty()) //if the stack is empty, break.
{cout << "There is no primary return route." << endl;break;}
cout << "\nDisplaying the return route." << endl;
route_back.display(); //Output the stack.
break;
case 0: //If the user enters 0.
exit = true; //Set exit condition true, exiting switch.
break;
} //switch.
}while(!exit); //End do-while checking for exit condition.
//Call destructors.
route_back.~Stack(); //Destroy the first stack.
route_back2.~Stack(); //Destroy the second stack.
my_route.~Queue(); //Destroy the first route.
my_route2.~Queue(); //Destroy the second route.
return 0;
}
//Function to welcome the user to the test program.
void welcome()
{
cout << "=============================================" << endl;
cout << "Welcome the Route Planner Test Program\n" << endl;
}
//Function to outline the test conditions in the program.
void menu()
{
cout << "Select a test condition from the following:" << endl;
cout << "Test 1. Create a primary route." << endl;
cout << "Test 2. Create an alternate route." << endl;
cout << "Test 3. Display primary route." << endl;
cout << "Test 4. Display alternate route." << endl;
cout << "Test 5. Display primary return route." << endl;
cout << "Test 6. Display secondary return route." << endl;
cout << "Test 7. Dequeue a route segment." << endl;
cout << "Test 8. Check first step in return trip." << endl;
cout << "Test 9. Remove first leg of return trip." << endl;
cout << "Test 10. SIMULATE JOURNEY TO AND FROM!" << endl;
cout << "0. Exit test program." << endl;
}
//Function to prompt the user if they want to enter another leg.
bool again()
{
char choice = 0;
cout << "Again? (Y/N) " << endl;
cin >> choice;
cin.ignore(100,'\n');
choice = toupper(choice);
if(choice == 'Y')
{
return 1;
}
else
return 0;
}
|