The question asks:

Write and compile a C++ program that simulates the arrivals of airplanes at Regina airport. An airplane is represented using a C++ struct. Each plane belongs to an airline, such as United, and records the city from which it is arriving, for example Chicago. The airport is an ADT that holds all of the arrivals at the airport. These arrivals are stored in an array. Boolean functions are needed to test whether or not there are any arrivals or if the arrivals terminal is full (4 airplanes). A function to add a new arrival to the airport is, of course, necessary. This function places the next arriving plane at the end of the (unsorted) arrival array. Moreover, an initialization function that sets the arrival terminal to empty is required. Finally, create a boolean function to test if a particular airline from a specified city is currently sitting in the arrival terminal. Test your program using the script given below (code this in the main function), namely

Initialize arrival terminal to empty
If there are any arrivals, print that there are some arrivals; otherwise, print that there are no arrivals yet
Add a new WestJet airplane from Calgary
Add a new United airplane from Chicago
If there are any arrivals, print that there are some arrivals; otherwise, print that there are no arrivals yet
If the arrival terminal is full, print that it is full; otherwise, print that it is not full
If there is an Air Canada plane from Toronto, print that it has arrived; otherwise, print that it has not yet arrived Add a new Air Canada airplane from Toronto
Add a new Delta airplane from Minneapolis
If the arrival terminal is full, print that it is full; otherwise, print that it is not full
If there is an Air Canada plane from Toronto, print that it has arrived; otherwise, print that it has not yet arrived

I need some help getting started here. This is what I have written so far, can anyone point me in the right direction on this one?

#include <iostream>
using namespace std;

class Airport
{
    private:
        string arrivals[4];
        string newArrival;

    public:
        Airport();
        void setArrival(string newArrival); 
        string getArrival();
        bool isArrived(const Airport &airport);
        bool isFull(const Airport &airport);
};


struct Airplane
{
    string airline;
    string city;
};




int main()
{

}

Recommended Answers

All 6 Replies

Hi,

I think you're asking for too much here. In my opinion there's no "right direction", you just have to solve all the parts of the problem.

Maybe if you pick one part it will be easier to be helped, other than that it's basically do the homework for you.

Given the lack of info in the description, I assume the program is menu driven. In other words, you just execute the menu commands after initialization in this order:

arrivals?
add
add
arrivals?
full?
check
add
add
full?
check

Is that about it?

I need some help getting started here. This is what I have written so far, can anyone point me in the right direction on this one?

It's obvious. Start writing the functions specified in the description.
In main(), test these functions as you write them.

You might want to start with a
1) the initialize method
2) print method to display all the current planes (useful for debugging)
3) add method so you can add the planes
Then test the above until they work.

Now start adding all the other functions.

bool isFull(const Airport &airport);
Why pass in the Airport? The method is part of the Airport definition. Therefore bool isFull(void); is an appropriate definition.

#include <iostream>
#include <string>
using namespace std;
class Airport
{
    private:
        string arrivals[4];
        string newArrival;
    public:
        Airport();
        void setArrival(string newArrival); 
        string getArrival();
        bool isArrived(const Airport &airport);
        bool isFull(const Airport &airport);
};
struct Airplane
{
    string airline;
    string city;
};
int main()
{
    int x, y, b, c, z;
    bool power = true;
    string *ports, comm, plane, *airport, *planelist;
    planelist = new string [c];
    ports = new string [x];
    airport = new Airport [y]
    Airplane plane;
    while(power)
    {
        cin >> comm;
        if(comm == "quit") power = false;
        if(comm == "add") 
        {
            c++
            cout << "\nAirline: ";
            cin >> plane.airline;
            cout << "\nCity: ";
            cin >> plane.city;
            for(int a = 0; a <= x; a++;)
            {
                if(plane.city == ports[a]) break;
                x++;
                ports[x] = plane.city;
                y++;
                //airport description
                planelist[c] << plane.airline << " " << plane.city;
                plane.airline = NULL;
                plane.city = NULL;
            }
        }
        if(comm == "check")
        {
            for(b = 0; b <= x; b++;)
            {
                cout << "\n" << ports[b];
            }
        }
    }
return 0;
}

That should cover most of it.

commented: This code is worthless. Does nothing the OP needs -3

Ok thank you all, ill try to find a solution and post it if i do.

Ok I am still tying to work through this. Here is my code now.

#include <iostream>
#include <string>
using namespace std;

//************************************************************//
class Airport
{
private:
    string plane;
    string city;
    string terminal[4];
public:
    void setPlane(string aPlane);
    void setCity(string aCity);
    void setTerminal(string plane1, string plane2, string plane3, string plane4);
    string getTerminal(int i);
    string getPlane();
    string getCity();
    string getArrival();
};

struct Airplane
{
    string airline;
    string city;
};



//**************************************************************//

void Airport::setPlane(string aPlane)
{
    plane = aPlane;
}

void Airport::setCity(string aCity)
{
    plane = aCity;
}

void Airport::setTerminal(string plane1, string plane2, string plane3, string plane4)
{
    terminal[0] = plane1;
    terminal[1] = plane2;
    terminal[2] = plane3;
    terminal[3] = plane4;
}

string Airport::getPlane()
{
    return plane;
}


string Airport::getCity()
{
    return city;
}

string Airport::getTerminal(int i)
{
    if (i<=4 && i>=0)
    {
        return terminal[i];
    }
    else
    {
        cout << "terminal is full"; 
    }
}

//**************************************************************//


//**************************************************************//
int main()
{
    string Plane_name, City_name;
    Airport port; 
    string exit;
    int i;

    // Test for empty arrival terminals;
    port.getTerminal(i);

    cout << "Airline: ";
    getline(cin, Plane_name, '\n');
    port.setPlane(Plane_name);
    port.setTerminal(Plane_name, Plane_name, Plane_name, Plane_name);


    cout << "City: ";
    getline(cin, Plane_name, '\n');
    port.setCity(City_name);




    return 0;
}

I am very confused as to what to do now. Any tips?

Depends.

What is your concept?
How do you process each of the commands in your description?

When programming, you can't just start throwing code into your file. You have to make many decisions before you code anything.

Case in point, After reading your description and making my first post, I decided this was interesting enough to try to do. In an hour I had a working program -- by following my 'design' outlined above. Granted, I've been doing this for years, but the point is I started with a design.

Since you didn't seem to like anything in what I suggested (you didn't use any of my ideas at all), you'll need to explain (design) your program given the concept you listed in your first post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.