帮我写一个C++代码的影碟租赁管理信息系统,可以实现影碟管理、影碟租借、 影碟查询和月租管理的功能。
时间: 2024-04-08 21:33:41 浏览: 18
当然可以!下面是一个简单的影碟租赁管理信息系统的C++代码示例:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class DVD {
public:
string title;
bool available;
DVD(string t) {
title = t;
available = true;
}
};
class DVDLibrary {
private:
vector<DVD> DVDs;
public:
void addDVD(string title) {
DVDs.push_back(DVD(title));
}
void rentDVD(string title) {
for (DVD& dvd : DVDs) {
if (dvd.title == title && dvd.available) {
dvd.available = false;
cout << "成功租借影碟:" << title << endl;
return;
}
}
cout << "影碟不可用或不存在:" << title << endl;
}
void returnDVD(string title) {
for (DVD& dvd : DVDs) {
if (dvd.title == title && !dvd.available) {
dvd.available = true;
cout << "成功归还影碟:" << title << endl;
return;
}
}
cout << "影碟不存在或已归还:" << title << endl;
}
void listDVDs() {
cout << "影碟列表:" << endl;
for (const DVD& dvd : DVDs) {
cout << "- " << dvd.title << "(" << (dvd.available ? "可借" : "已借出") << ")" << endl;
}
}
};
int main() {
DVDLibrary library;
library.addDVD("影碟1");
library.addDVD("影碟2");
library.addDVD("影碟3");
library.listDVDs();
library.rentDVD("影碟2");
library.rentDVD("影碟4");
library.returnDVD("影碟2");
library.returnDVD("影碟3");
library.listDVDs();
return 0;
}
```
这段代码创建了一个DVD类来表示影碟,包含标题和可用性信息。DVDLibrary类管理DVDs的集合,并提供了添加、租借、归还和列出DVD的功能。
你可以根据自己的需求扩展该代码,并添加其他功能,比如月租管理等。
希望这能帮到你!如果你还有其他问题,请随时提问。