I am having a couple issues with the following code. Any help with understanding what I am doing wrong is worth its weight in gold rather than handing me the answer. My problem with the following code is I can Add a Flight to the database but it seems to infinite loop as soon as I hit the sentinel. Does anyone see something there that is causing this? And, if there is any input on how to improve this code its appreciated as well.
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <assert.h>
#include <iterator.h>
#include <list.h>
template <typename NodeValueType>
ostream & operator<<(ostream & out, /*const*/ list <NodeValueType> & l)
{
if (l.empty())
out << "list is empty" << endl;
else
for (typename list<NodeValueType>::iterator j=l.begin(); j!=l.end(); j++)
//"typename" declares what follows it to be interpreted as a type.
out << *j << " ";
out << "end of list" << endl;
return out; //return the "left" operand so can chain "<<" operations together.
}
struct FlightType{
int FlightNum;
int FlightCap;
};
ostream& operator<< (ostream& outstream, FlightType const &flight)
{
outstream<<"Flight Number is:"<< flight.FlightNum<<".";
outstream<<"Flight Capacity is:"<< flight.FlightCap<<endl;
return outstream;
}
int main(void)
{
list<FlightType> flightList;
int option;
do
{
cout<<"Please choose your menu options/n"<<endl;
cout<<"Choose 1 to add flight/n"<<endl;
cout<<"Choose 2 to print flight/n"<<endl;
cout<<"Choose 3 to delete flight/n"<<endl;
cout<<"Choose 4 to exit/n"<<endl;
cin>>option;
switch(option)
{
case 1:
for(;;)
{
int FlightNum, FlightCap;
cout << "Enter Flight Number"; cin >> FlightNum;
cout << "Enter Flight Capacity"; cin >> FlightCap;
if(FlightNum==-1000)break;
FlightType flight;
flight.FlightNum = FlightNum;
flight.FlightCap = FlightCap;
cout << "You just entered: " <<flight<< endl;
flightList.push_front(flight);
}
case 2:
cout<<"/n The flights you just entered are:/n";
while(flightList.begin()!= flightList.end())
{
cout<<"The printed flight num is"<<*flightList.begin();
}
cout << "push Enter to quit\n"; cin.get(); cin.get();
case 3:
for(;;)
{
int FlightNum;
cin>>FlightNum;
if(FlightNum==-1000)break;
flightList.remove();
cout << "Removed Flight from Database";
}
case 4:
{
return 0;
}
}
}while(option!=4);
}