-2

我在将用户分配给数组然后显示数组时遇到问题。典型的“飞行座位分配”计划。任何帮助都会很棒,因为我被严重卡住了。

编译时我没有收到任何错误,所以我假设我离得太远了?代码如下。

注意,单独的头文件中的类。

// Flight Class - Scotia 2
// Contains information on seating (array), space available and return to menu option.
#include <iostream>
#include <string>
#include "booking.h"

using namespace std;

class Flight
{

public:

    public:
    struct Seat
        {
            int Available;
            string fullName;
        };// End of struct

// Structure for seat plan (24 spaces available)
    struct Seat seatArray[4][6];

    void seatPlan()
    {   //------
        cout << "Scotia Airlines Seating Plan\n";
        cout << "------------------------\n";
        cout << " 1D  2D  3D  4D  5D  6D\n";
        cout << " 1C  2C  3C  4C  5C  6C\n";
        cout << "                       \n";
        cout << " 1B  2B  3B  4B  5B  6B\n";
        cout << " 1A  2A  3A  4A  5A  6A\n";
        cout << "------------------------\n\n\n";
        //------
        for (int i=0;i<4;i++)
        {
            for (int j=0;j<6;j++)
                {
                if (seatArray[i][j].Available == 0)
                cout << seatArray[i][j].fullName << "=" << i+1;

                else
                cout << "Seating Plan is unavailable";
                break;
                }
        }// End of for loop
    }// End of seatPlan function

};// End of Flight class

这也是我的预订舱位,因为我相信这将有助于发现问题......

//Booking class - Scotia Airlines
//This class will reserve a seat for passenger

#include <iostream>
#include <string>

using namespace std;

class Booking{

public:
    struct Seat
        {
            int Available;
            string fullName;
        };// End of struct

// Structure for seat plan (24 spaces available)
    struct Seat seatArray[4][6];

//variables for taking in customer details, calculating ticket cost (inc discounts) and adding details to system
    public:
    string fName, sName, busName, fullName;
    int age, livesAt;
    float discount, tickPrice, tCost;

    void addBooking()

    {
    cout << "\tBooking Menu \n\n";
    cout << "Please select ticket type: \n";
    cout << "1- Business \n";
    cout << "2- Western Isles \n";
    cout << "3- Ordinary \n";
    cin >> livesAt;

    // This will be used to calc total cost for each passenger dependant on ticket type
                    if(livesAt == 1)
                        {
                            discount = 0.75;
                            cout << "Please enter your business name\n";
                            cin >> busName;
                        }

                        else if (livesAt == 2)
                            {
                            discount = 0.90;
                            }

                        else
                            {
                            discount = 1.0;
                            };

    // Calculation - Standard ticket price is 60 Beans
                tickPrice = 60.0;
                tCost = (tickPrice * discount);


            bool booked = false;
                for(int i = 0; i < 4 && !booked; i++)
                    {
                        for(int j = 0; j < 6 && !booked; j++)
                        {
                            if(seatArray[i][j].Available == 1)
                            {
                                cout << "Please enter your first name \n";
                                cin >> fName;
                                cout << "Please enter your second name \n";
                                cin >> sName;
                                fullName == fName + " " + sName;
                                seatArray[i][j].fullName = fullName;
                                booked = true;
                                    // Message on screen for customer displaying cost of flight
                                cout << "*******************************\n";
                                cout << "\tBooking for " << fName + " " + sName << " confirmed.\n";
                                cout << "\tTotal cost = " << tCost << " GBP.\n";
                            }//end of if
                        }//end of for2
                    }//end of for1


    }// End of addBooking function
};// End of Booking class

任何帮助将不胜感激!

4

1 回答 1

0

以下是我发现的一些错误:

  1. 首先,您永远不会将座位标记为不可用。将此添加到您的添加嘘声功能中。
  2. 其次,我相信在第二个中的 else for in seatPlan 应该在 else 中。
  3. 在 else 语句之后不需要半列(在设置折扣为 1.0 时的 else 中)

因为你从来没有提到你得到的错误是什么,所以这是我能得到的。希望这个答案有帮助。

于 2012-12-19T19:41:00.460 回答