航空客运订票系统c++
时间: 2023-12-24 16:03:35 浏览: 38
航空客运订票系统的设计与实现是一个可以实现航空客运订票的系统。它包括了浏览和查询航班信息、机票预订和办理退票等主要业务活动。以下是一个使用C++实现的简单示例:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Flight {
string start;
string destination;
string number;
string airplaneNumber;
string flightDate;
int totalSeats;
int availableSeats;
int firstClassSeats;
int businessClassSeats;
int economyClassSeats;
double firstClassPrice;
double businessClassPrice;
double economyClassPrice;
};
vector<Flight> flights;
void addFlight() {
Flight flight;
cout << "Enter start: ";
cin >> flight.start;
cout << "Enter destination: ";
cin >> flight.destination;
cout << "Enter number: ";
cin >> flight.number;
cout << "Enter airplane number: ";
cin >> flight.airplaneNumber;
cout << "Enter flight date: ";
cin >> flight.flightDate;
cout << "Enter total seats: ";
cin >> flight.totalSeats;
cout << "Enter available seats: ";
cin >> flight.availableSeats;
cout << "Enter first class seats: ";
cin >> flight.firstClassSeats;
cout << "Enter business class seats: ";
cin >> flight.businessClassSeats;
cout << "Enter economy class seats: ";
cin >> flight.economyClassSeats;
cout << "Enter first class price: ";
cin >> flight.firstClassPrice;
cout << "Enter business class price: ";
cin >> flight.businessClassPrice;
cout << "Enter economy class price: ";
cin >> flight.economyClassPrice;
flights.push_back(flight);
cout << "Flight added successfully!" << endl;
}
void deleteFlight() {
string number;
cout << "Enter flight number to delete: ";
cin >> number;
for (int i = 0; i < flights.size(); i++) {
if (flights[i].number == number) {
flights.erase(flights.begin() + i);
cout << "Flight deleted successfully!" << endl;
return;
}
}
cout << "Flight not found!" << endl;
}
void displayFlights() {
for (const Flight& flight : flights) {
cout << "Start: " << flight.start << endl;
cout << "Destination: " << flight.destination << endl;
cout << "Number: " << flight.number << endl;
cout << "Airplane Number: " << flight.airplaneNumber << endl;
cout << "Flight Date: " << flight.flightDate << endl;
cout << "Total Seats: " << flight.totalSeats << endl;
cout << "Available Seats: " << flight.availableSeats << endl;
cout << "First Class Seats: " << flight.firstClassSeats << endl;
cout << "Business Class Seats: " << flight.businessClassSeats << endl;
cout << "Economy Class Seats: " << flight.economyClassSeats << endl;
cout << "First Class Price: " << flight.firstClassPrice << endl;
cout << "Business Class Price: " << flight.businessClassPrice << endl;
cout << "Economy Class Price: " << flight.economyClassPrice << endl;
cout << endl;
}
}
int main() {
int choice;
do {
cout << "1. Add Flight" << endl;
cout << "2. Delete Flight" << endl;
cout << "3. Display Flights" << endl;
cout << "0. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
addFlight();
break;
case 2:
deleteFlight();
break;
case 3:
displayFlights();
break;
case 0:
cout << "Exiting..." << endl;
break;
default:
cout << "Invalid choice!" << endl;
break;
}
cout << endl;
} while (choice != 0);
return 0;
}
```
这个示例实现了航空客运订票系统的基本功能,包括添加航班、删除航班和显示航班信息。你可以根据自己的需求进行扩展和修改。