I am trying to make the following work (firs the .h file followed by the problem):
The .h file:
The problem:Code:#ifndef MYLIST_H #define MYLIST_H struct Air { string person; Air *next; }; class JGOp { public: JGOp();// Constructor //~JGOp();//Destructor void InsertPassenger(); // Enters a passenger name. private: int size; //static const int MAXsize = 20; Air *head; //string person; string input; }; #endif
Main:Code:#include <iostream> #include <cstdlib> #include <string> #include <iomanip> #include <fstream> using namespace std; using std::ostream; #include "MyList.h" JGOp::JGOp() { size = 0; head = NULL; } void JGOp::InsertPassenger() { Air *ptr = new Air; cout << "Enter passenger: "; cin >> input; Add(input); } void JGOp::Add(string input) { Air *current = new Air; Air *ptr = new Air; Air *previous = new Air; ptr->person = input; if (head == NULL) { head = ptr->next; } current = head; previous = head; if(ptr->person < current->person) { current = previous->next; while (current != NULL && previous != NULL) { if(ptr->person < current->person) { ptr->next = current; previous->next = ptr; } current = current->next; previous = previous->next; } } else; current = head; previous = head; current = previous->next; while(current != NULL) { current = current->next; previous = previous->next; } previous->next = ptr; }
The point of this program is the following:Code:#include <iostream> #include <string> using namespace std; #include "MyList.h" int main() { JGOp JG; int choice, End; End = 1; while (End != 0) { cout << "Welcome to JetGreen Airlines, the Number #1 choice for" << endl; cout << "quality travel for Spring Break.\n"<< endl; cout << "Press 1 to reserve a flight on one of our luxurious aircrafts." << endl; cout << "Press 9 to exit our system." << endl << endl; cout << "What would you like to do?: "; cin >> choice; cout << "\n"; switch (choice) { case 1: JG.InsertPassenger(); /* Asks the user for passenger name and flight. It then adds the passenger to the appropriate flight.*/ break; break; case 9: cout << "Thank you for choosing Jet Green!" << endl << endl ; End = 0; } } return 0; }
When the program loads, I want to put in a name, and have that name be saved to a string, which I can later print. The code complies, but once I run it, enter a passenger name, and press enter, I get an error. Can someone tell me what I am doing wrong here?




Reply With Quote