このフォーラムは初めてです。コード、レイアウト、またはその他の関連するものに関する建設的な批判は大歓迎です!
私が抱えている問題は、(タイトルが示すように)標準の座席予約プログラムfullName
の配列に文字列を追加することに関するものです。seatArray
私が得ているエラーは、一度コンパイルすると、の後に出力がないということです'please enter your second name'
。コンパイル時にデバッガーにエラーは表示されません。また、これは私の配列に何も追加されていないことを意味すると想定しているseatArray
ので、少なくとも正しい方向に向けていただければ幸いです!
注意: すべてのクラスは個別のヘッダー ファイルです
まず、私の main.cpp ファイル
// Main class - Scotia2
// Main cpp file
#include <iostream>
#include "menu.h"
using namespace std;
int main()
{
Menu m;
m.userMenu();
return 0;
};
私のMenu
クラス(これが問題に関連しているかどうかはわかりませんが、とにかく含めます)
// Menu class - Scotia2
#include <iostream>
#include "flight.h"
using namespace std;
class Menu
{
// Access specifier
public:
int userMenu()
{
Flight f1;
Booking b1;
int option;
cout << "Scotia Airlines\n";
cout << "\n 1- Check Availability";
cout << "\n 2- Book a Seat";
cout << "\n 3- Cancel a Reservation";
cout << "\n 4- Exit \n ";
cout << "-------------------\n\n ";
cin >> option;
do{
switch (option)
{
case 1: f1.seatPlan();
break;
case 2: b1.addBooking();
break;
//case 3: c1.cancel; // Link to cancel.h
//break;
case 4: return (0);
break;
}
}while (option == 0); // End of do-while
return option;
cout << "\n";
}// End of userMenu function
};// End of menu class
私のFlight
クラス:
// 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;
else
cout << "Seating Plan is unavailable";
}
}// End of for loop
}// End of seatPlan function
};// End of Flight class
そして最後に、私のBooking
クラス。これは、エラーが発生している場所だと思います。おそらく物事が正しい順序で実行されていないと思ったので、さまざまな方法でコードをレイアウトしようとしました。ただし、これは実際には機能していません。
//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 = 0.0;
}
// Calculation - Standard ticket price is 60
tickPrice = 60.0;
tCost = (tickPrice * discount);
//Create full name for pass to asign to seat
fullName = fName + " " +sName;
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 6; 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;
cin >> seatArray[i][j].fullName;
seatArray[i][j].Available = 0;
}// end of if
}// end of nested for
};//end of for
// Message on screen for customer displaying cost of flight
cout << "*******************************\n";
cout << "\tBooking for " << fullName << " confirmed\n";
cout << "\tTotal cost = " << tCost << " GBP.\n";
}// End of addBooking function
};// End of Booking class
私が言ったように、コードが少しずさんである可能性があることは承知しています(かなり初心者のプログラマー)ので、ヒントなどは大歓迎です!#
敬具、
ZM