急求c++实现MySQL数据库图书管理系统报告,只有源代码也可以,万分感谢...
发布网友
发布时间:2022-04-24 16:09
我来回答
共1个回答
热心网友
时间:2022-04-07 23:39
#include<iostream>
#include<fstream>
#include<windows.h>
#include<stdlib.h>
using namespace std;
void mainmenu();
void Manage_Book();
void input_Book();
void input_Reader();
void New_Book();
void Seek_Book();
void Borrow_Manage();
void Borrow_Book();
void Return_Book();
void Output_Message();
void Exit_System();
int u,v=3,k=0;
struct Book
{
char name[20];
int booknumber;
int num_present;
int num_all;
}book[1000];
struct Reader
{
char name[20];
int readernumber;
int card;
}reader[3];
void mainmenu()
{
int Num_Choice1,flag=1;
system("color E");
for(;k<=0;k++)
{
input_Book();
input_Reader();
}
while(flag==1)
{
system("cls");
cout<<"\t\t\t◆◆◆◆◆主菜单◆◆◆◆◆"<<endl
<<"\t\t\t☆ 1.图书管理 ☆"<<endl
<<"\t\t\t☆ 2.借阅管理 ☆"<<endl
<<"\t\t\t☆ 3.输出信息 ☆"<<endl
<<"\t\t\t☆ 4.退出系统 ☆"<<endl
<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cout<<"请输入所需要的服务编码"<<endl;
cin>>Num_Choice1;
switch(Num_Choice1)
{
case 1:
Manage_Book();
break;
case 2:
Borrow_Manage();
break;
case 3:
Output_Message();
break;
case 4:
Exit_System();
flag=0;
break;
default:
flag=0;
cout<<"输入有误!!"<<endl;
}
}
}
void Manage_Book()
{
int flag1=1,Num_Choice2;
system("cls"); while(flag1==1)
{
cout<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl
<<"\t\t\t☆ 1.新书入库 ☆"<<endl
<<"\t\t\t☆ 2.图书查询 ☆"<<endl
<<"\t\t\t☆ 3.返回主菜单 ☆"<<endl
<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cin>>Num_Choice2;
switch(Num_Choice2)
{
case 1:
flag1=2;
New_Book();
break;
case 2:
flag1=2;
Seek_Book();
break;
case 3:
mainmenu();
default:
flag1=1;
cout<<"输入有误!"<<endl;
system("pause");
system("cls");
}
}}
void input_Book()
{
cout<<"请依照提示输入现有的三本图书的信息:"<<endl;
for(int i=0;i<3;i++)
{
cout<<"书名:"<<endl;
cin>>book[i].name;
cout<<"书号:"<<endl;
cin>>book[i].booknumber;
cout<<"库存量:"<<endl;
cin>>book[i].num_all;
cout<<"现存量:"<<endl;
cin>>book[i].num_present;
}
}
void New_Book()
{
system("cls");
int j;
char newbook_name[20];
cout<<"请输入新书书名:"<<endl;
cin>>newbook_name;
for(j=0;j<1000;j++)
{
if(strcmp(newbook_name,book[j].name)==0)
{
book[j].num_all++;
book[j].num_present++;
break;
}
}
if(j==1000)
{
cout<<"请为此新书编号:"<<endl;
v++;
cin>>book[v].booknumber;
strcpy(book[v].name,newbook_name);
book[v].num_all=1;
book[v].num_present=1;
}
else cout<<"已有此书,库存量加一"<<endl;
system("pause");
}
void Seek_Book()
{
system("cls");
int k,booknumber;
cout<<"请输入所要查询的书号:"<<endl;
cin>>booknumber;
for(k=0;k<1000;k++)
{
if(book[k].booknumber==booknumber)
{
cout<<"书号:"<<booknumber<<endl;
cout<<"书名:"<<book[k].name<<endl;
cout<<"库存量:"<<book[k].num_all<<endl;
cout<<"现存量:"<<book[k].num_present<<endl;
system("pause");
break;
}
}
if(k==1000)
{
cout<<"未找到此书!!"<<endl;
system("pause");
}
}
void Borrow_Manage()
{
int flag=1;
system("cls");
int Num_Choice3;
while(flag==1)
{
cout<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl
<<"\t\t\t☆ 1.借书登记 ☆"<<endl
<<"\t\t\t☆ 2.还书管理 ☆"<<endl
<<"\t\t\t☆ 3.返回主菜单 ☆"<<endl
<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cin>>Num_Choice3;
switch(Num_Choice3)
{
case 1:
flag=2;
Borrow_Book();
break;
case 2:
flag=2;
Return_Book();
break;
case 3:
mainmenu();
default:
flag=1;
cout<<"输入有误!!"<<endl;
system("pause");
}
system("cls");
}
}
void input_Reader()
{
system("cls");
cout<<"请依照提示输入现有的三位读者的信息:"<<endl;
for(int m=0;m<3;m++)
{
cout<<"姓名:"<<endl;
cin>>reader[m].name;
cout<<"编号:"<<endl;
cin>>reader[m].readernumber;
reader[m].card=0;
}
}
void Borrow_Book()
{
system("cls");
char reader_name[20];
int n,book_number;
cout<<"请输入读者姓名:"<<endl;
cin>>reader_name;
for(n=0;n<3;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
{
if(reader[n].card!=0)
{
cout<<"已借书,不能再借,请按任意键返回"<<endl;
system("pause");
mainmenu();
}
else
break;
}
}
if(n==3)
{
cout<<"无此读者!输入有误!!按任意键返回主菜单"<<endl;
system("pause");
mainmenu();
}
cout<<"请输入所借图书书号:"<<endl;
cin>>book_number;
for(n=0;n<v;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
reader[n].card=book_number;
}
for(n=0;n<v;n++)
{
if(book[n].booknumber==book_number)
{
if(book[n].num_present==0)
{
cout<<"该书已经被借完,请按任意键返回"<<endl;
system("pause");
for(n=0;n<v;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
reader[n].card=0;
}
mainmenu();
}
else
{
book[n].num_present--;
cout<<"借书成功,请按任意键返回"<<endl;
system("pause");
break;
}
}
}
if(n==v)
{
for(n=0;n<v;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
reader[n].card=0;
}
cout<<"所输入的书号不存在,请按任意键返回主菜单"<<endl;
system("pause");
mainmenu();
}
}void Return_Book()
{
system("cls");
int j;
char reader_name[20];
int book_number;
cout<<"请输入读者姓名:"<<endl;
cin>>reader_name;
for(j=0;j<3;j++)
{
if(strcmp(reader_name,reader[j].name)==0)
break;
}
if(j==3)
{
cout<<"无此读者!输入有误!!按任意键返回主菜单"<<endl;
system("pause");
mainmenu();
}
cout<<"请输入所还图书书号:"<<endl;
cin>>book_number;
for(j=0;j<3;j++)
{
if(strcmp(reader_name,reader[j].name)==0)
{
if(book_number==reader[j].card)
{
reader[j].card=0;
for(j=0;j<v;j++)
{
if(book[j].booknumber==book_number)
{
book[j].num_present++;
cout<<"还书成功,请按任意键返回"<<endl;
system("pause");
break;
}
}
}
else
{
cout<<"该读者未借此书"<<endl;
system("pause");
}
}
if(j==v)
cout<<"所输入的书号不存在:"<<endl;
}
}
void Output_Message()
{
system("cls");
int q;
cout<<"以下是图书信息"<<endl<<endl;
for(q=0;q<v;q++)
{
cout<<"书号:"<<book[q].booknumber<<'\t';
cout<<"书名:"<<book[q].name<<'\t';
cout<<"库存量:"<<book[q].num_all<<'\t';
cout<<"现存量:"<<book[q].num_present<<endl;
}
cout<<"以下是读者信息"<<endl<<endl;
for(q=0;q<3;q++)
{
cout<<"姓名:"<<reader[q].name<<'\t'
<<"编号:"<<reader[q].readernumber<<'\t'
<<"所借书号:"<<reader[q].card<<endl;
}
system("pause");
}
void Exit_System()
{
system("cls");
cout<<"欢迎下次使用,谢谢"<<endl;
system("pause");
}
void main()
{
mainmenu();
}追问谢谢🙏可是这个用到mysql了吗