C++ Array,Pointer,Dynamic

Hi,
I am working on a project that requires a dynamic array and I am not sure how to create this array. I have created the whole project skeleton and works okay, but now I need to add the array.

If you look under the rules. There is always a list to be printed containing "Plane name, Name of Party and Number of people in the party".

Please look the "bold" text on each of the rules. As far I understand, this list must be kept with all records entered;so , I can print from it when one of the rules is true. Once one of the planes "fly", the records for that plane should be deleted from the array/table.

Again, I got the program running, but it's not keeping the record of parties names and how many in the party to be displayed when one of the rules is true.



Here is the text of the project;
--------------------------------
Your employer has determined a market for a simple airline ticketing system for a very simple airline. The airline only has two aircraft, named ALFA and BRAVO. Initially, the ticket system will determine the number of seats on each plane and in the lounge. The ticketing system is to be installed at the airport ticket booth for the airline and will operate under the following rules:
.
1) If a party arrives and there is enough room on the plane requested, they are allowed to board and a message to that effect is printed.
.
2) If a party arrives and there is not enough room on the plane requested due to people already being on the plane, the party is directed to wait in the lounge and a message to that effect is printed.
.

3) If a party arrives and there is not enough room on the plane requested because the plane is just too small, the party is turned away and a message to that effect is printed.
.

4) If a party is directed to the lounge and there is not enough room in the lounge, the party is turned away.
.
5) Parties are never split.
.
6) A plane will fly whenever it becomes full and a list of all parties on board will be printed.
.
7) A plane may fly upon a command from the ticket clerk. Again a list of all parties on board will be printed.

8) The ticket clerk will enter when a plane flys and upon the return of the plane the system will move people from the lounge to the plane in the order in which the parties arrived, but will skip parties that cannot fit and search for those which can fit. A list of those parties boarding the plane will be printed.
.
9) When the airline shuts down for the night, the airplanes will continue to fly and return (without the ticket clerk performing any action) until all parties in the lounge have flown with appropriate messages being printed.
.
10) Party names do not have a maximum size.

I have asked the professor more about it and he wrote me back saying:
====================================================================
You can dynamically create a one dimensional array of structures. In database terms, a table consisting of multiple records,
each record having multiple fields. You only have one entry per party but part of that structure (a field of the record) contains
the number of people in the party. You need to keep track of how many parties are on the plane so you know which slot is empty for
the next party. The number of seats is another piece of information you keep track of and update by the number of seats used (people in) the party.

Here are the structures in the program:
======================================

#ifndef PLANE_H
#define PLANE_H

#include "Party.h"

struct Plane
{
long MaxNumSeats;
long NumSeatsAvailable;
long HowManyParties;
Party * Who;
};

#endif

. . . . . . . . . . . . .

#ifndef PARTY_H
#define PARTY_H

enum Planes {Alfa, Bravo, Invalid};

struct Party
{
char * pName;
long HowMany;
Planes WhichPlane;
};

#endif


Thanks in advance,
easo.

Last edited on
Your question must be short and specific. Like "how can I ...?"
We're here to share knowledge not solve your assignment for you.

You allocate memory dynamically by using a pointer and the new[] and delete[] operators so:
1
2
3
4
5
SomeType *p;

p = new SomeType[30]; // p now acts as an array of 30 SomeType objects

delete[] p; // after you're done, release the memory 

Catfish,

Sorry... I did not mean to ask to resolve my project, but thanks for your reply.

I just wanted to ask how to create the array/table based on my structures, but I will work my array/table based in your example. I will let you know...

Thanks,
easo.
Catfish,

I have created

PlaneAlfa.Who = new Party [Number];
PlaneBravo.Who = new Party [Number];
PlaneLounge.Who = new Party [Number];

The "Number is entered as part of the initalization......

Below I am initializating Alfa....

case ALFA:
if (AlfaInitialized == false)
{
//cout << "ALFAInitialized-1 :" << AlfaInitialized << endl;
cout << "Enter number of ALFA seats: ";
Number = ReadInteger (); // number entered will define maxseat, seatavailable

InAlfaMaxNumSeats = Number;

PlaneAlfa.MaxNumSeats = Number;
PlaneAlfa.NumSeatsAvailable = Number;
PlaneAlfa.Who = new Party [Number];
//cout << "PlaneAlfa.Who " << PlaneAlfa.Who << endl;
PlaneAlfa.HowManyParties = 0;
AlfaInitialized = true;

break;

======================

Then trying to load information for Alfa plane....below....

case Alfa:
TempParty.WhichPlane = Alfa;
//------------------------------
cout << " " << endl;
cout << "Enter NAME of Party: ";
TempParty.pName = ReadChars ();
cout << " " << endl;
//------------------------------

cout << " " << endl;
cout << "Enter NUMBER of Party: "; //me
TempParty.HowMany = ReadInteger (); //me
cout << " " << endl;

.
.
.
.
.
.
.
.
// Board Alfa plane, enter: name of party, How many in the party
if ((TempParty.HowMany <= PlaneAlfa.MaxNumSeats) && (TempParty.HowMany <= PlaneAlfa.NumSeatsAvailable)) //BoardPlaneAlfa
{
// HERE I need to create a the table to load name of party and howmany in the party

cout << ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " << endl;
//seats are available
PlaneAlfa.NumSeatsAvailable -= TempParty.HowMany; // substracting seats available
cout << " Alfa: Seats Avail.: " << PlaneAlfa.NumSeatsAvailable << endl;
//parties in plane
PlaneAlfa.Who [PlaneAlfa.HowManyParties++] = TempParty ; // counting homany parties in the alfa plane
cout << " Alfa: Parties in Plane: " << PlaneAlfa.HowManyParties << endl;
//name parties
cout << " Alfa: Lastnames: " << PlaneAlfa.Who << endl;

======================= I am not sure how to load the tables, print out and delete those records that flu in plane Alfa.... Can you guide me how to do that?

Thanks,
easo.



Can you guide me how to do that?

Do you have a specific question? If not, keep working until you do, or succeed.
You are already using tables, example: planeAlfa.Who[].
I do not understand what you need help with.
Topic archived. No new replies allowed.