用c++程序语言写完整的影碟出租管理系统 基本要求: 影碟信息包括:影碟名称、国家、类型、借阅标记等 出租信息包括:会员名、碟片名称、借阅日期、归还日期、租金等 功能要求: 1)新片上架:添加碟片信息 保片查询:按片名查询是否可借阅,结果有三种(可借阅、已借出、无此片) 3)碟片借阅:输入会员名、碟片名称、借阅日期、修改碟片租借标记 4)碟片归还:输入会员名、碟片平常、归还日期,修改碟片的租借标记,计算租金(每三天的租金为1元,不满三天按三天计算)
时间: 2023-07-04 11:17:35 浏览: 24
下面是用C++实现基本要求的影碟出租管理系统的代码:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
// 定义影碟信息结构体
struct DVD {
string name; // 影碟名称
string country; // 国家
string type; // 类型
bool rented; // 借阅标记
};
// 定义出租信息结构体
struct Rental {
string memberName; // 会员名
string dvdName; // 碟片名称
time_t rentalDate; // 借阅日期
time_t returnDate; // 归还日期
float rent; // 租金
};
// 定义全局变量
vector<DVD> dvdList; // 影碟列表
vector<Rental> rentalList; // 出租列表
// 新片上架
void addDVD() {
DVD dvd;
cout << "请输入影碟名称:";
getline(cin, dvd.name);
cout << "请输入国家:";
getline(cin, dvd.country);
cout << "请输入类型:";
getline(cin, dvd.type);
dvd.rented = false; // 默认未借出
dvdList.push_back(dvd);
cout << "影碟《" << dvd.name << "》已加入库存。\n";
}
// 影碟查询
void searchDVD() {
string name;
cout << "请输入要查询的影碟名称:";
getline(cin, name);
bool found = false;
for (int i = 0; i < dvdList.size(); i++) {
if (dvdList[i].name == name) {
if (dvdList[i].rented) {
cout << "影碟《" << name << "》已被借出。\n";
} else {
cout << "影碟《" << name << "》可借阅。\n";
}
found = true;
break;
}
}
if (!found) {
cout << "无此片。\n";
}
}
// 影碟借阅
void rentDVD() {
string memberName, dvdName;
time_t rentalDate = time(0); // 获取当前时间
tm* t = localtime(&rentalDate);
t->tm_hour = 0; // 将时间设置为零时
t->tm_min = 0;
t->tm_sec = 0;
rentalDate = mktime(t);
cout << "请输入会员名:";
getline(cin, memberName);
cout << "请输入碟片名称:";
getline(cin, dvdName);
bool found = false;
for (int i = 0; i < dvdList.size(); i++) {
if (dvdList[i].name == dvdName) {
if (dvdList[i].rented) {
cout << "影碟《" << dvdName << "》已被借出。\n";
} else {
dvdList[i].rented = true;
Rental rental;
rental.memberName = memberName;
rental.dvdName = dvdName;
rental.rentalDate = rentalDate;
rental.returnDate = 0;
rental.rent = 0;
rentalList.push_back(rental);
cout << "会员" << memberName << "已借阅影碟《" << dvdName << "》。\n";
}
found = true;
break;
}
}
if (!found) {
cout << "无此片。\n";
}
}
// 影碟归还
void returnDVD() {
string memberName, dvdName;
time_t returnDate = time(0); // 获取当前时间
tm* t = localtime(&returnDate);
t->tm_hour = 0; // 将时间设置为零时
t->tm_min = 0;
t->tm_sec = 0;
returnDate = mktime(t);
cout << "请输入会员名:";
getline(cin, memberName);
cout << "请输入碟片名称:";
getline(cin, dvdName);
bool found = false;
for (int i = 0; i < rentalList.size(); i++) {
if (rentalList[i].memberName == memberName && rentalList[i].dvdName == dvdName) {
rentalList[i].returnDate = returnDate;
float days = difftime(returnDate, rentalList[i].rentalDate) / (24 * 60 * 60); // 计算租借天数
int rentDays = days / 3; // 计算租金天数
if (days - rentDays * 3 > 0) {
rentDays++;
}
rentalList[i].rent = rentDays; // 每三天的租金为1元
for (int j = 0; j < dvdList.size(); j++) {
if (dvdList[j].name == dvdName) {
dvdList[j].rented = false;
break;
}
}
cout << "会员" << memberName << "已归还影碟《" << dvdName << "》,租金为" << rentDays << "元。\n";
found = true;
break;
}
}
if (!found) {
cout << "无此记录。\n";
}
}
int main() {
while (true) {
cout << "请输入数字选择功能:\n";
cout << "1.新片上架\n";
cout << "2.碟片查询\n";
cout << "3.碟片借阅\n";
cout << "4.碟片归还\n";
cout << "5.退出\n";
int choice;
cin >> choice;
cin.ignore(); // 忽略换行符
switch (choice) {
case 1:
addDVD();
break;
case 2:
searchDVD();
break;
case 3:
rentDVD();
break;
case 4:
returnDVD();
break;
case 5:
return 0;
default:
cout << "无效选择,请重新输入。\n";
break;
}
}
return 0;
}
```
这个程序实现了基本要求中的四个功能,可以通过输入数字选择功能。新片上架和影碟查询功能比较简单,主要是通过查询影碟列表来实现。影碟借阅和影碟归还功能需要修改影碟的借阅标记,并在出租列表中添加或修改记录。在计算租金时,程序使用了C++的时间库来计算租借天数,并按照每三天1元的规则计算租金。