这是主文件
#include
#include
#include
#include
#pragma comment(lib,"winmm.lib")
#include
#include
#include
#include
#include
const int MaxDM = 4; //++++++++++++++++++++
using namespace std;
void manager();
//读取并播放视频
#include
//#include
//#include
using namespace cv;
IMAGE backimg; //定义一张图片
void Welcome()
{
//初始化界面
initgraph(1070, 800); //1070 800
srand((unsigned int)time(NULL));
//加载图片
loadimage(&backimg, "./yy/10.jpg", 1070, 800);
PlaySound("./yy/fripSide - late in autumn.wav", NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
// 播放背景音乐
/*for (int i = 0; i < 50; i++) //50
{
//圆的轨迹方程。
int x = 600 + int(180 * sin(PI * 2 * i / 60));
int y = 200 + int(180 * cos(PI * 2 * i / 60));
cleardevice();
settextcolor(WHITE);
settextstyle(i, 0, "楷体");
outtextxy(x - 80, y, "我最爱的动漫Clannad~");
outtextxy(x - 10, y + 70, "你是我心中善良的一面!");
Sleep(25);
}
/*如果一个人笑,那就证明这个人很开心。
但是一直笑,那就绝对不是。
这就可以证明这个人的过去,有一种非常痛苦的经历,让她在面对未来的生活中必须微笑
-- 愿君与你白头偕老 《鬼灭之刃》
微风轻倦,拥满院
刹时花开,蝶未飞 -- 纪野川奈 《鬼灭之刃》
*/
putimage(0, 0, &backimg);
_getch();
settextstyle(24, 0, "楷体");
settextcolor(WHITE);
setbkmode(0);
outtextxy(200, 200, "如果一个人笑,那就证明这个人很开心。");
outtextxy(200, 250, "但是一直笑,那就绝对不是。");
outtextxy(70, 300, "这就可以证明这个人的过去,有一种非常痛苦的经历,让她在面对未来的生活中必须微笑 ");
outtextxy(200, 350, "-- 愿君与你白头偕老");
outtextxy(200, 400, "微风轻倦,拥满院");
outtextxy(200, 450, "刹时花开,蝶未飞");
outtextxy(200, 500, "-- 纪野川奈 《鬼灭之刃》");
outtextxy(400, 550, "——兔婧");
_getch();
cleardevice();
}
void bfsp()
{
srand((unsigned int)time(NULL));
VideoCapture capture("./yy/2.mp4"); //读入视频,实例化的同时再初始化
//2循环显示每一帧
while (1)//(!_kbhit())
{
Mat frame; //定义一个Mat变量,用于存储每一帧的图像
capture >> frame; //读取当前帧
//若视频播放完成,退出循环
if (frame.empty())
{
break;
}
imshow("读取视频", frame); //显示当前帧
waitKey(30); //延时30MS
}
_getch();
cleardevice();
/*如果一个人笑,那就证明这个人很开心。
但是一直笑,那就绝对不是。
这就可以证明这个人的过去,有一种非常痛苦的经历,让她在面对未来的生活中必须微笑
-- 愿君与你白头偕老 《鬼灭之刃》
微风轻倦,拥满院
刹时花开,蝶未飞 -- 纪野川奈 《鬼灭之刃》
*/
}
class DM {
int del_tag;
int dm_No;//++++++++++++++++++
char dm_Name[49];
char dm_Password[13];
public:
DM();
DM(int dmNo, char dmName[49], char dmPassword[13]); //+++++++++++++
int getDelTag();
int getDMNo();//++++++++++++
char* getDMName();
char* getDMPassword();
void setDMName(char dmName[]);
void setDMPassword(char dmPassword[]);
void delDM();
void addDM(int dmNo, char dmName[], char dmPassword[]);
int strcmp1(char dmName[]);
int strcmp2(char dmPassword[]);
};
DM::DM()
{}
DM::DM(int dmNo, char dmName[49], char dmPassword[13]) {
addDM(dmNo, dmName, dmPassword);
}
int DM::getDelTag() {
return del_tag;
}
int DM::getDMNo() {
return dm_No;
}
void DM::delDM() {
del_tag = 1;
}
void DM::addDM(int dmNo, char dmName[], char dmPassword[]) {
del_tag = 0;
dm_No = dmNo;
strcpy_s(dm_Name, dmName);
strcpy_s(dm_Password, dmPassword);
}
void DM::setDMName(char dmName[]) {
strcpy_s(dm_Name, dmName);
}
void DM::setDMPassword(char dmPassword[]) {
strcpy_s(dm_Password, dmPassword);
}
char* DM::getDMName() {
return dm_Name;
}
char* DM::getDMPassword() {
return dm_Password;
}
int DM::strcmp1(char dmName[]) {
if (strcmp(dmName, dm_Name) == 0)
return 1;
return 0;
}
int DM::strcmp2(char dmPassword[]) {
if (strcmp(dmPassword, dm_Password) == 0)
return 1;
return 0;
}
class DMDataBase {
list
public:
DMDataBase();
~DMDataBase();
void clear();
int addDM(int dmNo, char dmName[], char dmPassword[]);
DM* query(int dmNo);
DM* query1(char dmName[]);
DM* query2(char dmPassword[]);
void dmdata();
};
DMDataBase::DMDataBase() {
DM L;
fstream file("dm.dat", ios::in);
while (1) {
file.read((char*)&L, sizeof(L));
if (!file)
break;
d_m.push_back(L);
}
file.close();
}
DMDataBase::~DMDataBase() {
fstream file("dm.dat", ios::out | ios::binary);
list
for (iter = d_m.begin(); iter != d_m.end(); iter++) {
if (iter->getDelTag() == 0)
file.write((char*)&(*iter), sizeof(DM));
}
file.close();
}
void DMDataBase::clear() {
d_m.clear();
}
int DMDataBase::addDM(int dmNo, char dmName[], char dmPassword[]) {
DM* p = query(dmNo);
if (p == NULL) {
DM M(dmNo, dmName, dmPassword);
d_m.push_back(M);
return 1;
}
return 0;
}
DM* DMDataBase::query(int dmNo) {
list
for (iter = d_m.begin(); iter != d_m.end(); iter++) {
if (iter->getDMNo() == dmNo && iter->getDelTag() == 0)
return &(*iter);
}
return NULL;
}
DM* DMDataBase::query1(char dmName[]) {
list
for (iter = d_m.begin(); iter != d_m.end(); iter++) {
if (strcmp(iter->getDMName(), dmName) == 0 && iter->getDelTag() == 0)
return &(*iter);
}
return NULL;
}
DM* DMDataBase::query2(char dmPassword[]) {
list
for (iter = d_m.begin(); iter != d_m.end(); iter++) {
if (strcmp(iter->getDMPassword(), dmPassword) == 0 && iter->getDelTag() == 0)
return &(*iter);
}
return NULL;
}
void DMDataBase::dmdata() {
int choice = 1;
int temp = 1;
char dmname[49];
char dmpassword[13];
int dmno;
int estimate = 0;
int n = 0;
int count;
int k = 1;
int k2 = 1;
char c;
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
DM* M;
while (choice != 0) {
cout << "" << endl;
cout << " ┌───────────────────────────────────┐\n";
cout << " │ ++ ★★★★★管理员权限管理★★★★★++ │\n";
cout << " ├───────┬────────┬────────┬─────────┤\n";
cout << " │1:管理员登录 │ 2:管理员注册 │3:管理员权限修改│ 0:返回上一级目录 │\n";
cout << " ├───────┼────────┼────────┼─────────┤\n";
cout << " │ 请您选择: │\n";
cout << " └───────────────────────────────────┘\n";
cout << "\t";
cin >> choice;
switch (choice) {
case 1: //登录
a:
cout << "\n\n\t\t\t请输入管理员名称:";
cin >> dmname;
M = query1(dmname); //根据输入的管理员名称查询
if (M == NULL) { //如果查询的结果为空
system("cls");
system("color 4E");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t对不起,你的用户名不正确或用户名不存在!请重新输入或先注册:" << endl;
while (k < 3) { //当输入次数在三次之内执行下面的语句
k++;
goto a; //跳到a处继续循环
}
cout << "\n\n\n\t\t并且您已输错三次用户名,请查证后再行登录!!!";
break;
}
else {
b:
cout << "\n\n\t\t\t请输入管理员密码:";
dmpassword[9] = 0;
count = 0;
while ((c = _getch()) != '\r') { //当输入的字符不是回车
dmpassword[count++] = c;
putchar('*');
}
dmpassword[count] = '\0';
estimate = M->strcmp2(dmpassword); //核对密码
if (estimate == 0) {
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t您的密码不正确!请重新输入:" << endl;
while (k2 < 3) {
k2++;
goto b;
}
cout << "\n\n\n\t\t并且您已输错三次密码,请查证后再行登录!!!";
break;
}
else {
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t\t恭喜登录成功!" << endl;
manager();
break;
}
}
break;
case 2: //注册
f:
cout << "\n\n\t\t\t请输入您要注册的管理员编号(请牢记管理员编号):";
cin >> dmno;
M = query(dmno); //根据编号查询
if (M != NULL) {
cout << "\n\n\t\t\t提示:该管理员已存在,请重新注册" << endl;
goto f; //跳到f处继续执行
}
cout << "\n\n\t\t\t请输入您要注册的管理员姓名:";
cin >> dmname;
cout << "\n\n\t\t\t请输入您要注册的管理密码:";
count = 0;
while ((c = _getch()) != '\r') {
dmpassword[count++] = c;
putchar('*');
}
dmpassword[count] = '\0';
addDM(dmno, dmname, dmpassword); //添加管理员函数
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t管理员注册成功!!!" << endl;
break;
case 3: //修改管理员
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
while (temp != 0) {
cout << "\n\n\t1.管理员名称修改\t2.管理员密码修改\t0.返回上一级目录\n";
cout << "\n\n\t请选择:";
cin >> temp;
switch (temp) {
case 1: //修改管理员名称
cout << "\n\n\t\t\t请输入管理员编号:";
cin >> dmno;
d:
M = query(dmno);
if (M == NULL) {
cout << "\n\n\t\t\t提示:该管理员不存在,请重新输入:" << endl;
goto d;
}
cout << "\n\n\t\t\t请输入管理员名称:";
cin >> dmname;
M = query1(dmname);
if (M == NULL) {
cout << "\n\n\t\t\t提示:该管理员不存在" << endl;
goto d;
}
cout << "\n\n\t\t\t请输入新的管理员名称:";
cin >> dmname;
M->setDMName(dmname);
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t管理员名称修改成功!!!" << endl;
break;
case 2: //修改管理员密码
cout << "\n\n\t\t\t请输入管理员编号:";
cin >> dmno;
e:
cout << "\n\n\t\t\t请输入管理员密码:";
count = 0;
while ((c = _getch()) != '\r') {
dmpassword[count++] = c;
putchar('*');
}
dmpassword[count] = '\0';
M = query2(dmpassword); //根据密码查询
if (M == NULL) {
cout << "\n\n\t\t\t您输入的密码有误,请重新输入:" << endl;
goto e;
}
cout << "\n\n\t\t\t请输入新的管理员密码:";
count = 0;
while ((c = _getch()) != '\r') {
dmpassword[count++] = c;
putchar('*');
}
dmpassword[count] = '\0';
M->setDMPassword(dmpassword); //设置管理员密码
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t管理员密码修改成功!!!" << endl;
break;
default:
if (temp == 0) {
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
break;
}
break;
cout << "\n\n\t\t\t输入错误!!!\n请重新选择:";
break;
}
}
break;
default:
if (choice == 0) {
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
break;
}
break;
cout << "\n\n\t\t\t输入错误!!!\n请重新选择:";
break;
}
}
}
class DMZXY { //动漫类
int del_tag; //删除标记 1.已删 0.未删
int dm_1no; //动漫编号
char dm_2name[44]; //动漫名
int dm_onshelf; //是否在看 1.在看 0.已看
public:
DMZXY(); //构造函数
DMZXY(int dmid, char dm3name[]); //重载构造函数
char* getdm3Name(); //获取动漫名
int getdm4No(); //获取动漫编号
int getDelTag(); //获取删除标记
int borrowdm(); //借动漫操作
void retdm(); //还动漫操作
void setname(char dm3name[]); //设置动漫名
void deldm(); //删除动漫
void adddm(int dmid, char dm3name[]); //增加动漫
void dmdisplay(); //显示一部动漫
};
DMZXY::DMZXY() //构造函数
{}
DMZXY::DMZXY(int dmid, char dm3name[]) { //重载构造函数
adddm(dmid, dm3name); //增加动漫
}
char* DMZXY::getdm3Name() {
return dm_2name; //获得动漫名
}
int DMZXY::getdm4No() {
return dm_1no; //获得动漫编号
}
int DMZXY::getDelTag() {
return del_tag; //返回删除标记
}
int DMZXY::borrowdm() { //借动漫函数
if (dm_onshelf == 1) { //如果变量值为1,表示在架
dm_onshelf = 0; //改变值为0
return 1; //返回真
}
return 0; //否则返回假
}
void DMZXY::retdm() { //还
dm_onshelf = 1; //变量值为1,表示在看
}
void DMZXY::setname(char dm3name[]) {
strcpy_s(dm_2name, dm3name); //设置动漫名
}
void DMZXY::deldm() {
del_tag = 1; //设置删除标记为1
}
void DMZXY::adddm(int dmid, char dm3name[]) {
del_tag = 0; //删除标记设值为0
dm_1no = dmid;
strcpy_s(dm_2name, dm3name);
dm_onshelf = 1; //在看
}
void DMZXY::dmdisplay() { //输出一个动漫函数
cout << "\n\n\t\t\t";
cout << setw(6) << dm_1no << setw(12) << dm_2name << setw(10) << (dm_onshelf == 1 ? "没看" : "已看") << endl;
}
class DMZXYDataBase { //动漫类
list
public:
DMZXYDataBase(); //构造函数
~DMZXYDataBase(); //析构函数
void clear(); //清除函数
int adddm(int dmid, char dm_2name[]); //添加动漫函数
DMZXY* query(int dmid); //根据动漫的编号查询函数
void dmdata(); //动漫维护函数
void dmdispall(); //输出所有动漫函数
};
DMZXYDataBase::DMZXYDataBase() { //通过构造函数将数据写入文件
DMZXY X;
fstream file("dmx.dat", ios::in);
while (1) {
file.read((char*)&X, sizeof(X));
if (!file)
break;
dmx.push_back(X);
}
file.close();
}
DMZXYDataBase::~DMZXYDataBase() { //通过析构函数将数据写入文件
fstream file("dmx.dat", ios::out | ios::trunc);
list
for (iter = dmx.begin(); iter != dmx.end(); iter++) {
if (iter->getDelTag() == 0)
file.write((char*)&(*iter), sizeof(DMZXY));
}
file.close();
}
void DMZXYDataBase::clear() { //清除所有动漫
dmx.clear();
}
int DMZXYDataBase::adddm(int dmid, char dm_2name[]) { //添加动漫函数
int s = 0;
ifstream ifile("serchdmx.txt");
if (ifile) { //如果文件能正常打开
ifile >> s; //将文件中的数据输入到内存中
ifile.close();
}
else {
s = 0;
}
DMZXY* p = query(dmid);
if (p == NULL) {
DMZXY X(dmid, dm_2name);
dmx.push_back(X);
s++; //管理员每添加一部动漫,动漫记录加1
ofstream tfile("serchdmx.txt");
tfile << s; //将数据输出到文件中
tfile.close(); //关闭文件
return 1;
}
return 0;
}
DMZXY* DMZXYDataBase::query(int dmid) { //根据动漫编号查询函数
list
for (iter = dmx.begin(); iter != dmx.end(); iter++) {
if (iter->getdm4No() == dmid && iter->getDelTag() == 0)
return &(*iter);
}
return NULL;
}
void DMZXYDataBase::dmdispall() { //输出所有动漫函数
list
if (dmx.empty()) { //如果列表中为空
cout << "\n\n\t\t\t对不起,此时没有动漫!!!" << endl;
}
else {
int s = 0;
ifstream ifile("serchdmx.txt"); //打开文件
if (ifile) { //如果文件打开正常
ifile >> s; //将文件中的记录数输入到内存中
ifile.close();
}
else {
s = 0;
}
cout << "\n\n\t\t\t已有动漫" << s << "部" << endl;
cout << "\n\n\t\t\t动漫编号\t动漫名\t状态" << endl;
for (iter = dmx.begin(); iter != dmx.end(); iter++) {
if (iter->getDelTag() == 0)
iter->dmdisplay();
}
}
}
void DMZXYDataBase::dmdata() { //动漫维护函数
int choice = 1;
int n = 0;
char dmxname[44];
int dmid;
system("cls"); //清屏
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
DMZXY* X;
while (choice != 0) {
cout << "" << endl;
cout << " ┌───────────────────────────────────┐\n";
cout << " │ ★★★★★动漫维护★★★★★ │\n";
cout << " ├────┬────┬────┬───┬───┬───┬────────┤\n";
cout << " │1:新增 │2:更改 │3:删除 │4:查找│5:显示│6:全删│0:返回上一级目录│\n";
cout << " ├────┼────┼────┼───┼───┼───┼────────┤\n";
cout << " │ 请您选择: │\n";
cout << " └───────────────────────────────────┘\n";
cout << "\t";
cin >> choice;
switch (choice) {
case 1:
a:
cout << "\n\n\t\t\t输入动漫编号:";
cin >> dmid;
X = query(dmid); //根据动漫的编号查询
if (X != NULL) {
cout << "\n\n\t\t\t提示:该编号动漫已存在,请重新添加:" << endl;
goto a;
break;
}
cout << "\n\n\t\t\t输入动漫名:";
cin >> dmxname;
adddm(dmid, dmxname); //添加动漫
cout << "\n\n\t\t\t动漫添加成功!!!" << endl;
cout << "\n\n\t\t\t是否继续添加?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto a;
else {
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
continue;
}
break;
case 2: //修改函数
b:
cout << "\n\n\t\t\t输入动漫编号:";
cin >> dmid;
X = query(dmid);
if (X == NULL) {
cout << "\n\n\t\t\t提示:该动漫不存在" << endl;
break;
}
cout << "\n\n\t\t\t请输入新的动漫名:";
cin >> dmxname;
X->setname(dmxname);
cout << "\n\n\t\t\t动漫修改成功!!!" << endl;
cout << "\n\n\t\t\t是否继续修改?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto b;
else {
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
continue;
}
break;
case 3: //删除函数
c:
cout << "\n\n\t\t\t输入动漫编号:";
cin >> dmid;
X = query(dmid);
if (X == NULL) {
cout << "\n\n\t\t\t提示:该动漫不存在" << endl;
break;
}
X->deldm();
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t动漫删除成功!" << endl;
cout << "\n\n\t\t\t是否继续删除?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto c;
else {
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
continue;
}
break;
case 4: //查找函数
d:
cout << "\n\n\t\t\t输入动漫编号:";
cin >> dmid;
X = query(dmid);
if (X == NULL) {
cout << "\n\n\t\t\t提示:该动漫不存在" << endl;
}
system("cls");
system("color 9d");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t动漫编号\t动漫名\t状态" << endl;
X->dmdisplay();
cout << "\n\n\t\t\t动漫查找成功!" << endl;
cout << "\n\n\t\t\t是否继续查找?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto d;
else
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
continue;
break;
case 5: //显示所有动漫
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
dmdispall();
break;
case 6: //删除所有动漫
clear();
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t提示:记录已全部删除!!!" << endl;
break;
default:
if (choice == 0) {
system("cls");
system("color 7e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
break;
}
break;
cout << "\n\n\t\t\t输入错误!!!\n请重新选择:";
break;
}
}
}
class Reader { //读者类
int del_tag; //删除标记 1.已删 2.未删
int read_no; //读者编号
char read_name[44]; //读者名
int borrow_dmu[MaxDM]; //所借动漫
public:
Reader(); //构造函数
Reader(int readid, char readname[]); //重载构造函数
char* getReadName(); //获取读者名
int getReadNo(); //获取读者编号
int getDelTag(); //获取删除标记
int retdm(int dmid); //看完动漫操作
void borrowdm(int bookid); //准备看动漫操作
void setname(char readname[]); //设置读者名
void delread(); //删除动漫读者
void addread(int readid, char readname[]); //增加读者
void readdisplay(); //显示一本读者
};
Reader::Reader() //构造函数
{}
Reader::Reader(int readid, char readname[]) { //重载构造函数
addread(readid, readname);
}
char* Reader::getReadName() {
return read_name; //获得读者姓名
}
int Reader::getReadNo() {
return read_no;
}
int Reader::getDelTag() { //获得删除标记
return del_tag;
}
int Reader::retdm(int dmid) { //还书函数
for (int i = 0; i < MaxDM; i++) { //循环条件是i值小于最大借书数
if (borrow_dmu[i] == dmid) {
borrow_dmu[i] = 0;
return 1;
}
}
return 0;
}
void Reader::borrowdm(int dmid) { //借动漫函数
for (int i = 0; i < MaxDM; i++) {
if (borrow_dmu[i] = 0) {
borrow_dmu[i] = dmid;
return;
}
}
}
void Reader::setname(char readname[]) {
strcpy_s(read_name, readname); //设置读者姓名
}
void Reader::delread() {
del_tag = 1; //设置删除标记的值为1
}
void Reader::addread(int readid, char readname[]) { //添加读者函数
del_tag = 0;
read_no = readid;
strcpy_s(read_name, readname);
for (int i = 0; i < MaxDM; i++)
borrow_dmu[i] = 0;
}
void Reader::readdisplay() { //输出单个读者函数
cout << "\n\n\t\t\t";
cout << setw(6) << read_no << setw(15) << read_name << endl;
}
class ReaderDataBase { //读者库类
list
public:
ReaderDataBase(); //构造函数
~ReaderDataBase(); //析构函数
void clear(); //清除函数
int addread(int readid, char readname[]); //添加读者函数
Reader* query(int readid); //根据读者编号查询函数
void readdata();
void readdispall(); //输出所有读者函数
};
ReaderDataBase::ReaderDataBase() { //构造函数
Reader r; //创建读者类对象
fstream file("read.dat", ios::in);
while (1) {
file.read((char*)&r, sizeof(r));
if (!file)
break;
read.push_back(r);
}
file.close();
}
ReaderDataBase::~ReaderDataBase() { //通过析构函数将数据写入文件
fstream file("read.dat", ios::out | ios::trunc);
list
for (iter = read.begin(); iter != read.end(); iter++) {
if (iter->getDelTag() == 0)
file.write((char*)&(*iter), sizeof(Reader));
}
file.close();
}
void ReaderDataBase::clear() { //清除函数
read.clear();
}
int ReaderDataBase::addread(int readid, char readname[]) { //添加读者函数
Reader* p = query(readid);
if (p == NULL) {
Reader r(readid, readname);
read.push_back(r);
return 1;
}
return 0;
}
Reader* ReaderDataBase::query(int readid) { //查询函数
list
for (iter = read.begin(); iter != read.end(); iter++) {
if (iter->getReadNo() == readid && iter->getDelTag() == 0)
return &(*iter);
}
return NULL;
}
void ReaderDataBase::readdispall() { //输出所有读者
list
if (read.empty()) {
cout << "\n\n\t\t\t对不起,此时没有读者!!!" << endl;
}
else {
cout << "\n\n\t\t\t读者编号\t读者姓名" << endl;
for (iter = read.begin(); iter != read.end(); iter++) {
if (iter->getDelTag() == 0)
iter->readdisplay();
}
}
}
void ReaderDataBase::readdata() { //读者维护
int choice = 1;
int n = 0;
char readname[40];
int readid;
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
Reader* r;
while (choice != 0) {
cout << "" << endl;
cout << "" << endl;
cout << " ┌───────────────────────────────────┐\n";
cout << " │ ★★★★★读者维护★★★★★ │\n";
cout << " ├────┬────┬────┬───┬───┬───┬────────┤\n";
cout << " │1:新增 │2:更改 │3:删除 │4:查找│5:显示│6:全删│0:返回上一级目录│\n";
cout << " ├────┼────┼────┼───┼───┼───┼────────┤\n";
cout << " │ 请您选择: │\n";
cout << " └───────────────────────────────────┘\n";
cout << "\t";
cin >> choice;
switch (choice) {
case 1: //增加读者
a:
cout << "\n\n\t\t\t输入读者编号:";
cin >> readid;
r = query(readid);
if (r != NULL) {
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t提示:该读者已存在" << endl;
goto a;
break;
}
cout << "\n\n\t\t\t输入读者动漫名:";
cin >> readname;
addread(readid, readname);
cout << "\n\n\t\t\t读者添加成功!!!" << endl;
cout << "\n\n\t\t\t是否继续添加?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto a;
else
continue;
break;
case 2: //修改读者
b:
cout << "\n\n\t\t\t输入读者编号:";
cin >> readid;
r = query(readid);
if (r == NULL) {
cout << "\n\n\t\t\t提示:该读者不存在" << endl;
break;
}
cout << "\n\n\t\t\t请输入新的动漫名:";
cin >> readname;
r->setname(readname);
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t读者修改成功!!!" << endl;
cout << "\n\n\t\t\t是否继续修改?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto b;
else
continue;
break;
case 3: //删除读者
c:
cout << "\n\n\t\t\t输入读者编号:";
cin >> readid;
r = query(readid);
if (r == NULL) {
cout << "\n\n\t\t\t提示:该读者不存在" << endl;
break;
}
r->delread();
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t读者删除成功!" << endl;
cout << "\n\n\t\t\t是否继续删除?\t1.是 2.否 3.按其他任意键返回上一级目录" << endl;
cin >> n;
if (n == 1)
goto c;
else
continue;
break;
case 4: //查询读者
cout << "\n\n\t\t\t输入读者编号:";
cin >> readid;
r = query(readid);
if (r == NULL) {
cout << "\n\n\t\t\t提示:该读者不存在" << endl;
break;
}
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
r->readdisplay();
break;
case 5: //显示所有读者
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
readdispall();
break;
case 6: //删除所有读者
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
clear();
cout << "\n\n\t\t\t提示:记录已全部删除!!!" << endl;
break;
default:
if (choice == 0) {
system("cls");
system("color 7a");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
break;
}
break;
cout << "\n\n\t\t\t输入错误!!!\n请重新选择:";
break;
}
}
}
void manager() { //动漫管理函数
int choice = 1;
int dmid, readerid;
system("cls");
system("color 5f");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
DMZXYDataBase dmDB; //动漫库类创建对象
DMZXY* dm; //动漫类创建一个指针对象
ReaderDataBase readerDB; //读者库类创建对象
Reader* read; //读者类创建一个指针对象
while (choice != 0) {
cout << " ┌───────────────────────────────────┐\n";
cout << " │ ★★★★★动漫管理★★★★★ │\n";
cout << " ├──────┬──────┬─────┬─────┬─────────┤\n";
cout << " │1:动漫维护 │ 2:读者维护│3:在看 │ 4.已看 │ 0:返回上一级目录 │\n";
cout << " ├──────┼──────┼─────┼─────┼─────────┤\n";
cout << " │ 请您选择: │\n";
cout << " └───────────────────────────────────┘\n";
cout << "\t";
cin >> choice;
switch (choice) {
case 1: //动漫维护
system("cls");
system("color 5f");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
dmDB.dmdata(); //调用动漫维护函数
break;
case 2:
system("cls");
system("color 5f");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
readerDB.readdata(); //调用读者维护函数
break;
case 3: //在看
cout << "\n\n\t\t\t借动漫\n\n\t\t\t读者编号:";
cin >> readerid;
cout << "\n\n\t\t\t动漫编号:";
cin >> dmid;
read = readerDB.query(readerid);
if (read == NULL) {
cout << "\n\n\t\t\t不存在该读者,不能看!" << endl;
break;
}
dm = dmDB.query(dmid);
if (dm == NULL) {
cout << "\n\n\t\t\t不存在该动漫,不能看!" << endl;
break;
}
if (dm->borrowdm() == 0) {
cout << "\n\n\t\t\t对不起,该动漫已看!" << endl;
break;
}
read->borrowdm(dm->getdm4No());
cout << "\n\n\t\t\t在看动漫成功!!!" << endl;
break;
case 4: //
cout << "\n\n\t\t\t已看\n\n\t\t\t读者编号:";
cin >> readerid;
cout << "\n\n\t\t\t动漫编号:";
cin >> dmid;
read = readerDB.query(readerid);
if (read == NULL) {
cout << "\n\n\t\t\t不存在该读者,不能看" << endl;
break;
}
dm = dmDB.query(dmid);
if (dm == NULL) {
cout << "\n\n\t\t\t不存在该动漫,不能看" << endl;
break;
}
dm->retdm();
read->retdm(dm->getdm4No());
cout << "\n\n\t\t\t已看成功!!!" << endl;
break;
default:
if (choice == 0) {
system("cls");
system("color 5f");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
break;
}
break;
cout << "\n\n\t\t\t输入错误!!!\n请重新选择:";
break;
}
}
}
void login() { //登录函数
DMDataBase dmDB; //动漫管理员类库创建对象
dmDB.dmdata(); //调用动漫管理员维护函数
}
int main() { //主函数
int h;
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "" << endl;
cout << " ┌───────────────────────────────────┐\n";
cout << " │ ★★★★★动漫管理系统★★★★★ │\n";
cout << " ├────────────────┬──────────────────┤\n";
cout << " │ 1:管理员登录 │ 0:退出系统 │\n";
cout << " ├────────────────┼──────────────────┤\n";
cout << " │ 请您选择: │\n";
cout << " └───────────────────────────────────┘\n";
cout << "\t";
cin >> h;
if (h >= 0 && h < 2) {
switch (h) {
case 0: //退出系统
system("cls");
system("color 4e");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "\n\n\t\t\t谢谢光临本动漫管理系统!" << endl;
exit(0);
case 1:
login(); //登录
system("pause");
break;
}
}
else {
system("cls");
system("color 4b");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << "\n\n\t\t\t您的操作是无效的!!!!" << endl;
system("pause");
}
Welcome();
bfsp();
return 0;
}
这是头文件
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define IDI_ICON1 101
#define IDI_ICON2 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
这是资源文件
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/
#undef APSTUDIO_READONLY_SYMBOLS
/
// Chinese (P.R.C.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32
/
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON DISCARDABLE "07.ico"
#ifdef APSTUDIO_INVOKED
/
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Chinese (P.R.C.) resources
/
#ifndef APSTUDIO_INVOKED
/
//
// Generated from the TEXTINCLUDE 3 resource.
//
/
#endif // not APSTUDIO_INVOKED
这个程序用到了音乐、图片、视频文件,需要Easyx库和opencv库,当你使用时,会产生4个相关文件(dat和txt文件)。有图标。
这是运行成功的样子~
【动漫管理系统-------简单的用C++实现,封装了一下~-哔哩哔哩】 https://b23.tv/atQojEb
我调试了一些发现了两个bug
1.音乐名称有特殊字符播放不了!!!!
2.在程序中添加动漫名称时有空格会一直打印动漫编号已存在!停不下来。!!!
有好的想法是非常完美的,因为可以尝试实现她~