Colossusx10
n00b
- Joined
- May 19, 2007
- Messages
- 8
First of all I want to say I AM NOT ASKING FOR ANYONE TO WRITE THIS FOR ME. I will provide as much detail as possible, because this program is complicated.
I have a program I need write. I have to create a program for an airline called Jet Green or JG for short (it's actually a college assignment). This program has the following requirements: The names of the passengers are to be stored in a linked list and in alphabetical order. All of JG airplanes have 20 seats with two seats per row. Seats are numbered 0-19 (so seats 0 & 1 are together, 2 & 3 are together, etc.) Passengers are not assigned seats when they register for a flight. Seats are assigned later in the process. Passengers may travel together in pairs. This information is stored and when seats are assigned, passengers traveling together are assigned adjacent seats (HINT: you must design your data structure to store this information). Flights may also get cancelled, and in this case passengers from one flight are put on another flight (the passenger lists are merged).
It has the following functions:
1. Register a passenger for a flight -- This routine will prompt the user for a passenger name.
2. Delete a passenger from a flight -- This routine will delete a passenger from the flight roster.
3. Print a flight manifest This routine will print the names of the passenger on the flight. YOU MUST USE THE OVERLOADED >> operator.
4. Find a passenger Find a passenger on a flight. This routine should return a true if the passenger is on the flight, false otherwise. In Option 2, this should return the flight the passenger is on as well.
5. Register passengers flying together Input the names of passengers flying together. Assume at most 2 passengers may be flying together.
6. Merge two flights (append the passengers from one flight to another). This is to be done as a regular function for Option I, or as a member function for Option II.
7. Seat all passengers for flights Assign seat numbers to all passengers. Make sure to keep passengers who are traveling together in adjacent seats.
8. Read a set of passengers from a file
9. Exit Program
So far, I almost completed 1-4, but am having a lot of trouble with 5-8. Here is the code I have now, i think it is correct:
-------------------------------------------------------------------------
Header file:
-------------------------------------------------------------------------
First cpp file (the Add function works):
------------------------------------------------------------------------------
File with main in it:
---------------------------------------------------------------------------------------
Please help! I really am having a hard time figuring out how to do finish. Any help would be greatly appreciated!
I have a program I need write. I have to create a program for an airline called Jet Green or JG for short (it's actually a college assignment). This program has the following requirements: The names of the passengers are to be stored in a linked list and in alphabetical order. All of JG airplanes have 20 seats with two seats per row. Seats are numbered 0-19 (so seats 0 & 1 are together, 2 & 3 are together, etc.) Passengers are not assigned seats when they register for a flight. Seats are assigned later in the process. Passengers may travel together in pairs. This information is stored and when seats are assigned, passengers traveling together are assigned adjacent seats (HINT: you must design your data structure to store this information). Flights may also get cancelled, and in this case passengers from one flight are put on another flight (the passenger lists are merged).
It has the following functions:
1. Register a passenger for a flight -- This routine will prompt the user for a passenger name.
2. Delete a passenger from a flight -- This routine will delete a passenger from the flight roster.
3. Print a flight manifest This routine will print the names of the passenger on the flight. YOU MUST USE THE OVERLOADED >> operator.
4. Find a passenger Find a passenger on a flight. This routine should return a true if the passenger is on the flight, false otherwise. In Option 2, this should return the flight the passenger is on as well.
5. Register passengers flying together Input the names of passengers flying together. Assume at most 2 passengers may be flying together.
6. Merge two flights (append the passengers from one flight to another). This is to be done as a regular function for Option I, or as a member function for Option II.
7. Seat all passengers for flights Assign seat numbers to all passengers. Make sure to keep passengers who are traveling together in adjacent seats.
8. Read a set of passengers from a file
9. Exit Program
So far, I almost completed 1-4, but am having a lot of trouble with 5-8. Here is the code I have now, i think it is correct:
-------------------------------------------------------------------------
Header file:
Code:
#ifndef MYLIST_H
#define MYLIST_H
struct Air
{
string person;
Air *next;
};
class JGOp
{
public:
JGOp();// Constructor
void InsertPassenger(); // Enters a passenger name.
void Together(); //Registers passengers flying together.
void FlightandSeat(); //Prints flight and seat number of a passenger.
void Delete(); //Deletes a passenger from the flight roster.
void Find(); //Finds a passenger on a flight.
void Seat(); //Assigns seat numbers to all passengers.
void ReadFile(); //Reads a set of passengers from a file.
void Merge(); //Merges two flights.
void Add( string );
void Print();
friend ostream &operator<<(ostream &,Air &);
private:
int size;
Air *head;
string input;
};
#endif
First cpp file (the Add function works):
Code:
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
using std::ostream;
#include "MyList.h"
JGOp::JGOp()//Constructor
{
size = 0;
head = NULL;
}//JGOp
void JGOp::InsertPassenger()
{
//Check Add function
Air *ptr = new Air;
cout << "Enter passenger: ";
cin >> input;
Add(input);
}
void JGOp::Print()
{
Air *current = new Air;
for(current = head; current != NULL; current = current->next)
{
cout << current->person;
}
}
void JGOp::Together()
{
}//Together
/*ostream &operator<<(ostream &out, Air &getpass)
{
Air *current = new Air;
for(current = getpass.head; current != NULL; current = current->next)
{
out << current->person <<endl;
}
return out;
}*/
void JGOp::FlightandSeat()
{
}
void JGOp::Delete()
{
Air *previous;
Air *current;
string input;
cout << "Select person to delete: ";
cin >> input;
current = new Air;
current = head;
previous = new Air;
previous = head;
current = previous->next;
while(current->person != input)
{
current = current->next;
previous = previous->next;
}
current->next=NULL;
previous->next = current->next;
delete current;
}//Deletepassenger
void JGOp::Seat()
{
/*Air *current = new Air;
current = head;
Snumber = 0;
for (Air *current = head; current != NULL; current = current->next)
{
current->seat = 0;
}
for (int x = 0; x < 20; x++)
{
while (current!=NULL)
{
if (a[x] !="NULL" && a[x] == current->passenger)
{
current->seat = Snumber++;
break;
}
current = current->next;
}
current = head;
}
current = head;
while (current !=NULL)
{
if (current->seat == 0)
{
current->seat = Snumber++;
}
current = current->next;
}
cout << "passenger seating complete. All passenger are now seated." << endl;
current = head;
while (current !=NULL)
{
cout << current->passenger << "." << current->seat << endl;
current = current->next;
}*/
}
void JGOp::ReadFile()
{
Air *current = new Air;
//current = head;
string name;
ifstream myfile ("SampleInput.txt");
while (!myfile.eof())
{
getline (myfile,name);
InsertPassenger();
}
myfile.close();
cout << "Cannot locate file!";
}
void JGOp::Add(string input)
{
Air *current = new Air;
Air *ptr = new Air;
Air *previous = new Air;
ptr->person = input;
Air *next = new Air;
if (head == NULL)
{
head = ptr;
}
else
{
current = head;
previous = head;
if(ptr->person < current->person)
{
current = previous->next;
while (current != NULL && previous != NULL)
{
if(ptr->person < head->person)
{
ptr->next = head;
head= ptr;
}
else
{
previous=head;
current=previous->next;
while (current!=NULL && current->person < ptr->person)
{
previous=current;
current=current->next;
}
ptr->next=current;
previous->next=ptr;
}//end else
}//end while
}//end if
}//end else
}//Add
void JGOp::Find()
{
Air *current = new Air;
string input;
cout << "Enter a passenger to find: ";
cin >> input;
while(current != NULL)
{
while(current->person != input)
{
current = current->next;
}
}
cout << current->person;
}
File with main in it:
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 2 to reassign your seat next to a companion traveler." << endl;
cout << "Press 3 to print the flight manifest." << endl;
cout << "Press 4 to find out your flight number and seat assignment." << endl;
cout << "Press 5 to delete a passenger from a flight." << endl;
cout << "Press 6 to merge two flights." << endl;
cout << "Press 7 to seat all passengers for flights." << endl;
cout << "Press 8 to read a set of passengers from a file." << 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;
case 2:
JG.Together();
/* Asks the user for flight and names of the passengers going together,
then gives them adjacent seat numbers.*/
break;
case 3:
JG.Print();
//cout << JG;
/* Prints a list of passengers for a certain flight. Asks for the flight number
to print out.*/
break;
case 4:
JG.FlightandSeat();
/* Asks the user for a passenger's name, then searches for that
passenger, and prints out their flight and seat number.*/
break;
case 5:
JG.Delete();
/*Asks the user for a flight number, then a passenger name
to delete from that flight.*/
break;
case 6:
//JG.Merge();
/*Merges two flights together.*/
break;
case 7:
JG.Seat();
/*Assigns seat numbers to all passengers, making sure to keep passengers who
are traveling together in adjacent seats.*/
break;
case 8:
JG.ReadFile();
/*Reads a set of passengers from a file*/
break;
case 9:
cout << "Thank you for choosing Jet Green!" << endl << endl ;
End = 0;
}
}
return 0;
}
Please help! I really am having a hard time figuring out how to do finish. Any help would be greatly appreciated!