求纯c语言编写的 图书信息管理系统 a~
图书信息包括:登录号、书名、作者名、分类号、出版单位、出版时间、价格等。试设计一图书信息管理系统,使之能提供以下功能:系统以菜单方式工作v图书信息录入功能(图书信息用文件...
图书信息包括:登录号、书名、作者名、分类号、出版单位、出版时间、价格等。试设计一图书信息管理系统,使之能提供以下功能:
系统以菜单方式工作v
图书信息录入功能(图书信息用文件保存)--输入v
图书信息浏览功能--输出v
查询和排序功能:(至少一种查询方式)--算法v
l 按书名查询
l 按作者名查询
图书信息的删除与修改(可选项)v
小弟的设计作业 明天中午就要交了 - -急呀。。 展开
系统以菜单方式工作v
图书信息录入功能(图书信息用文件保存)--输入v
图书信息浏览功能--输出v
查询和排序功能:(至少一种查询方式)--算法v
l 按书名查询
l 按作者名查询
图书信息的删除与修改(可选项)v
小弟的设计作业 明天中午就要交了 - -急呀。。 展开
推荐于2016-01-19
展开全部
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
class controlloer //图书管理员
{
private:
int number;
int age;
char name[20];
public:
controlloer();
controlloer(int c,int a,char b[20] );
int getnumber();
int getage();
char *getname();
void reworkage(int i);
void reworkname(char a[20]);
};
controlloer::controlloer()
{
number=0;
char b[20]="no one";
age=0;
strcpy(name,b);
}
controlloer::controlloer(int c,int a,char b[20])
{
number=c;
age=a;
strcpy(name,b);
}
int controlloer::getage()
{return age;}
char *controlloer::getname()
{return name;}
int controlloer::getnumber()
{return number;}
void controlloer::reworkage(int i)
{age=i;}
void controlloer::reworkname(char a[20])
{strcpy(name,a);}
class reader //读者(学生,老师)
{
private:
int number;
int age;
char name[20];
char zhiye[20];
char borrowbook[20];
public:
reader();
reader(int c,int a,char b[20],char d[20],char e[20]);
int getnumber();
int getage();
char *getzhiye();
char *getname();
char * getborrowbook();
void reworkborrowbook(char a[20]);
};
reader::reader()
{
char a[20]="没有人";
char b[20]="无职称";
char c[20]="没有借书";
number=0;
age=0;
strcpy(name,a);
strcpy(zhiye,b);
strcpy(borrowbook,c);
}
reader::reader(int a,int c,char b[20],char d[20],char e[20])
{
number=a;
age=c;
strcpy(name,b);
strcpy(zhiye,d);
strcpy(borrowbook,e);
}
int reader::getnumber(){return number;}
int reader::getage(){return age;}
char *reader::getzhiye(){return zhiye;}
char *reader::getname(){return name;}
char * reader::getborrowbook(){return borrowbook;}
void reader::reworkborrowbook(char a[20]){strcpy(borrowbook,a);}
struct book //图书
{
int num;
char name[20];
char people[20];
};
void store() //存入图书信息
{
int i,c,b;
char a[20],d[20];
ifstream file("num.txt");
file>>b;
file.close();
cout<<"现有的图书个数:";
cout<<b<<endl;
cout<<"请输入你要输入的图书信息个数:"<<endl;
cin>>c;
book *shu=new book[c];
cout<<"输入图书信息(编号,名字,作者名:)"<<endl;
for(i=0;i<c;i++)
{
cin>>shu[i].num;
cin>>a>>d;
strcpy(shu[i].name,a);
strcpy(shu[i].people,d);
b++;
}
ofstream outfile("stu.txt",ios_base::app);
for(i=0;i<c;i++)
{
outfile.write((char *)&shu[i],sizeof(shu[i]));
}
outfile.close();
cout<<"存入成功!"<<endl;
ofstream tfile("num.txt");
tfile<<b;
tfile.close();
}
void outbook() //输出图书信息
{
int i,h,j,g,z;
char k ;
ifstream tfile("num.txt");
if(!tfile)
{
cout<<" 文件不存在! ";
tfile.close();
cout<<"你是否想创建(输入Y或N)";
cin>>k;
if(k=='N') exit(0);
else {ofstream tfile("num.txt");g=0;tfile<<g;}
}
else tfile>>g;
cout<<"本图书馆已经有"<<g<<"本图书"<<endl;
if(g==0)
{cout<<"图书馆里没有书!"<<endl;exit(0);}
else
{ book *shu=new book[g];
ifstream is("stu.txt",ios_base::binary);
if(is)
{
for(i=0;i<g;i++)
{
is.read((char *)&shu[i],sizeof(shu[i]));
}
for(i=0;i<g;i++)
{
cout<<"编号 名字 作者名"<<endl;
cout<<shu[i].num<<" "<<shu[i].name<<" "<<shu[i].people<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
ifstream file("readernum.txt");
if(file) { file>>z; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<z<<endl;
cout<<"输入你的编号:";
cin>>j;
cout<<"你想借哪本书(输入编号):";
cin>>h;
reader *people=new reader[z];
ifstream out("reader.txt",ios_base::binary);
if(out)
{
for(i=0;i<z;i++)
{
out.read((char *)&people[i],sizeof(people[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
out.close();
people[j-1].reworkborrowbook(shu[h-1].name);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[j-1].getnumber()<<" "<<people[j-1].getage()<<" "<<people[j-1].getname()<<" "<<people[j-1].getzhiye()<<" "<<people[j-1].getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::binary);
for(i=0;i<z;i++)
{
outfile.write((char *)&people[i],sizeof(people[i]));}
outfile.close();
}
cout<<"借阅成功!";
}
void controller() //图书管理员信息
{
int b,i,d,h=0;
ifstream file("controlloernum.txt");
if(file) { file>>b; file.close();cout<<"图书管理员个数:"<<b<<endl;}
else
{
cout<<"没有图书管信息理员"<<endl;
cout<<"你是否想创建(请输入Y或N):";
cin>>d;
if(d='y') {ofstream infile("controlloernum.txt");infile<<h;exit(0);}
else exit(0);
}
ifstream is("controlloer.txt",ios_base::binary);
if(is)
{
controlloer *bookpeople=new controlloer[b];
for(i=0;i<b;i++)
{
is.read((char *)&bookpeople[i],sizeof(bookpeople[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople[i].getnumber()<<" "<<bookpeople[i].getage()<<" "<<bookpeople[i].getname()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
cout<<"没有这个文件夹"<<endl;
cout<<"你是否想创建(请输入Y或N):";
cin>>d;
if(d='y') {ofstream infile("controlloer.txt");exit(0);}
else exit(0);
}
is.close();
}
void libary() //图书馆的总信息
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"学校图书馆由本部图书馆及彭州校区图书馆组成.馆舍面积41048平方米";
cout<<" (其中现有馆舍面积11578 平方米,在建图书馆馆舍面积29470平方米),";
cout<<"各院系资料室面积1120平方米。学校拥有纸质文献198万余册, ";
cout<<"生均81.17册,电子文献161.7万余种。近三年校图书馆每年进书量均超过15万册."<<endl;
}
void storecontroller() //存入新的管理员的信息
{
int i,b,c,h=0;
char a[20],d;
ifstream file("controlloernum.txt");
if(file)
{
file>>b; file.close();cout<<"已有的图书管理员个数:";
cout<<b<<endl;
}
else
{
cout<<"没有图书管信息理员"<<endl;
cout<<"你是否想创建(请输入y或n):";
cin>>d;
if(d=='y')
{ofstream infile("controlloernum.txt");infile<<h;infile.close();b=0;}
else exit(0) ;
}
ofstream outfile("controlloer.txt",ios::app);
cout<<"请输入图书管理员的编号和年龄,名字:";
cin>>c>>i>>a;
controlloer bookpeople(c,i,a);
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople.getnumber()<<" "<<bookpeople.getage()<<" "<<bookpeople.getname()<<endl;
outfile.write((char *)&bookpeople,sizeof(bookpeople));
outfile.close();
b++;
ofstream tfile("controlloernum.txt");
tfile<<b;
tfile.close();
cout<<"保存成功!";
}
void reworkcontrolloer() ///修改图书管理员
{
int i,b,h,j,g;
char d[20];
ifstream file("controlloernum.txt");
if(file) { file>>b; file.close();}
else {cout<<"没有图书管信息理员"; exit(0);}
cout<<"已有的图书管理员个数:";
cout<<b<<endl;
controlloer *bookpeople=new controlloer[b];
ifstream is("controlloer.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&bookpeople[i],sizeof(bookpeople[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople[i].getnumber()<<" "<<bookpeople[i].getage()<<" "<<bookpeople[i].getname()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"请输入你要修改的管理员编号:";
cin>>h;
cout<<"输入年龄,名字:";
cin>>g>>d;
bookpeople[h-1].reworkage(g);
bookpeople[h-1].reworkname(d);
cout<<"该了后的名字:"<<bookpeople[h-1].getname();
ofstream tfile("controlloer.txt",ios_base::binary);
for(j=0;j<b;j++)
{
tfile.write((char *)&bookpeople[j],sizeof(bookpeople[j]));
}
tfile.close();
}__page_break__
void storereader() //存入读者信息
{
int i,b,c,h,l=1;
char f;
char a[20],d[20],e[20];
ifstream file("readernum.txt");
if(file) { file>>b; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<b<<endl;
cout<<"如果你想重新存入(输入y或n):";
cin>>f;
if(f=='n')
{
while(l==1)
{ cout<<"请输入读者的编号和年龄,名字,职业,借书情况:";
cin>>c>>i>>a>>d>>e;
reader people(c,i,a,d,e);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people.getnumber()<<" "<<people.getage()<<" "<<people.getname()<<" "<<people.getzhiye()<<" "<<people.getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::app);
outfile.write((char *)&people,sizeof(people));
outfile.close();
b++;
cout<<"你还要添加,请按1,不添按0:";
cin>>h;
if(h==1) l=1;
if(h==0) l=0;
}
ofstream tfile("readernum.txt");
tfile<<b;
tfile.close();
cout<<"保存成功!";
}
else
{
int g=0;
cout<<"请输入读者的编号和年龄,名字,职业,借书情况:";
cin>>c>>i>>a>>d>>e;
reader people(c,i,a,d,e);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people.getnumber()<<" "<<people.getage()<<" "<<people.getname()<<" "<<people.getzhiye()<<" "<<people.getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::trunc );
outfile.write((char *)&people,sizeof(people));
outfile.close();
g++;
ofstream file("readernum.txt");
file<<g;
cout<<g;
file.close();
cout<<"保存成功!";
}
}
void reseachallread() //读者的总信息
{
int i,b;
ifstream file("readernum.txt");
if(file) { file>>b; file.close();}
else { cout<<"没有文件";exit(0);}
cout<<"已有的读者个数:";
cout<<b<<endl;
reader *people=new reader[b];
ifstream is("reader.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&people[i],sizeof(people[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[i].getnumber()<<" "<<people[i].getage()<<" "<<people[i].getname()<<" "<<people[i].getzhiye()<<" "<<people[i].getborrowbook()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
}
void choicecontroll() //管理员
{
int q,l=1,i,h;
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"请输入密码:";
cin>>i;
while(l)
{
if(i==12)
{ system("cls");
system("color 3e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"*****"<<"0,退出."<<" ******"<<endl;
cout<<" "<<"*****" <<"1,查询图书馆管理员的信息"<<" ******"<<endl;
cout<<" "<<"*****" <<"2,存入新的管理员信息. "<<" ******"<<endl;
cout<<" "<<"*****" <<"3,存入图书的信息"<<" ******"<<endl;
cout<<" "<<" *****" <<"4,修改图书管理员的信息"<<" ******"<<endl;
cout<<" "<<" *****" <<"5,存入读者的信息 "<<" ******"<<endl;
cout<<" "<<" *****" <<"6,查询读者的总信息(借阅情况)"<<" ******"<<endl;
cout<<"请选择执行的操作:";
cin>>q;
if(q>=0&&q<7)
{
switch(q)
{
case 0:
l=0;
break;
case 1:controller();
system("pause");
break;
case 2:storecontroller();
system("pause");
break;
case 3:store() ;
system("pause");
break;
case 4:reworkcontrolloer();
system("pause");
break;
case 5:storereader();
system("pause");
break;
case 6:reseachallread();
system("pause");
break;
}
}
else
{
system("cls");
system("color 4e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"输入错误请重新输入!"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
system("pause");
}
}
else
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<" 密码错误"<<endl;
cout<<" "<<" 请输入正确的密码!"<<endl;
cout<<" "<<"退出,请按0,不退出,按1"<<endl;
cin>>h;
if(h==0) l=0;
if(h==1)
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"请输入密码:";
cin>>i;
}
}
}
}
void researchbook()
{
int i,g,h=0;
char a[20];
ifstream tfile("num.txt");
tfile>>g;
cout<<"本图书馆已经有"<<g<<"本图书"<<endl;
book *shu=new book[g];
if(g==0)cout<<"图书馆里没有书!"<<endl;
else
{
ifstream is("stu.txt",ios_base::binary);
if(is)
{
for(i=0;i<g;i++)
{
is.read((char *)&shu[i],sizeof(shu[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"你要查找的书的名字:";
cin>>a;
for(i=0;i<g;i++)
{
if(strcmp(shu[i].name,a)==0)
{
cout<<"编号 名字 作者名"<<endl;
cout<<shu[i].num<<" "<<shu[i].name<<" "<<shu[i].people<<endl;
h++;
}
}
if(h==0)cout<<"没有你要找的书!!";
}
}
void reseachreader() //查询读者的信息
{
int i,b,h=0;
char a[20];
ifstream file("readernum.txt");
if(file) { file>>b; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<b<<endl;
reader *people=new reader[b];
ifstream is("reader.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&people[i],sizeof(people[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"请输入你要查找读者的名字:";
cin>>a;
for(i=0;i<b;i++)
{
if(strcmp(people[i].getname(),a)==0)
{
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[i].getnumber()<<" "<<people[i].getage()<<" "<<people[i].getname()<<" "<<people[i].getzhiye()<<" "<<people[i].getborrowbook()<<endl;
h++;
}
}
if(h==0)cout<<"没有这个读者!";
}
void choicepeople() //学生,老师
{
int i;
char l='y';
while(l=='y')
{
system("cls");
system("color 3b");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"******"<<"0,退出."<<"******"<<endl;
cout<<" "<<"******"<<"1,输出图书信息. "<<"******"<<endl;
cout<<" "<<"******"<<"2,查询图书馆的总信息."<<"******"<<endl;
cout<<" "<<"******"<<"3,查询图书."<<"******"<<endl;
cout<<" "<<"******"<<"4,查询读者的信息."<<"******"<<endl;
cout<<"请选择执行的操作:";
cin>>i;
switch(i)
{
case 0: l='n';
break;
case 1:outbook();
system("pause");
break;
case 2:libary();
system("pause");
break;
case 3:researchbook();
system("pause");
break;
case 4:reseachreader();
system("pause");
break;
}
}
}
void main()
{
int h,l=1;
while(l)
{
system("cls");
system("color 1a");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"图书管理系统"<<endl;
cout<<" -------设计者:计算机学院06级2班卢克波"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"0.退出"<<endl;
cout<<" "<<"1.管理员"<<endl;
cout<<" "<<"2.其他人(学生,老师)"<<endl;
cout<<"请选择执行的操作:";
cin>>h;
if(h>=0&&h<3)
{
switch(h)
{
case 0:cout<<"欢迎参阅本图书馆!"<<endl;exit(0);
case 1:
choicecontroll();
system("pause");
break;
case 2:
choicepeople();
system("pause");
break;
}
}
else
{
system("cls");
system("color 4e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"输入错误请重新输入!"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
system("pause");
}
}
}
#include<string.h>
#include<fstream>
using namespace std;
class controlloer //图书管理员
{
private:
int number;
int age;
char name[20];
public:
controlloer();
controlloer(int c,int a,char b[20] );
int getnumber();
int getage();
char *getname();
void reworkage(int i);
void reworkname(char a[20]);
};
controlloer::controlloer()
{
number=0;
char b[20]="no one";
age=0;
strcpy(name,b);
}
controlloer::controlloer(int c,int a,char b[20])
{
number=c;
age=a;
strcpy(name,b);
}
int controlloer::getage()
{return age;}
char *controlloer::getname()
{return name;}
int controlloer::getnumber()
{return number;}
void controlloer::reworkage(int i)
{age=i;}
void controlloer::reworkname(char a[20])
{strcpy(name,a);}
class reader //读者(学生,老师)
{
private:
int number;
int age;
char name[20];
char zhiye[20];
char borrowbook[20];
public:
reader();
reader(int c,int a,char b[20],char d[20],char e[20]);
int getnumber();
int getage();
char *getzhiye();
char *getname();
char * getborrowbook();
void reworkborrowbook(char a[20]);
};
reader::reader()
{
char a[20]="没有人";
char b[20]="无职称";
char c[20]="没有借书";
number=0;
age=0;
strcpy(name,a);
strcpy(zhiye,b);
strcpy(borrowbook,c);
}
reader::reader(int a,int c,char b[20],char d[20],char e[20])
{
number=a;
age=c;
strcpy(name,b);
strcpy(zhiye,d);
strcpy(borrowbook,e);
}
int reader::getnumber(){return number;}
int reader::getage(){return age;}
char *reader::getzhiye(){return zhiye;}
char *reader::getname(){return name;}
char * reader::getborrowbook(){return borrowbook;}
void reader::reworkborrowbook(char a[20]){strcpy(borrowbook,a);}
struct book //图书
{
int num;
char name[20];
char people[20];
};
void store() //存入图书信息
{
int i,c,b;
char a[20],d[20];
ifstream file("num.txt");
file>>b;
file.close();
cout<<"现有的图书个数:";
cout<<b<<endl;
cout<<"请输入你要输入的图书信息个数:"<<endl;
cin>>c;
book *shu=new book[c];
cout<<"输入图书信息(编号,名字,作者名:)"<<endl;
for(i=0;i<c;i++)
{
cin>>shu[i].num;
cin>>a>>d;
strcpy(shu[i].name,a);
strcpy(shu[i].people,d);
b++;
}
ofstream outfile("stu.txt",ios_base::app);
for(i=0;i<c;i++)
{
outfile.write((char *)&shu[i],sizeof(shu[i]));
}
outfile.close();
cout<<"存入成功!"<<endl;
ofstream tfile("num.txt");
tfile<<b;
tfile.close();
}
void outbook() //输出图书信息
{
int i,h,j,g,z;
char k ;
ifstream tfile("num.txt");
if(!tfile)
{
cout<<" 文件不存在! ";
tfile.close();
cout<<"你是否想创建(输入Y或N)";
cin>>k;
if(k=='N') exit(0);
else {ofstream tfile("num.txt");g=0;tfile<<g;}
}
else tfile>>g;
cout<<"本图书馆已经有"<<g<<"本图书"<<endl;
if(g==0)
{cout<<"图书馆里没有书!"<<endl;exit(0);}
else
{ book *shu=new book[g];
ifstream is("stu.txt",ios_base::binary);
if(is)
{
for(i=0;i<g;i++)
{
is.read((char *)&shu[i],sizeof(shu[i]));
}
for(i=0;i<g;i++)
{
cout<<"编号 名字 作者名"<<endl;
cout<<shu[i].num<<" "<<shu[i].name<<" "<<shu[i].people<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
ifstream file("readernum.txt");
if(file) { file>>z; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<z<<endl;
cout<<"输入你的编号:";
cin>>j;
cout<<"你想借哪本书(输入编号):";
cin>>h;
reader *people=new reader[z];
ifstream out("reader.txt",ios_base::binary);
if(out)
{
for(i=0;i<z;i++)
{
out.read((char *)&people[i],sizeof(people[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
out.close();
people[j-1].reworkborrowbook(shu[h-1].name);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[j-1].getnumber()<<" "<<people[j-1].getage()<<" "<<people[j-1].getname()<<" "<<people[j-1].getzhiye()<<" "<<people[j-1].getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::binary);
for(i=0;i<z;i++)
{
outfile.write((char *)&people[i],sizeof(people[i]));}
outfile.close();
}
cout<<"借阅成功!";
}
void controller() //图书管理员信息
{
int b,i,d,h=0;
ifstream file("controlloernum.txt");
if(file) { file>>b; file.close();cout<<"图书管理员个数:"<<b<<endl;}
else
{
cout<<"没有图书管信息理员"<<endl;
cout<<"你是否想创建(请输入Y或N):";
cin>>d;
if(d='y') {ofstream infile("controlloernum.txt");infile<<h;exit(0);}
else exit(0);
}
ifstream is("controlloer.txt",ios_base::binary);
if(is)
{
controlloer *bookpeople=new controlloer[b];
for(i=0;i<b;i++)
{
is.read((char *)&bookpeople[i],sizeof(bookpeople[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople[i].getnumber()<<" "<<bookpeople[i].getage()<<" "<<bookpeople[i].getname()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
cout<<"没有这个文件夹"<<endl;
cout<<"你是否想创建(请输入Y或N):";
cin>>d;
if(d='y') {ofstream infile("controlloer.txt");exit(0);}
else exit(0);
}
is.close();
}
void libary() //图书馆的总信息
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"学校图书馆由本部图书馆及彭州校区图书馆组成.馆舍面积41048平方米";
cout<<" (其中现有馆舍面积11578 平方米,在建图书馆馆舍面积29470平方米),";
cout<<"各院系资料室面积1120平方米。学校拥有纸质文献198万余册, ";
cout<<"生均81.17册,电子文献161.7万余种。近三年校图书馆每年进书量均超过15万册."<<endl;
}
void storecontroller() //存入新的管理员的信息
{
int i,b,c,h=0;
char a[20],d;
ifstream file("controlloernum.txt");
if(file)
{
file>>b; file.close();cout<<"已有的图书管理员个数:";
cout<<b<<endl;
}
else
{
cout<<"没有图书管信息理员"<<endl;
cout<<"你是否想创建(请输入y或n):";
cin>>d;
if(d=='y')
{ofstream infile("controlloernum.txt");infile<<h;infile.close();b=0;}
else exit(0) ;
}
ofstream outfile("controlloer.txt",ios::app);
cout<<"请输入图书管理员的编号和年龄,名字:";
cin>>c>>i>>a;
controlloer bookpeople(c,i,a);
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople.getnumber()<<" "<<bookpeople.getage()<<" "<<bookpeople.getname()<<endl;
outfile.write((char *)&bookpeople,sizeof(bookpeople));
outfile.close();
b++;
ofstream tfile("controlloernum.txt");
tfile<<b;
tfile.close();
cout<<"保存成功!";
}
void reworkcontrolloer() ///修改图书管理员
{
int i,b,h,j,g;
char d[20];
ifstream file("controlloernum.txt");
if(file) { file>>b; file.close();}
else {cout<<"没有图书管信息理员"; exit(0);}
cout<<"已有的图书管理员个数:";
cout<<b<<endl;
controlloer *bookpeople=new controlloer[b];
ifstream is("controlloer.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&bookpeople[i],sizeof(bookpeople[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 "<<endl;
cout<<bookpeople[i].getnumber()<<" "<<bookpeople[i].getage()<<" "<<bookpeople[i].getname()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"请输入你要修改的管理员编号:";
cin>>h;
cout<<"输入年龄,名字:";
cin>>g>>d;
bookpeople[h-1].reworkage(g);
bookpeople[h-1].reworkname(d);
cout<<"该了后的名字:"<<bookpeople[h-1].getname();
ofstream tfile("controlloer.txt",ios_base::binary);
for(j=0;j<b;j++)
{
tfile.write((char *)&bookpeople[j],sizeof(bookpeople[j]));
}
tfile.close();
}__page_break__
void storereader() //存入读者信息
{
int i,b,c,h,l=1;
char f;
char a[20],d[20],e[20];
ifstream file("readernum.txt");
if(file) { file>>b; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<b<<endl;
cout<<"如果你想重新存入(输入y或n):";
cin>>f;
if(f=='n')
{
while(l==1)
{ cout<<"请输入读者的编号和年龄,名字,职业,借书情况:";
cin>>c>>i>>a>>d>>e;
reader people(c,i,a,d,e);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people.getnumber()<<" "<<people.getage()<<" "<<people.getname()<<" "<<people.getzhiye()<<" "<<people.getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::app);
outfile.write((char *)&people,sizeof(people));
outfile.close();
b++;
cout<<"你还要添加,请按1,不添按0:";
cin>>h;
if(h==1) l=1;
if(h==0) l=0;
}
ofstream tfile("readernum.txt");
tfile<<b;
tfile.close();
cout<<"保存成功!";
}
else
{
int g=0;
cout<<"请输入读者的编号和年龄,名字,职业,借书情况:";
cin>>c>>i>>a>>d>>e;
reader people(c,i,a,d,e);
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people.getnumber()<<" "<<people.getage()<<" "<<people.getname()<<" "<<people.getzhiye()<<" "<<people.getborrowbook()<<endl;
ofstream outfile("reader.txt",ios_base::trunc );
outfile.write((char *)&people,sizeof(people));
outfile.close();
g++;
ofstream file("readernum.txt");
file<<g;
cout<<g;
file.close();
cout<<"保存成功!";
}
}
void reseachallread() //读者的总信息
{
int i,b;
ifstream file("readernum.txt");
if(file) { file>>b; file.close();}
else { cout<<"没有文件";exit(0);}
cout<<"已有的读者个数:";
cout<<b<<endl;
reader *people=new reader[b];
ifstream is("reader.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&people[i],sizeof(people[i]));
}
for(i=0;i<b;i++)
{
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[i].getnumber()<<" "<<people[i].getage()<<" "<<people[i].getname()<<" "<<people[i].getzhiye()<<" "<<people[i].getborrowbook()<<endl;
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
}
void choicecontroll() //管理员
{
int q,l=1,i,h;
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"请输入密码:";
cin>>i;
while(l)
{
if(i==12)
{ system("cls");
system("color 3e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"*****"<<"0,退出."<<" ******"<<endl;
cout<<" "<<"*****" <<"1,查询图书馆管理员的信息"<<" ******"<<endl;
cout<<" "<<"*****" <<"2,存入新的管理员信息. "<<" ******"<<endl;
cout<<" "<<"*****" <<"3,存入图书的信息"<<" ******"<<endl;
cout<<" "<<" *****" <<"4,修改图书管理员的信息"<<" ******"<<endl;
cout<<" "<<" *****" <<"5,存入读者的信息 "<<" ******"<<endl;
cout<<" "<<" *****" <<"6,查询读者的总信息(借阅情况)"<<" ******"<<endl;
cout<<"请选择执行的操作:";
cin>>q;
if(q>=0&&q<7)
{
switch(q)
{
case 0:
l=0;
break;
case 1:controller();
system("pause");
break;
case 2:storecontroller();
system("pause");
break;
case 3:store() ;
system("pause");
break;
case 4:reworkcontrolloer();
system("pause");
break;
case 5:storereader();
system("pause");
break;
case 6:reseachallread();
system("pause");
break;
}
}
else
{
system("cls");
system("color 4e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"输入错误请重新输入!"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
system("pause");
}
}
else
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<" 密码错误"<<endl;
cout<<" "<<" 请输入正确的密码!"<<endl;
cout<<" "<<"退出,请按0,不退出,按1"<<endl;
cin>>h;
if(h==0) l=0;
if(h==1)
{
system("cls");
system("color 2e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"请输入密码:";
cin>>i;
}
}
}
}
void researchbook()
{
int i,g,h=0;
char a[20];
ifstream tfile("num.txt");
tfile>>g;
cout<<"本图书馆已经有"<<g<<"本图书"<<endl;
book *shu=new book[g];
if(g==0)cout<<"图书馆里没有书!"<<endl;
else
{
ifstream is("stu.txt",ios_base::binary);
if(is)
{
for(i=0;i<g;i++)
{
is.read((char *)&shu[i],sizeof(shu[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"你要查找的书的名字:";
cin>>a;
for(i=0;i<g;i++)
{
if(strcmp(shu[i].name,a)==0)
{
cout<<"编号 名字 作者名"<<endl;
cout<<shu[i].num<<" "<<shu[i].name<<" "<<shu[i].people<<endl;
h++;
}
}
if(h==0)cout<<"没有你要找的书!!";
}
}
void reseachreader() //查询读者的信息
{
int i,b,h=0;
char a[20];
ifstream file("readernum.txt");
if(file) { file>>b; file.close();}
else { cout<<"没有文件";}
cout<<"已有的读者个数:";
cout<<b<<endl;
reader *people=new reader[b];
ifstream is("reader.txt",ios_base::binary);
if(is)
{
for(i=0;i<b;i++)
{
is.read((char *)&people[i],sizeof(people[i]));
}
}
else
{
cout<<"ERROR:cannot open file'stu.txt'"<<endl;
}
is.close();
cout<<"请输入你要查找读者的名字:";
cin>>a;
for(i=0;i<b;i++)
{
if(strcmp(people[i].getname(),a)==0)
{
cout<<"编号 年龄 名字 职业 借书情况 "<<endl;
cout<<people[i].getnumber()<<" "<<people[i].getage()<<" "<<people[i].getname()<<" "<<people[i].getzhiye()<<" "<<people[i].getborrowbook()<<endl;
h++;
}
}
if(h==0)cout<<"没有这个读者!";
}
void choicepeople() //学生,老师
{
int i;
char l='y';
while(l=='y')
{
system("cls");
system("color 3b");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"******"<<"0,退出."<<"******"<<endl;
cout<<" "<<"******"<<"1,输出图书信息. "<<"******"<<endl;
cout<<" "<<"******"<<"2,查询图书馆的总信息."<<"******"<<endl;
cout<<" "<<"******"<<"3,查询图书."<<"******"<<endl;
cout<<" "<<"******"<<"4,查询读者的信息."<<"******"<<endl;
cout<<"请选择执行的操作:";
cin>>i;
switch(i)
{
case 0: l='n';
break;
case 1:outbook();
system("pause");
break;
case 2:libary();
system("pause");
break;
case 3:researchbook();
system("pause");
break;
case 4:reseachreader();
system("pause");
break;
}
}
}
void main()
{
int h,l=1;
while(l)
{
system("cls");
system("color 1a");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"图书管理系统"<<endl;
cout<<" -------设计者:计算机学院06级2班卢克波"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"0.退出"<<endl;
cout<<" "<<"1.管理员"<<endl;
cout<<" "<<"2.其他人(学生,老师)"<<endl;
cout<<"请选择执行的操作:";
cin>>h;
if(h>=0&&h<3)
{
switch(h)
{
case 0:cout<<"欢迎参阅本图书馆!"<<endl;exit(0);
case 1:
choicecontroll();
system("pause");
break;
case 2:
choicepeople();
system("pause");
break;
}
}
else
{
system("cls");
system("color 4e");
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<"输入错误请重新输入!"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
system("pause");
}
}
}
展开全部
#include
#include
#include
using
namespace
std;
class
controlloer
//图书管理员
{
private:
int
number;
int
age;
char
name[20];
public:
controlloer();
controlloer(int
c,int
a,char
b[20]
);
int
getnumber();
int
getage();
char
*getname();
void
reworkage(int
i);
void
reworkname(char
a[20]);
};
controlloer::controlloer()
{
number=0;
char
b[20]="no
one";
age=0;
strcpy(name,b);
}
controlloer::controlloer(int
c,int
a,char
b[20])
{
number=c;
age=a;
strcpy(name,b);
}
int
controlloer::getage()
{return
age;}
char
*controlloer::getname()
{return
name;}
int
controlloer::getnumber()
{return
number;}
void
controlloer::reworkage(int
i)
{age=i;}
void
controlloer::reworkname(char
a[20])
{strcpy(name,a);}
class
reader
//读者(学生,老师)
{
private:
int
number;
int
age;
char
name[20];
char
zhiye[20];
char
borrowbook[20];
public:
reader();
reader(int
c,int
a,char
b[20],char
d[20],char
e[20]);
int
getnumber();
int
getage();
char
*getzhiye();
char
*getname();
char
*
getborrowbook();
void
reworkborrowbook(char
a[20]);
};
reader::reader()
{
char
a[20]="没有人";
char
b[20]="无职称";
char
c[20]="没有借书";
number=0;
age=0;
strcpy(name,a);
strcpy(zhiye,b);
strcpy(borrowbook,c);
}
reader::reader(int
a,int
c,char
b[20],char
d[20],char
e[20])
{
number=a;
age=c;
strcpy(name,b);
strcpy(zhiye,d);
strcpy(borrowbook,e);
}
int
reader::getnumber(){return
number;}
int
reader::getage(){return
age;}
char
*reader::getzhiye(){return
zhiye;}
char
*reader::getname(){return
name;}
char
*
reader::getborrowbook(){return
borrowbook;}
void
reader::reworkborrowbook(char
a[20]){strcpy(borrowbook,a);}
struct
book
#include
#include
using
namespace
std;
class
controlloer
//图书管理员
{
private:
int
number;
int
age;
char
name[20];
public:
controlloer();
controlloer(int
c,int
a,char
b[20]
);
int
getnumber();
int
getage();
char
*getname();
void
reworkage(int
i);
void
reworkname(char
a[20]);
};
controlloer::controlloer()
{
number=0;
char
b[20]="no
one";
age=0;
strcpy(name,b);
}
controlloer::controlloer(int
c,int
a,char
b[20])
{
number=c;
age=a;
strcpy(name,b);
}
int
controlloer::getage()
{return
age;}
char
*controlloer::getname()
{return
name;}
int
controlloer::getnumber()
{return
number;}
void
controlloer::reworkage(int
i)
{age=i;}
void
controlloer::reworkname(char
a[20])
{strcpy(name,a);}
class
reader
//读者(学生,老师)
{
private:
int
number;
int
age;
char
name[20];
char
zhiye[20];
char
borrowbook[20];
public:
reader();
reader(int
c,int
a,char
b[20],char
d[20],char
e[20]);
int
getnumber();
int
getage();
char
*getzhiye();
char
*getname();
char
*
getborrowbook();
void
reworkborrowbook(char
a[20]);
};
reader::reader()
{
char
a[20]="没有人";
char
b[20]="无职称";
char
c[20]="没有借书";
number=0;
age=0;
strcpy(name,a);
strcpy(zhiye,b);
strcpy(borrowbook,c);
}
reader::reader(int
a,int
c,char
b[20],char
d[20],char
e[20])
{
number=a;
age=c;
strcpy(name,b);
strcpy(zhiye,d);
strcpy(borrowbook,e);
}
int
reader::getnumber(){return
number;}
int
reader::getage(){return
age;}
char
*reader::getzhiye(){return
zhiye;}
char
*reader::getname(){return
name;}
char
*
reader::getborrowbook(){return
borrowbook;}
void
reader::reworkborrowbook(char
a[20]){strcpy(borrowbook,a);}
struct
book
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个等等吧,要俩天最少,上面的纯c知道么?
现在什么人都有,我还要问,你说纯c,那就是控制台是不是?
你做这个有用么?
现在什么人都有,我还要问,你说纯c,那就是控制台是不是?
你做这个有用么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询