#include "ds.h"//自定义的头文件
using namespace std;//c++中指定命名空间
struct books //定义一种图书信息结构体类型
{
int num; //书的数量
string ISBN; //书号
char BookName[MAXSIZE]; //书名
char author[MAXSIZE]; //作者
char publisher[MAXSIZE]; //出版单位
float price;//价格
string data;//出版日期
};
void imput(books &book)
{
int i;
cout<<"请输入"<<book.num<<"本图书的信息,空格分开\n";
cin>>book.num;
for(i=0; i<book.num; i++)
{
cin >> book.ISBN[i] >> book.BookName[i] >> book.author[i] >> book.publisher[i] >> book.price[i] >> book.data[i];
}
for(i=0; i<book.num; i++)
{
cout << book.ISBN[i] << book.BookName[i] << book.author[i] << book.publisher[i] << book.price[i] << book.data[i] <<endl;
}
}
void output(books book)
{
int i;
for (i = 0; i < book.num; i++)
{
cout << book.ISBN[i] << " " << book.BookName[i] << " " << book.author[i] << " " << book.publisher[i] << " " << book.price[i] << book.data[i] << " " <<endl;
}
cout<<"\n";
}
void insertm(books &book) //在最后面依次添加num本图书
{
int i,m;
cout << "需要添加图书信息的本数为:\n ";
cin >> m;
cout << "请输入其信息【依次为书号(ISBN) 书名 作者 出版单位 价格 出版日期(书号不重复,用空格空开】\n ";
for (i = 0; i < m; i++)
{
cin >> book.ISBN[i] >> book.BookName[i] >> book.author[i] >> book.publisher[i] >> book.price[i] >> book.data[i];
}
book.num = book.num + m;
cout << "图书信息添加后为:\n";
output(book);
}
int delete_books(books book)
{
int i,j,choice,BookNumber1,t=0;
char BookName1;
cout<<"进入删除图书系统\n";
cout<<"按书号删除请按1\n";
cout<<"按书名删除请按2\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"请输入你想删除的图书的书号: ";
cin>>BookNumber1;
/*if(lib->size == 0)
cout<<"图书库中无信息,删除失败!"<<endl;*/
for(i=0; i<book.num; i++)
{
if(BookNumber1 == book.ISBN[i])
{
t = i; //记住要删除图书的下标
break;
}
}
cout<<"删除失败,请确认书号是否正确!"<<endl;
if(t != book.num - 1) //判断要删除图书是否为最后一本 即判断t是否为最后一个值
{
for(i=t; i<book.num; i++)
{
book[i] = book[i+1];
}
}
book.num = book.num-1;
case 2:
cout<<"请输入你想删除的图书的书名: ";
cin>>BookName1;
for(i=0; i<book.num; i++)
{
if(BookName1 == book.BookName[i])
{
t = i; //记住要删除图书的下标
}
}
cout<<"删除失败,请确认书名是否正确!"<<endl;
if(t != book.num-1) //判断要删除图书是否为最后一本 即判断t是否为最后一个值
{
for(i=t; i<book.num; i++)
{
book[i] = book[i+1];
}
}
book.num = book.num-1;
}
void change_books(books book)
{
int BookNumber3,i,t=0,choice;
cout<<"请输入要修改信息图书的书号:"<<endl;
cin>>BookNumber3;
for(i=0; i<book.num; i++)
{
if(BookNumber3 == book.ISBN[i])
{
t = i;
break;
}
else
cout<<"无图书信息,请确认书号是否正确!"<<endl;
}
cout<<"请输入需要修改信息的序号:"<<endl;
cout<<"1.书名"<<endl;
cout<<"2.作者"<<endl;
cout<<"3.出版单位"<<endl;
cout<<"4.价格"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"请输入:";
cin>>book.BookName[t];
break;
case 2:
cout<<"请输入:";
cin>>book.author[t];
break;
case 3:
cout<<"请输入:";
cin>>book.publisher[t];
break;
case 4:
cout<<"请输入:";
cin>>book.price[t];
break;
default:
cout<<"输入错误!"<<endl;
}
}
void book_search(books book)
{
int i,j,choice,ISBN2;
char BookName2;
cout<<"进入查询图书系统\n";
cout<<"按书号查询请按1\n";
cout<<"按书名查询请按2\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"请输入你想查询的图书的书号:";
cin>>ISBN2;
for(i=0; i<book.num; i++)
{
if(ISBN2 == book.ISBN[i])
{
cout<<"查询成功\n";
cout<<"该书基本信息为:\n";
cout<<"书名:"<<book.BookName[i]<<" 作者;"<<book.author[i]<<" 出版单位:"<<book.publisher[i]<<" 价格:"<<book.price[i]<<" 出版日期:"<<book.data[i]<<endl;
break;
}
}
cout<<"查询失败,请核对书号是否正确\n";
case 2:
cout<<"请输入你想查询的图书的书名:";
cin>>BookName2;
for(i=0; i<book.num; i++)
{
if(BookName2 == book[i].BookName)
{
cout<<"查询成功\n";
cout<<"该书基本信息为:\n";
cout<<"书名:"<<book.BookName[i]<<" 作者;"<<book.author[i]<<" 出版单位:"<<book.publisher[i]<<" 价格:"<<book.price[i]<<" 出版日期:"<<book.data[i]<<endl;
break;
}
}
cout<<"查询失败,请核对书名是否正确\n";
}
}
void main()
{
books book1;
int i;
cout << "请输入你想进行图书信息管理的图书本数:\n";
cin >> book1.num;
cout << "请输入" << book1.num << "本图书信息 【书号(ISBN) 书名 作者 出版单位 价格 出版日期(书号不重复),用空格空开】: \n"; //完成图书信息输入
for (i = 0; i < book1.num; i++)
{
cin >> book.ISBN >> book.BookName[i] >> book.author[i] >> book.publisher[i] >> book.price[i] >> book.data[i] ; //字符数组进行整体输入
}
cout << "进行图书信息浏览: " << endl;
output(book1);
insertm(book1);
output(book1);
delete_books(book1);
change_books(book1);
book_search(book1);
system("pause");
}
关于#c++#的问题:cout << "请输入" << book1.num << "本图书信息 【书号(ISBN) 书名 作者 出版单位 价格 出版日期(书号不重复)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- threenewbee 2023-03-16 20:56关注
程序整个思路有问题
book.ISBN[i]
这里你似乎是觉得是数组,但是你books中的isbn是string,不是string数组
下面很多都是同理你要先搞清楚books到底代表一本书,还是所有的书
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 TCP的客户端和服务器的互联
- ¥15 VB.NET操作免驱摄像头
- ¥15 笔记本上移动热点开关状态查询
- ¥85 类鸟群Boids——仿真鸟群避障的相关问题
- ¥15 CFEDEM自带算例错误,如何解决?
- ¥15 有没有会使用flac3d软件的家人
- ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
- ¥15 docker实践项目
- ¥15 利用pthon计算薄膜结构的光导纳
- ¥15 海康hlss视频流怎么播放