请用C++语言写一个详细的城市饭店信息管理系统,功能包括
时间: 2024-03-27 11:37:07 浏览: 19
好的,以下是一个简单的城市饭店信息管理系统的代码,它包括以下功能:
1. 添加酒店信息
2. 显示酒店信息
3. 搜索酒店信息
4. 修改酒店信息
5. 删除酒店信息
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Hotel {
public:
string name;
string location;
string phone;
int rooms;
void print() {
cout << "Name: " << name << endl;
cout << "Location: " << location << endl;
cout << "Phone: " << phone << endl;
cout << "Rooms: " << rooms << endl;
}
};
vector<Hotel> hotels;
void addHotel() {
Hotel hotel;
cout << "Enter hotel name: ";
cin >> hotel.name;
cout << "Enter hotel location: ";
cin >> hotel.location;
cout << "Enter hotel phone: ";
cin >> hotel.phone;
cout << "Enter number of rooms: ";
cin >> hotel.rooms;
hotels.push_back(hotel);
}
void displayHotels() {
if (hotels.size() == 0) {
cout << "No hotels found." << endl;
return;
}
for (int i = 0; i < hotels.size(); i++) {
hotels[i].print();
cout << endl;
}
}
void searchHotels() {
string searchName;
cout << "Enter hotel name to search: ";
cin >> searchName;
bool found = false;
for (int i = 0; i < hotels.size(); i++) {
if (hotels[i].name == searchName) {
hotels[i].print();
found = true;
}
}
if (!found) {
cout << "No hotels found with name " << searchName << endl;
}
}
void modifyHotel() {
string modifyName;
cout << "Enter hotel name to modify: ";
cin >> modifyName;
bool found = false;
for (int i = 0; i < hotels.size(); i++) {
if (hotels[i].name == modifyName) {
cout << "Enter new hotel name: ";
cin >> hotels[i].name;
cout << "Enter new hotel location: ";
cin >> hotels[i].location;
cout << "Enter new hotel phone: ";
cin >> hotels[i].phone;
cout << "Enter new number of rooms: ";
cin >> hotels[i].rooms;
found = true;
}
}
if (!found) {
cout << "No hotels found with name " << modifyName << endl;
}
}
void deleteHotel() {
string deleteName;
cout << "Enter hotel name to delete: ";
cin >> deleteName;
bool found = false;
for (int i = 0; i < hotels.size(); i++) {
if (hotels[i].name == deleteName) {
hotels.erase(hotels.begin() + i);
found = true;
}
}
if (!found) {
cout << "No hotels found with name " << deleteName << endl;
}
}
int main() {
int choice;
do {
cout << "1. Add hotel" << endl;
cout << "2. Display hotels" << endl;
cout << "3. Search hotels" << endl;
cout << "4. Modify hotel" << endl;
cout << "5. Delete hotel" << endl;
cout << "6. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
addHotel();
break;
case 2:
displayHotels();
break;
case 3:
searchHotels();
break;
case 4:
modifyHotel();
break;
case 5:
deleteHotel();
break;
case 6:
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 6);
return 0;
}
```
这个代码使用了一个 Hotel 类来表示一个酒店的信息,同时使用了一个 vector 来存储所有的酒店信息。每个酒店信息包括名称、位置、电话和房间数。主程序提供了一个菜单,用户可以选择不同的操作来添加、显示、搜索、修改和删除酒店信息。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)