精通C(++)语言的高手帮帮我吧~图书信息管理系统设计~我是一点头绪都没有~过几天就要交了。

2025-01-01 02:42:24
推荐回答(2个)
回答1:

这边有!

#include
#include
#include
#include
struct bookData
{
int booknumber;
char bookname[30];
int store;
};
struct Person
{
char name[20];
char studynumber[10];
int count;
bookData Rbook[2];
//bookData Rbook;
};
class History
{
public:
History(fstream& a){readerbook=a;}
void writehistory();
void readhistory(fstream&);
private:
fstream readerbook;
};
class Liberian;

void Find(fstream&);
void CreateTxt(fstream&);

class Reader
{
friend Liberian;
public:
Reader(fstream&);
void print();
void handlebook(fstream&);
void change();
bool findreader();
void Addreader();
void deletereader();
private:

fstream file;
Person person;

};
class Liberian
{
public:
Liberian(char *,char *);
void changeReader(Reader&);
void selfprint();
void Append(fstream&);
private:
char workname[20];
char worknumber[20];
};

int main()
{
fstream bookRecord(" book.dat",ios::in| ios::out);
if(!bookRecord)
{
cerr<<" Can't open,try again!"<exit(1);
}
fstream readerRecord("reader.dat",ios::in|ios::out);
if(!readerRecord)
{
cerr<<" Can't open,try again!"<exit(1);
}

int choice;
int key; Reader reader(readerRecord);//读者管理系统
Liberian liberian("李天","123456");//图书管理员
History rec(readerRecord);//声明显示历史记录类
while(1)
{
cout<<" 请输入您的选择:\n\n"
<<"1--图书管理员\n"
<<"2--读者系统\n"
<<"0--结束程序\n";
cin>>choice;
switch(choice)
{
case 1:

{
cout<<" Hello,图书管理员:\n";
liberian.selfprint();cout<cout<<"1-- 增加新图书\n"
<<"2-- 改变读者的属性\n"
<<"3-- 显示历史记录\n"
<<"0-- 返回\n";
cin>>key;

switch(key)
{
case 1:
liberian.Append(bookRecord);
break;
case 2:
liberian.changeReader(reader);
break;
case 3:
rec.readhistory(readerRecord);
case 0:
break ;
}
}
break;
case 2:
{
cout<<"学生读者\n"; int iflag=1;

//reader.findreader();
cout<<"1-- 借书与还书信息\n"
<<"2-- 修改个人信息\n"
<<"0-- 返回\n";

cin>>key;
switch(key)
{
case 1:
reader.handlebook(bookRecord);
break;
case 2:
reader.change();
break;
case 0:
break;
}
}
break;
default:
return 0;
}
}

return 0;
}
//增加书籍
void Liberian::Append(fstream& storef)
{
bookData book;
int choice;
int key;
int num;
storef.seekp(0,ios::end);
int posEnd=storef.tellp();
cout<<"*************书籍入库***************"<while(1)
{
cout<<" Please enter your choice:"<cout<<"1--添加新书\n"<<"2--已有书籍\n"<<"0--返回\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<" 书号, 书名, 数量?"<cin>>book.booknumber>>book.bookname>>book.store;
storef.write(reinterpret_cast(&book),sizeof(bookData));
break;
case 2:
storef.seekg(0,ios::beg);
cout<<"Booknumber?\n";
cin>>key;
do{
storef.read(reinterpret_cast(&book),sizeof(bookData));
}while(book.booknumber!=key&&storef.tellg()!=posEnd);

if(book.booknumber==key)
{
cout<cout<<" 输入已有书增加的数量:"<cin>>num;

if(num>0)
book.store+=num;
else
{
cout<<" Invalid input"<}

storef.seekp(-long(sizeof(bookData)),ios::cur);////////////////////
storef.write(reinterpret_cast(&book),sizeof(bookData));
cout<<"现在书籍: "<}
else
cout<<"找不到此书,请重新查阅书号是否正确!"<break;
case 0:
return ;
}
}
}

//书籍查询

void Find(fstream & f)
{
bookData book;
int key;
int choice;
f.seekg(0,ios::end);
int posEnd=f.tellp();

cout<<"*************书籍查询***************"<while(1)
{
cout<<" 请输入您的选择\n"
<<" 1-- 检索一本书\n"
<<"2-- 显示全部书籍\n"
<<"0-- 返回\n";
cin>>choice;
switch(choice)
{
case 1:
f.seekg(0,ios::beg);
cout<<"输入你想检索书的书号"<cin>>key;
do{
f.read(reinterpret_cast(&book),sizeof(bookData));
}while(book.booknumber!=key&&f.tellg()!=posEnd);
if(book.booknumber==key)
cout<else
cout<<"找不到此书,请重新确认!"<break;
case 2:
f.seekg(0,ios::beg);
do{
f.read(reinterpret_cast(&book),sizeof(bookData));
cout<}while(f.tellg()!=posEnd);
break;
case 0:
return ;
}
}
}

Reader::Reader(fstream& c)
{

file=c;
Person person={"0","0",0,{{0,"0",0}, {0,"0",0}}};
}

void Reader::print()
{
cout<<"Name"<<"---"<}

//操作书籍??????????????????????
void Reader::handlebook(fstream &filee)
{

int key; int choice;

bookData book; bool iflag;int num=0;
filee.seekp(0,ios::end);
int posEnd=filee.tellp();
while(!(iflag=findreader()))
{
num++;
if(num>=3)
return;
}
//cout<while(1)
{

cout<<"1-- 借书\n"
<<"2-- 还书\n"
<<"3-- 查找一本书\n"
<<"0-- 返回"<<'\n';
cin>>choice;
switch(choice)
{

case 1:
{
filee.seekp(0,ios::end);
int posEnd=filee.tellp();
if(person.count<=1)
{
cout<<" 输入你要借阅图书的书号:"<cin>>key;
filee.seekg(0);
do{
filee.read(reinterpret_cast(&book),sizeof(bookData));
}while(book.booknumber!=key&&filee.tellp()!=posEnd);
//cout<if(book.booknumber==key)
{
//cout<<" 找到你想借阅的图书,成功借阅!"<
if(book.store>0)
{
person.Rbook[person.count]=book;
person.count+=1;
book.store-=1;
filee.seekp(-long(sizeof(bookData)),ios::cur);
filee.write(reinterpret_cast(&book),sizeof(bookData));
cout<<" 找到你想借阅的图书,成功借阅!"<cout<<"书籍 :"<
}
else
cout<<" 现在此图书已经被借完了,请耐心等待几天!"<
}
else
cout<<" 找不到你想要的图书"<
}
else
cout<<"你最多只能借2本\n\n";

}

break;

case 2:
{
bookData blankbook={0,"0",0};
//if(person.count>0)
//{
int iflag=0;
filee.seekg(0);
cout<<" 输入你想要还的书的书号:"<cin>>key;
for(int i=0;i<2;i++)
{
if(key==person.Rbook[i].booknumber)
{
person.Rbook[i]=blankbook;
cout<<"成功归还此书!";
iflag=1;
person.count--;

do{
filee.read(reinterpret_cast(&book),sizeof(bookData));
}while(book.booknumber!=key&&filee.tellp()!=posEnd);

if(book.booknumber==key)
{

book.store+=1;
filee.seekp(-long(sizeof(bookData)),ios::cur);
filee.write(reinterpret_cast(&book),sizeof(bookData));
cout<<"书籍 :"<}

}

}

if(!iflag)
{
cout<<" 你没有借阅那本书,请确认!"<}
// }
// else
// cout<<"你没有借书,请重新确认!\n\n";

}
break;
case 3:
Find(filee);
break;
case 0:
return;
}
}
}

void Reader::change()
{
char newname[20]; char newnumber[10];
int choice;
file.seekp(0,ios::cur);
int Posend=file.tellp(); bool iflag;int num=0;
while(!(iflag=findreader()))
{
num++;
if(num>=3)
return;
}
cout<<" 请输入你的选择!"<cout<<"1--改变名字!\n"
<<"2--修改学号r\n"
<<"0--返回\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"输入你的新名字!\n";
cin>>newname;
strcpy(person.name,newname);
break;
case 2:
cout<<"输入你的信学号?\n";
cin>>newnumber;
strcpy(person.studynumber,newnumber);
break;
default:
break;;
}
file.seekp(-long(sizeof(Person)),ios::cur);
file.write(reinterpret_cast(&person),sizeof(Person));
cout<<"信息修改成功!"<}

void Liberian::selfprint()
{
cout<<" 图书管理员 :\n"
<}
Liberian::Liberian(char *a,char*b)
{
strcpy(workname,a);
strcpy(worknumber,b);
}

void Liberian::changeReader(Reader& a)
{
int choice; char newname[20];char newnumber[10];
cout<<"修改读者的数据信息!\n";

cout<<"1-- 增加一个读者\n"
<<"2-- 删除一个读者\n"
<<"0-- 结束程序\n";
cin>>choice;
switch(choice)
{
case 1:
a.Addreader();
break;
case 2:
a.deletereader();
break;
case 0:
return;
}
}

void Reader::Addreader()
{
Person temp;bookData book={0,"0",0};
file.seekp(0,ios::end);
int Posend=file.tellp();
cout<<"输入你想要增加的读者的名字"<cin>>temp.name;
cout<<"新读者的学号:"<cin>>temp.studynumber;
temp.Rbook[1]=book; temp.Rbook[0]=book; temp.count=0;
file.write(reinterpret_cast(&temp),sizeof(Person));
cout<<" 成功添加!"<}
void Reader::deletereader()
{
file.seekp(0,ios::end);
int Posend=file.tellp();
Person person;
char name[20];
cout<<"输入要删除的读者的名字!"<cin>>name;
file.seekg(0);
do{
file.read(reinterpret_cast(&person),sizeof(Person));
}while(strcmp(name,person.name)&&file.tellp()!=Posend);
if(!strcmp(name,person.name))
{
bookData blankbook={0,"0",0};
Person guest={"0","0",0,{{0,"0",0},{0,"0",0}}};

file.seekp(-long(sizeof(Person)),ios::cur);
file.write(reinterpret_cast(&guest),sizeof(Person));
cout<<"成功删除!"<}
else
cout<<"查无此人!"<}
bool Reader::findreader()
{
file.seekp(0,ios::end);
int Posend=file.tellp();
char name[20];

Person guest={"0","0",0,{{0,"0",0},{0,"0",0}}};
cout<<"输入查找人的名字!";
cin>>name;
file.seekg(0);
do{
file.read(reinterpret_cast(&person),sizeof(Person));
}while(strcmp(name,person.name)&&file.tellp()!=Posend);
if(!strcmp(name,person.name))
{
cout<<"查到此人:"<return true;
}
else
{
cout<<"找不到此人,请重新确认!"<return false;
}

}
//借阅历史
void History::readhistory(fstream& a)
{
readerbook=a;
char name[10]="0";
readerbook.seekp(0,ios::end);
int Posend=readerbook.tellp();
Person guest; int iflag=1;
cout<<" 书籍借阅信息如下:"<cout<<"姓名 学号 借书量 书籍名"<readerbook.seekg(0,ios::beg);
do{
readerbook.read(reinterpret_cast(&guest),sizeof(Person));
if(strcmp(guest.Rbook[1].bookname,name) || strcmp(guest.Rbook[1].bookname,name))
{
cout<for(int i=0;i<2;i++)
if(strcmp(guest.Rbook[i].bookname,name))
cout<iflag=0;
}

}while(readerbook.tellp()!=Posend);
if(iflag)
cout<<"没有读者借阅图书!"<
}

回答2:

美女你很漂亮