C++ 将名称指定给座椅并显示在阵列中
我在将用户分配到阵列然后显示阵列时遇到问题。典型的“航班座位分配”程序。任何帮助都将是美妙的,因为我被严重卡住了 我在编译时没有遇到任何错误,所以我假设我离得不远?代码如下 注意,类位于单独的头文件中C++ 将名称指定给座椅并显示在阵列中,c++,arrays,assign,C++,Arrays,Assign,我在将用户分配到阵列然后显示阵列时遇到问题。典型的“航班座位分配”程序。任何帮助都将是美妙的,因为我被严重卡住了 我在编译时没有遇到任何错误,所以我假设我离得不远?代码如下 注意,类位于单独的头文件中 // Flight Class - Scotia 2 // Contains information on seating (array), space available and return to menu option. #include <iostream> #include
// 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
任何帮助都将不胜感激 以下是我发现的一些错误: 首先,你从不把座位标记为不可用。将此添加到“添加嘘声”功能中。 第二个在第二个在海上的计划应该在其他我相信。 将折扣设置为1.0时,不需要在else中的else语句后加半列
因为你从来没有提到你所犯的错误,这是我能得到的最好的结果。希望这个答案有帮助。程序做错了什么?是什么让你问这个问题?这里只有一堆代码和一个非常模糊的问题描述。。。你试过调试吗?seatPlan函数中的break语句看起来不合适。这会导致内部循环只运行一次。与其使用i和j作为变量,我建议将它们重命名为row和column,这将使您的程序更易于阅读。对不起,各位。我确实忘了强调这个问题。当我调试时,没有给我一个错误。这就是问题所在。我想做的是让一名乘客在24座飞机上预订一个座位。它接收乘客的详细信息,即名字、姓氏,并将其分配给飞机上的一个座位。它允许我编译和运行,但当我从菜单中选择查看飞机座椅平面图时,它无法显示布局,然后错误消息座椅平面图不可用3次。很抱歉,我第一次忘了包括所有内容!: