你的位置:必讀網 > 科技 > 急急急。本人要一個《圖書管理系統》用vc++編的源代碼, 20

急急急。本人要一個《圖書管理系統》用vc++編的源代碼, 20

時間:2022-03-12 13:33瀏覽次數:200

1 楼: 百度網友82e849e46


去找本書,我記得我當初在瀋陽華儲電腦書店看過有這樣的書,帶原程序的

2 楼: jiner0503


你到這裏來吧.. http://www.pudn.com/

只要你上傳5個原碼,過一會你就可以下載了.保證你會滿意的.

3 楼: 百度網友dcab366


#include
#include
#include
#include
using namespace std;
const int Maxr=100;
const int Maxb=100;
const int Maxbor=5;
class Reader
{
private:
int tag;
int no;
char name[10];
int borbook[Maxbor];
public:
Reader() {}
char *getname() {return name;}
int gettag() {return tag;}
int getno() {return no;}
void setname(char na[])
{
strcpy(name,na);

}
void delbook(){ tag=1; }
void addreader(int n,char *na)
{
tag=0;
no=n;
strcpy(name,na);
for(int i=0;iborbook[i]=0;
}
void borrowbook(int bookid)
{
for(int i=0;i{
if (borbook[i]==0)
{
borbook[i]=bookid;
return;

}
}

}
int retbook(int bookid)
{
for(int i=0;i{
if(borbook[i]==bookid)
{
borbook[i]=0;
return 1;

}
}
return 0;
}
void disp()
{
cout << setw(5) << no <name<<"借書編號:[";
for(int i=0;iif(borbook[i]!=0)
cout << borbook[i] << "|";
cout << "]"<
}
};

class RDatabase
{
private:
int top;
Reader read[Maxr];
public:
RDatabase()
{
Reader s;
top=-1;
fstream file("reader.txt",ios::in);
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file)break;
top++;
read[top]=s;
}
file.close();
}
void clear()
{
top=-1;
}
int addreader(int n,char *na)
{
Reader *p=query(n);
if (p==NULL)
{
top++;
read[top].addreader(n,na);
return 1;
}
return 0;

}
Reader *query(int readerid)
{
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid &&
read[i].gettag()==0)
{
return &read[i];
}
return NULL;
}
void disp()
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void readerdata();
~RDatabase()
{
fstream file("reader.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();

}
};
void RDatabase::readerdata()
{

char choice;
char rname[20];
int readerid;
Reader *r;
while (choice!='0')
{
cout <<"\n\n\t\t\t讀者維護\n\n\n\t\t 1 新增\n\n\t\t 2 更改\n\n\t\t 3 刪除\n\n\t\t 4 查找\n\n\t\t 5 顯示\n\n\t\t 6 全刪\n\n\t\t 0 退出"<cin >> choice;
switch (choice)
{
case '1':
cout << "輸入讀者編號:";
cin >> readerid;
cout << "輸入讀者姓名:";
cin >> rname;
addreader (readerid,rname);
break;
case '2':
cout << "輸入讀者編號:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout << " 該讀者不存在 "<break;
}
cout << "輸入新的姓名:";
cin >> rname;
r->setname(rname);
break;
case '3':
cout << " 輸入讀者編號:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<" 該讀者不存在" << endl;
break;
}
r->delbook();
break;
case '4':
cout << "讀入讀者編號:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<"該讀者不存在"<< endl;
break;
}
r->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"輸入錯誤,請從新輸入:";break;
}
}
}

class Book
{
private:
int tag;
int no;
char name[20];
int onshelf;
public:
Book(){}
char *getname() { return name; }
int getno(){ return no; }
int gettag(){ return tag; }
void setname(char na[])
{
strcpy(name,na);
}
void delbook(){ tag=1;}
void addbook(int n,char *na)
{
tag=0;
no=n;
strcpy(name,na);
onshelf=1;
}
int borrowbook()
{
if (onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void retbook()
{
onshelf=1;
}
void disp()
{
cout << setw(6) << no << setw(18) << name
<< setw(10)
<<(onshelf==1? "在架":"已借") <}
};

class BDatabase
{
private:
int top;
Book book[Maxb];
public:
BDatabase()
{
Book b;
top=-1;
fstream file("book.txt",ios::in);
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
book[top]=b;
}
file.close();
}
void clear()
{
top=-1;
}
int addbook(int n,char *na)
{
Book *p=query(n);
if (NULL==p)
{
top++;
book[top].addbook(n,na);
return 1;
}
return 0;
}
Book *query(int bookid)
{
for (int i=0;i<=top;i++)
if (book[i].getno()==bookid &&book[i].gettag()==0)
{
return &book[i];
}
return NULL;
}
void bookdata();
void disp()
{
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
book[i].disp();
}
~BDatabase()
{
fstream file("book.txt",ios::out);
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
file.write((char *)&book[i],sizeof(book[i]));
file.close();
}
};
void BDatabase::bookdata()
{
char choice;
char bname[40];
int bookid;
Book *b;
while (choice!='0')
{
cout <<"\n\n\n\t\t\t圖書維護 "<cout<<"\t\t1 新增\n \t\t2 更改\n\t\t3 刪除\n\t\t4 查找\n\t\t5 顯示\n\t\t6 全刪\n\t\t0 退出"<cin >> choice;
switch (choice)
{
case '1':
cout << "輸入圖書編號:"<cin >> bookid;
cout << "輸入圖書書名:"<cin >> bname;
addbook(bookid,bname);
break;
case '2':
cout << "輸入圖書編號:"<cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout << " 該圖書不存在 "<break;
}
cout << "輸入新的書名:"<cin >> bname;
b->setname(bname);
break;
case '3':
cout <<" 讀入圖書編號:"<cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 該圖書不存在" << endl;
break;
}
b->delbook();
break;
case '4':
cout << " 讀入圖書編號:"<cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 該圖書不存在"<< endl;
break;
}
b->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"輸入錯誤,請從新輸入:";
}
}
}

void main()
{
char choice;
int bookid,readerid;
RDatabase ReaderDB;
Reader *r;
BDatabase BookDB;
Book *b;
while(choice!='0')
{
cout <
cout <<"\t\t\t1 借書\n\n\t\t\t2 還書 \n\n\t\t\t3 圖書維護\n\n\t\t\t4 讀者維護\n\n\t\t\t0 離開"<cin >> choice;
switch (choice)
{
case '1':
cout <<" 借書讀者編號:";
cin >>readerid;
cout <<" 圖書編號: ";
cin >>bookid;
r=ReaderDB.query(readerid);
if (NULL==r)
{
cout <<" 不存在該讀者,不能借書"<< endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在該圖書,不能借書"<< endl;
break;
}
if (b->borrowbook()==0)
{
cout << " 該圖書已借出,不能借書"<< endl;
break;
}
r->borrowbook(b->getno());
break;
case '2':
cout<<"還書\n 讀者編號:";
cin >>readerid;
cout << " 圖書編號:";
cin >>bookid;
r=ReaderDB.query(readerid);
if (r==NULL)
{
cout <<" 不存在該讀者,不能還書" << endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在該圖書,不能還書" <break;
}
b->retbook();
r->retbook(b->getno());
break;
case '3':
BookDB.bookdata();
break;
case '4':
ReaderDB.readerdata();
break;
default:cout<<"輸入錯誤,請從新輸入:";

}
}
}

友情链接: 91賽普網123新聞網邁特網蓋倫網馬賽網巴比特網科斯網必讀網聰明網

必讀網娛樂生活科技教育

Copyright © 2013-2022 必讀網 版權所有