📄 sources.cpp
字号:
{
ofstream output_book("Bookmanagement.txt");
cout<<"是否将修改写入文件?(Y/N)"<<endl;
char deci;
cin>>deci;
if(deci =='y' ||deci =='Y')
{
output_book<<"序号 ISBN 书名 作者 出版社 库存数 单价 入库时间 出库时间\n";
head=head->next;//跳过第一行
while(head)
{
output_book<<head->sequenceNum<<"\t"<<head->ISBN<<"\t"<<head->BookName<<"\t"<<head->author<<"\t"<<head->press<<"\t"<<head->store_number<<"\t"<<head->price<<"\t"<<head->date_of_in<<"\t"<<head->date_of_out<<"\n";
head=head->next;
}
cout<<"写入完毕!"<<endl;
output_book.close();
}
}
char decision;
cout<<"是否继续?(Y/N):"<<endl;
cin>>decision;
if(decision =='y' ||decision =='Y')menu();
else cout<<"谢谢使用!"<<endl;
}
void Modify()
{
cout<<"请选择要修改的ISBN编号:"<<endl;
string ISBN_of_Modify;
cin>>ISBN_of_Modify;
LNode *x= CreateDefaultLink();
LNode *head=x;
int exist_tag=0; //图书存在识别标志
while(x!=NULL && (int)x->store_number)
{
if( ISBN_of_Modify.compare(x->ISBN)==0)//判断入库图书是否已经存在,使用ISBN判别
{
cout<<endl;
cout<<"此书书库中存在"<<endl;
cout<<x->ISBN<<"\t"<<x->BookName<<"\t"<<x->author<<"\t"<<x->press<<"\t"<<x->price<<"\t"<<x->date_of_in<<endl;
cout<<"请依次按照顺序输入图书的信息: ISBN编号 书名 作者 出版社 单价"<<endl;
char t[60];
cin>>x->ISBN;
cin>>x->BookName;
cin.get();
gets(t); x->author=t;
cin>>x->press;
cin.get();
gets(t);
x->price=atof(t);
x->date_of_in=get_date();
cout<<"您输入的图书的信息是:"<<endl;
cout<<"ISBN编号 书名 作者 出版社 单价"<<endl;
cout<<x->ISBN<<"\t"<<x->BookName<<"\t"<<x->author<<"\t"<<x->press<<"\t"<<x->price<<"\t"<<x->date_of_in<<endl;
exist_tag=1; //图书存在识别标志.
break;
}
x=x->next;
}
if(exist_tag==0)
{
cout<<"此书书库中不存在!"<<endl;
}
//写入文件,因为是文本模式打开的,所以要全部重写文件。
else
{
ofstream output_book("Bookmanagement.txt",ios::trunc);
cout<<"是否将修改写入文件?(Y/N)"<<endl;
char deci;
cin>>deci;
if(deci =='y' ||deci =='Y')
{
output_book<<"序号 ISBN 书名 作者 出版社 库存数 单价 入库时间 出库时间\n";
head=head->next;//跳过第一行
while(head)
{
output_book<<head->sequenceNum<<"\t"<<head->ISBN<<"\t"<<head->BookName<<"\t"<<head->author<<"\t"<<head->press<<"\t"<<head->store_number<<"\t"<<head->price<<"\t"<<head->date_of_in<<"\t"<<head->date_of_out<<"\n";
head=head->next;
}
cout<<"写入完毕!"<<endl;
output_book.close();
}
}
char decision;
cout<<"是否继续?(Y/N):"<<endl;
cin>>decision;
if(decision =='y' ||decision =='Y')menu();
else cout<<"谢谢使用!"<<endl;
}
void sub_menu_Query()
{
cout<<"* 选择一个查询方式 *"<<endl;
cout<<"* <1> 按 书名 查询 *"<<endl;
cout<<"* <2> 按 ISBN 序列号查询 *"<<endl;
cout<<"* <3> 按 作者 查询 *"<<endl;
cout<<"* <4> 按 出版社 查询 *"<<endl;
cout<<"* <5> 清屏 *"<<endl;
cout<<"* <6> 返回上级菜单 *"<<endl;
cout<<"********************************************************************************"<<endl;
cout<<endl;
char choice='5';
cout<<" 请输入您的选择(1-6):"<<endl;
cin>>choice;
if (int(choice)<49 || int(choice)>54)
{
cout<<" 输入不正确!请重新再输入一个1至6之间的整数:"<<endl;
cin>>choice;
}
switch(choice)
{
case '1':
{
cout<<"请输入要查询的 书名(不提供模糊查询,请输入准确关键字) :"<<endl;
string name;
cin.clear(); //更改cin的状态标示符
cin.sync(); //清除输入缓存区的数据流
getline(cin,name,'\n');
query (1,name);
break;
}
case '2':
{
cout<<" 请输入要查询的 ISBN 编号(不提供模糊查询,请输入准确关键字):"<<endl;
string ISBN;
cin.clear(); //更改cin的状态标示符
cin.sync(); //清除输入缓存区的数据流
getline(cin,ISBN,'\n');
query (2,ISBN);
break;
}
case '3':
{
cout<<" 请输入要查询的 作者(不提供模糊查询,请输入准确关键字):"<<endl;
string author;
cin.clear(); //更改cin的状态标示符
cin.sync(); //清除输入缓存区的数据流
getline(cin,author,'\n');
query (3,author);
break;
}
case '4':
{
cout<<" 请输入要查询的 出版社(不提供模糊查询,请输入准确关键字):"<<endl;
string press;
cin.clear(); //更改cin的状态标示符
cin.sync(); //清除输入缓存区的数据流
getline(cin,press,'\n');
query (4,press);
break;
}
case '5':system("cls");sub_menu_Query();break;
case '6':menu();
}
cout<<"是否需要打印全部图书信息?(y/n)"<<endl;
char decision;
cin>>decision;
if(decision =='y' ||decision =='Y')
{
LNode *head=CreateDefaultLink();
cout<<"序号 ISBN编号 书名 作者 出版社 "<<endl;
head=head->next;//跳过第一行
while(head)
{
cout<<head->sequenceNum<<" "<<head->ISBN<<" "<<head->BookName<<" "<<head->author<<" "<<head->press<<"\n";
head=head->next;
}
cout<<endl;
}
cout<<"是否继续查询?(Y/N):"<<endl;
cin>>decision;
if(decision =='y' ||decision =='Y')sub_menu_Query();
else cout<<"谢谢使用!"<<endl;
}
void query(int choice_of_query,string query_keyword)
{
LNode * t=CreateDefaultLink();
switch (choice_of_query)
{
case 1:
{
int find_tag=0;
while(t && (int)t->store_number)
{
if( query_keyword.compare(t->BookName)==0)
{
cout<<t->sequenceNum<<"\t"<<t->ISBN<<"\t"<<"《"<<t->BookName<<"》"<<"\t"<<t->author<<"\t"<<t->press<<"\t"<<t->price<<endl;
cout<<endl;
find_tag=1;
}
t=t->next;
}
if (find_tag==0)
{
cout<<"对不起,未找到您所要求的图书!"<<endl;
break;
}
break;
}
case 2:
{
int find_tag=0;
while(t && (int)t->store_number)
{
if( query_keyword.compare(t->ISBN)==0)
{
cout<<t->sequenceNum<<"\t"<<t->ISBN<<"\t"<<"《"<<t->BookName<<"》"<<"\t"<<t->author<<"\t"<<t->press<<"\t"<<t->price<<endl;
cout<<endl;
find_tag=1;
}
t=t->next;
}
if (find_tag==0)
{
cout<<"对不起,未找到您所要求的图书!"<<endl;
break;
}
break;
}
case 3:
{
int find_tag=0;
while(t && (int)t->store_number)
{
if( query_keyword.compare(t->author)==0)
{
cout<<t->sequenceNum<<"\t"<<t->ISBN<<"\t"<<"《"<<t->BookName<<"》"<<"\t"<<t->author<<"\t"<<t->press<<"\t"<<t->price<<endl;
cout<<endl;
find_tag=1;
}
t=t->next;
}
if (find_tag==0)
{
cout<<"对不起,未找到您所要求的图书!"<<endl;
break;
}
break;
}
case 4:
{
int find_tag=0;
while(t && (int)t->store_number)
{
if( query_keyword.compare(t->press)==0)
{
cout<<t->sequenceNum<<"\t"<<t->ISBN<<"\t"<<"《"<<t->BookName<<"》"<<"\t"<<t->author<<"\t"<<t->press<<"\t"<<t->price<<endl;
cout<<endl;
find_tag=1;
}
t=t->next;
}
if (find_tag==0)
{
cout<<"对不起,未找到您所要求的图书!"<<endl;
break;
}
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -