目录
目录 .................................................................................................................................................. 1
图书管理程序 ................................................................................................................................... 2
源程序:........................................................................................................................................... 2
心得与体会....................................................................................................................................... 7
课设心得: 课设心得 ........................................... 7
课设心得: 课设心得 ................................................... 8
图书管理程序
图书信息应该包含:图书编号、书名、作者姓名、出版社、价格等,请设计一个图书管理程序。该程序具有信息的录入、查询、修改、删除等基本功能。具有下列功能:
1.通过键盘输入图书的基本信息;
2.给定图书编号,查询显示该本图书的信息;
3.给定作者姓名,查询显示所有该作者编写的图书信息;
4.给定出版社,显示该出版社的所有图书信息;
1)给定图书编号,删除该图书的信息;
2)提供一些统计各类信息的功能。
提示:设计一个结构体类型或类类型的一维数组,用来存放图书信息。
源程序:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <fstream.h>
class Book
{
public:
int numble;
char bookname[38];
char author[38];
char press[38];
double price;
void getdetail()
{cout<<" 图书编号: ";
cin>>numble;
cout<<" 书名: ";
cin>>bookname;
cout<<" 作者姓名: ";
cin>>author;
cout<<" 出版社: ";
cin>>press;
cout<<" 价格: ";
cin>>price;
}
void display()
{
cout<<"图书编号 书名 作者姓名 出版社 价格 "<<endl;
}
void print()
{
cout<<" "<<numble<<" "<<bookname<<" "<<author<<" "<<press<<" "<<price<<endl;
}
int getnumble()
{return numble;}
char *getbookname()
{return bookname;}
char *getauthor()
{return author;}
char *getpress()
{
return press;
}
double getprice()
{
return price;
}
};
void mu()
{cout<<" *** **----------------------"<<endl;
cout<<" 图书管理系统"<<endl;
cout<<" ------------------------------------"<<endl; cout<<" 1.) 退出系统 "<<endl; cout<<" 2.) 输入图书信息"<<endl; cout<<" 3.) 显示图书信息"<<endl; cout<<" 4.) 查询图书信息"<<endl; cout<<" 5.) 删除图书信息"<<endl; cout<<" 请选择服务项目:"<<endl;
}
void set()
{
system("cls");
mu();
Book b1;
ofstream outfile("book.txt",ios::app);
b1.getdetail();
outfile.write((char *)&b1,sizeof(b1));
outfile.close();
}
void dis()
{
system("cls");
mu();
Book b1;
ifstream infile("book.txt");
b1.display();
while(infile.read((char *)&b1,sizeof(b1)))
{
b1.print();
}
infile.close();
}
void chaxun()
{
system("cls");
mu();
int numble,x;
char author[38],press[38];
Book b1;
cout<<"1.根据图书编号进行查找\n";
cout<<"2.根据作者姓名进行查找\n";
cout<<"3.根据出版社进行查找\n"; fstream fs("f1.txt",ios::in|ios::out); cin>>x;
if(x==1) // 按图书编号查询
{
cout<<("需要查找的图书编号为:")<<endl;
cin>>numble;
while(true)
{
fs.read((char *)&b1,sizeof(b1));
if(numble==b1.getnumble ())
{
b1.display();
b1.print();
fs.close();
break;
}
}
}
if(x==2) // 按作者姓名查询
{
cout<<("需要查找的作者姓名为:")<<endl;
cin>>author[38];
while(true)
{
fs.read((char *)&b1,sizeof(b1));
if(strcmp(author,b1.getauthor())==0)
{
b1.display();
b1.print();
fs.close();
break;
}
}
}
if(x==3) // 按出版社查询
{
cout<<("需要查找的出版社为:")<<endl;
cin>>press[38];
while(true)
{
fs.read((char *)&b1,sizeof(b1));
if(strcmp(press,b1.getpress())==0)
{
b1.display();
b1.print();
fs.close(); …… 此处隐藏:2825字,全部文档内容请下载后查看。喜欢就下载吧 ……