2012-12-19 131 views
-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 

任何幫助將不勝感激!

+3

程序做錯了什麼?什麼導致你問這個問題? – 0x499602D2

+0

只有一堆代碼和一個非常模糊的問題描述...你嘗試調試嗎? –

+0

'seatPlan'函數中的'break'語句看起來不合適。它會導致內部循環只運行一次。 –

回答

0

這裏有一些錯誤,我都看準:

  1. 首先你從來沒有標記爲不可用座位。將此添加到您的添加噓聲功能。
  2. 第二在seatPlan的第二個應在其他我相信。
  3. (設置折扣爲1.0時,在其他人)你不需要一個else語句後半列

正如你別說你是什麼人收到此錯誤是一樣好,我可以得到。希望這個答案有幫助。

+0

抱歉的人。我沒有忘記強調這個問題。當我調試我沒有給錯誤。這就是它出錯的地方。我在這裏試圖做的事情是讓乘客在24座飛機上預留座位。它接收乘客的詳細信息,即名字,姓氏並將其分配給飛機上的座位。它可以讓我編譯和運行,但是當我從菜單中選擇查看飛機座位計劃時,它是cout的佈局,然後錯誤消息「座位計劃不可用」3次。對不起,我忘了第一次包括所有這些! :( –