c++ – List Elements Greater Than or Equal to & Allow User to Change Value


My assignment requires me to list all cruising aircraft with an altitude of 30,000ft or higher. However, it doesn’t seem to show the aircrafts when I compile it. Did I miss something in the code?

 std::vector<Aircraft> FlightSystem::ListAllCruisingAircraft()
{
    std::vector<Aircraft> cruisingAircraft;
    for (int a = 0; a < aircraftList_.size(); a++)
    {
        if (aircraftList_.at(a).GetAltitude() >= 30000)
        {
            cruisingAircraft.push_back(aircraftList_.at(a));
        }
    }
    return cruisingAircraft;
}

Also, I want the user to be able to change the heading and altitude of the aircraft, and for the change to be displayed on the list. I’m, however, having the same problem as above. The program compiles, but it won’t run the code.

    int FlightSystem::GetAltitude(std::string flightNumber)
{
    bool altitudeCheck = true;
    for (int a = 0; a < aircraftList_.size(); ++a)
    {
        if (aircraftList_[a].GetFlightNumber() == flightNumber)
        {
            aircraftList_[a].GetAltitude();
            altitudeCheck = false;
        }
    }
    return altitudeCheck;
}

void FlightSystem::ChangeAltitude(std::string flightNumber, int altitude)
{
    bool altitudeCheck = true;
    for (int a = 0; a < aircraftList_.size(); a++)
    {
        if (aircraftList_[a].GetFlightNumber() == flightNumber)
        {
            aircraftList_[a].GetAltitude();
            altitudeCheck = true;
            std::cout << "Altitude of Flight " << flightNumber << " changed to " << altitude << std::endl;
        }
        else
        {
            std::cout << "Flight " << flightNumber << " is not in the system." << std::endl;
            return;
        }
    }
}

Appreciate the help!



لینک منبع

پاسخ دهید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *