#include<fstream>
#include<conio.h>
using namespace std
class Librarian//图书管理员类
{
public:
Librarian()
Librarian(int n,int j,char na[20],int w )
int getnumber()
int getjobage()
char *getname()
int getwages()
void resetjobage(int j)
void resetwages(int w)
void resetname(char na[20])
private:
int number
int jobage
char name[20]
int wages
}
Librarian::Librarian() /御镇/其函数的实现
{
number=0
char b[20]="no one"
jobage=0
strcpy(name,b)
}
Librarian::Librarian(int n,int j,char na[20],int w)
{
number=n
jobage=j
strcpy(name,na)
wages=w
}
int Librarian::getjobage()
{return jobage}
char *Librarian::getname()
{return name}
int Librarian::getnumber()
{return number}
int Librarian::getwages()
{return wages}
void Librarian::resetjobage(int j)
{
jobage=j
}
void Librarian::resetname(char na[20])
{
strcpy(name,na)
}
void Librarian::resetwages(int w)
{
wages=w
}
class reader//读颤键者类
{
private:
int number
int age
char name[20]
char borrowbook[20]
public:
reader()
reader(int c,int a,char b[20],char e[20])
int getnumber()
int getage()
char *getname()
char * getborrowbook()
void reworkborrowbook(char a[20])
}
reader::reader() //其函数的实现
{
char a[20]="没有人"
char c[20]="没有借书"
number=0
age=0
}
reader::reader(int a,int c,char d[20],char e[20])
{
number=a
age=c
strcpy(name,d)
strcpy(borrowbook,e)
}
int reader::getnumber(){return number}
int reader::getage(){return age}
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 writer[20]
}
void outbookinf()//输出所有图茄拆巧书信息
{
int i
ifstream infile("allbook.txt",ios::in)
char line[50]
cout<<"书名"<<'\t'<<"书号"<<'\t'<<"作者"<<endl
for(i=1i<=10i++)
{
infile.getline(line,50,'\n')
cout<<line<<endl
}
infile.close()
}
void serchLaninf()//图书管理员信息函数
{
int n,i
ifstream file("serchLaninf.txt")
if(file){ file>>n file.close()}
else {cout<<"没有图书管信息理员"exit(0)}
ifstream is("controlloer.txt",ios_base::binary)
if(is)
{
Librarian *A=new Librarian[n]
for(i=0i<ni++)
{
is.read((char *)&A[i],sizeof(A[i]))
}
for(i=0i<ni++)
{
cout<<"编号"<<'\t'<<"工龄"<<'\t'<<"名字"<<'\t'<<"工资"<<endl
cout<<A[i].getnumber()<<"\t"<<A[i].getjobage()<<"\t"<<A[i].getname()<<"\t"<<A[i].getwages()<<endl
}
}
else
{
cout<<"txt文件打开出错'"<<endl
}
is.close()
}
void libary()//图书馆的总信息
{
system("cls")
system("color 2e")
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<"本校图书馆由本部图书馆及彭州校区图书馆组成,图书馆总面积达了****平方米"
cout<<" (本馆现在有***类书籍***万册,****类书籍****万册,****类书籍****万册****类书籍****万册),"
cout<<"图书馆现有工作人员***名"
cout<<"图书馆现有的现代化设备价值超过****万元………………"<<endl
}
void storelibrarian() //存入新的管理员的信息
{
int age,n,num,wage
char name[20]
ifstream file("serchLaninf.txt")
if(file){ file>>n file.close()}
else { n=0}
cout<<"已有的图书管理员个数:"
cout<<n<<endl
cout<<"请输入新图书管理员的编号和工龄,名字和工资:"
cin>>num>>age>>name>>wage
Librarian A(num,age,name,wage)
cout<<"编号 工龄 名字 工资 "<<endl
cout<<A.getnumber()<<""<<A.getjobage()<<" "<<A.getname()<<" "<<A.getwages()<<endl
ofstream outfile("controlloer.txt",ios_base::app )
outfile.write((char *)&A,sizeof(A))
outfile.close()
n++
ofstream tfile("serchLaninf.txt")
tfile<<n
tfile.close()
cout<<"保存成功!"
}
void reLaninf()//修改图书管理员
{
int i,n,h,jobage,wage,j
char name[20]
ifstream file("serchLaninf.txt")
if(file){ file>>n file.close()}
else {cout<<"没有图书管信息理员"
exit(0)}
cout<<"已有的图书管理员个数:"
cout<<n<<endl
Librarian *A=new Librarian[n]
ifstream is("controlloer.txt",ios_base::binary)
if(is)
{
for(i=0i<ni++)
{
is.read((char *)&A[i],sizeof(A[i]))
}
for(i=0i<ni++)
{
cout<<"编号 工龄 名字 工资"<<endl
cout<<A[i].getnumber()<<""<<A[i].getjobage()<<" "<<A[i].getname()<<" "<<A[i].getwages()<<endl
}
}
else
{
cout<<"打开文件出错"<<endl
}
is.close()
cout<<"请选择你要修改的管理员编号:"
cin>>h
cout<<"输入新的工龄,名字,工资:"
cin>>jobage>>name>>wage
A[h-1].resetjobage(jobage)
A[h-1].resetname(name)
A[h-1].resetwages(wage)
cout<<"该管理员修改后的名字是:"<<A[h-1].getname()<<" 工龄是:"<<A[h-1].getjobage()<<" 工资是:"<<A[h-1].getwages()<<endl
ofstream tfile("controlloer.txt",ios_base::binary)
for(j=0j<nj++)
{
tfile.write((char *)&A[j],sizeof(A[j]))
}
tfile.close()
}
void aadbook()//新增图书
{
int numchar name[12]char writer[10]int n
a:
ofstream fout("allbook.txt",ios::app)
cout<<"请录入图书信息:"<<endl
cout<<"书名"<<'\t'<<"书号"<<'\t'<<"作者"<<endl
cin>>namefout<<name<<'\t'
cin>>numfout<<num<<'\t'
cin>>writerfout<<writer<<'\n'
fout.close()
cout<<"是否继续录入?1.是2.否"<<endl
cin>>n
if(n==1)
goto a
else
{void studentland()
studentland()}
}
void delate() //删除函数
{ int m
cout<<"选择 *** 作选项:"<<endl
cout<<" 1.删除全部信息"<<endl
cout<<" 2.单个删除"<<endl
cin>>m
if(m==1)
{ofstream file("allbook.txt",ios::trunc)
cout<<"全部删除完毕,按任意键返回!"<<endl
file.close()
getch()
system("cls")
void studentland()
studentland()
}
char str[10][80],buf[20]
a:
int i=0,flag=100,c=0
ifstream fin("allbook.txt")
if(!fin){
cout<<"文件打开失败!"<<endl
getch()
system("cls")
void studentland()
studentland()
}
cout<<"请输入你要删除的书名:"<<endl
cin>>buf
strcat(buf,"\t")
while(fin.getline(str[i],80))
{
if(strncmp(str[i],buf,strlen(buf))==0)
{
flag=i
}
i++
}
fin.close()
if(flag==100)
{
cout<<"没有你所要删除的书籍!重新按1,否则0....."<<endl
int b
cin>>b
if(b==1)goto a
else c=1
}
if(c==0){
ofstream fout("allbook.txt")
for(int j=0j<ij++){
if(j==flag)continue
fout<<str[j]<<endl
}
fout.close()
cout<<"你要删除的书籍的信息已删除,继续按1,否则按0....."<<endl
int b
cin>>b
if(b==1)goto a
}
cout<<" *** 作已经结束,按任意键返回......"<<endl
getch()
system("cls")
void studentland()
studentland()
}
void searchbook()// 查找书籍
{
a:
ifstream fin
int flag=0,b,length
char str[20]
char f[200]char g[200]
fin.open("allbook.txt")
if(!fin)
{
cout<<"Open f1.dat error....."<<endl
exit(1)
}
while(1)
{
cout<<"请输入书名:"
cin>>str
strcat(str,"\t")
length=strlen(str)
cout<<"------------------------------------"<<endl
while(fin.getline(f,199))
{
strcpy(g,f)
if(strncmp(str,f,length)==0)
{
flag=1
break
}
}
if(flag==1)
{
cout<<"所查询的书已经找到:"<<'\n'
cout<<"--------------------------------"<<endl
cout<<"书名"<<'\t'<<"书号"<<'\t'<<"作者"<<'\t'<<endl
cout<<g<<endl
cout<<"--------------------------------"<<endl
flag=0
cout<<"要继续查询按1,否则按0:"<<endl
cin>>b
if(b==0)break
}
else
{
fin.close()
cout<<"没有此书,继续按1,否则按0..."<<endl
cin>>b
if(b==0)break
goto a
}
}
fin.close()
cout<<"查询完毕,按任意键返回......"<<endl
getch()
system("cls")
void studentland()
studentland()
}
void seachreader() // 查询读者信息
{
a:
ifstream fin
int flag=0,b,length
char str[20]
char f[200]char g[200]
fin.open("readernum.txt")
if(!fin)
{
cout<<"没有此信息文件!"<<endl
exit(1)
}
while(1)
{
cout<<"请输入你要查找读者的名字:"
cin>>str
strcat(str,"\t")
length=strlen(str)
cout<<"------------------------------------"<<endl
while(fin.getline(f,199))
{
strcpy(g,f)
if(strncmp(str,f,length)==0)
{
flag=1
break
}
}
if(flag==1)
{
cout<<"所查询的读者已经找到:"<<'\n'
cout<<"--------------------------------"<<endl
cout<<"名字"<<'\t'<<"编号"<<'\t'<<"年龄"<<'\t'<<"借书次数"<<endl
cout<<g<<endl
cout<<"--------------------------------"<<endl
flag=0
cout<<"要继续查询按1,否则按0:"<<endl
cin>>b
if(b==0)break
goto a
}
else
{
fin.close()
cout<<"没有此人,继续按1,否则按0..."<<endl
cin>>b
if(b==0)break
goto a
}
}
fin.close()
cout<<"查询完毕,按任意键返回......"<<endl
getch()
system("cls")
void studentland()
studentland()
}
/*void seachreader() //查询读者的信息
{
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 *A=new reader[b]
ifstream is("reader.txt",ios_base::binary)
if(is)
{
for(i=0i<bi++)
{
is.read((char *)&A[i],sizeof(A[i]))
}
}
else
{
cout<<"txt文件打开出错"<<endl
}
is.close()
cout<<"请输入你要查找读者的名字:"
cin>>a
for(i=0i<bi++)
{
if(strcmp(A[i].getname(),a)==0)
{
cout<<"编号 年龄名字 借书情况 "<<endl
cout<<A[i].getnumber()<<" "<<A[i].getage()<<" "<<A[i].getname()<<""<<A[i].getborrowbook()<<endl
h++
}
}
if(h==0)cout<<"没有这个读者!"
}
*/
void Librarianland()//管理员登陆函数
{
int q,l=1,i,h
system("cls")
system("color 2e")
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<" "<<"现在进行身份确认,请输入口令:"
cin>>i
while(l)
{
if(i==00000)
{
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<<"请选择执行的 *** 作:"
cin>>q
if(q>=0&&q<6)
{
switch(q)
{
case 0:
l=0
break
case 1:serchLaninf()
system("pause")
break
case 2:storelibrarian()
system("pause")
case 3:reLaninf()
system("pause")
break
case 4:
void aadbook()
aadbook()
break
case 5:
void delate()
delate()
break
default:
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<<" "<<"重新确认请按请按1,放弃请按0"<<endl
cout<<" "
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 studentland() //学生登陆函数
{
int h
char l='y'
while(l=='y')
{
system("cls")
system("color 3e")
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<""<<"******"<<"|输出藏书信息,请按1 | "<<"******"<<endl
cout<<""<<"******"<<"|查询图书馆的总信息,请按2| "<<"******"<<endl
cout<<""<<"******"<<"|按书名查找图书,请按3 | "<<"******"<<endl
cout<<""<<"******"<<"|查询读者的信息,请按4 | "<<"******"<<endl
cout<<" "<<" ******"<<"|返回上一级菜单,请按0 | "<<"******"<<endl
cout<<"请选择您将执行的 *** 作:"
cin>>h
if(h>=0&&h<5)
switch(h)
{
case 0:
l='n'
break
case 1:outbookinf()
system("pause")
break
case 2:libary()
system("pause")
break
case 3:searchbook()
system("pause")
break
case 4:seachreader()
system("pause")
break
}
else
{
system("cls")
system("color 4e")
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<" "<<"您的 *** 作是无效的!!!!"<<endl
system("pause")
}
}
}
void main() // 主函数
{
int h,l=1
while(l)
{
system("cls")
system("color 7c")
cout<<" "<<endl
cout<<" "<<endl
cout<<" "<<endl
cout<<" "<<"图书管理系统"<<endl
cout<<" "<<endl
cout<<" "<<endl
cout<<" ------------------"<<endl
cout<<" "<<"||管理员登陆 请按1||"<<endl
cout<<" "<<"||学生登陆 请按2 ||"<<endl
cout<<" "<<"||退出系统 请按0 ||"<<endl
cout<<" -------------------"<<endl
cout<<""<<endl
cout<<" 请您选择登陆方式:"
cin>>h
if(h>=0&&h<3)
{
switch(h)
{
case 0:
cout<<"谢谢光临本图书馆!"<<endl
exit(0)
case 1:
Librarianland()
system("pause")
break
case 2:
studentland()
system("pause")
break
}
}
else
{
system("cls")
system("color 4e")
cout<<""<<endl
cout<<""<<endl
cout<<""<<endl
cout<<" "<<"您的 *** 作是无效的!!!!"<<endl
system("pause")
}
}
}
图书馆的管理系统。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)