當前位置:歷史故事大全網 - 圖書館 - 用c語言編寫圖書館管理程序

用c語言編寫圖書館管理程序

這是c++

# include & ltiostream & gt

# include & ltfstream & gt

# include & ltconio.h & gt

使用命名空間std

圖書管理員類//圖書管理員類

{

公共:

圖書管理員();

Librarian(int n,int j,char na[20],int w);

int get number();

int getjobage();

char * getname();

int get wages();

void reset jobage(int j);

void reset wages(int w);

void reset name(char na[20]);

私人:

int數;

int jobage

char name[20];

int工資;

};

Librarian::Librarian() //其函數的實現

{

數字= 0;

char b[20]= "沒有人";

jobage = 0;

strcpy(名稱,b);

}

Librarian::Librarian(int n,int j,char na[20],int w)

{

數字= n;

jobage = j;

strcpy(姓名,不適用);

工資= w;

}

int Librarian::getjobage()

{返回jobage}

char *Librarian::getname()

{返回姓名;}

int Librarian::getnumber()

{返回號碼;}

int Librarian::getwages()

{返還工資;}

void Librarian::reset jobage(int j)

{

jobage = j;

}

void Librarian::reset name(char na[20])

{

strcpy(姓名,不適用);

}

void Librarian::resetwages(int w)

{

工資= w;

}

類讀取器//讀取器類

{

私人:

int數;

int age

char name[20];

char borrow book[20];

公共:

reader();

reader(int c,int a,char b[20],char e[20]);

int get number();

int getage();

char * getname();

char * getborrowbook();

void rework borrow book(char a[20]);

};

Reader::reader() //其函數的實現

{

Char a[20]=“沒有人”;

Char c[20]=“不借書”;

數字= 0;

年齡= 0;

}

reader::reader(int a,int c,char d[20],char e[20])

{

數字= a;

年齡= c;

strcpy(名稱,d);

strcpy(borrowbook,e);

}

int reader::get number(){ return number;}

int reader::getage(){ return age;}

char * reader::getname(){ return name;}

char * reader::getborrowbook(){ return borrowbook;}

void reader::rework borrow book(char a[20]){ strcpy(borrow book,a);}

結構書//書的結構

{

int num

char name[20];

char writer[20];

};

voidobookinf()//輸出所有圖書信息。

{

int I;

ifstream infile("allbook.txt ",IOs::in);

充電線[50];

cout & lt& lt"標題"

for(I = 1;我& lt=10;i++)

{

infile.getline(line,50,' \ n ');

cout & lt& ltline & lt& ltendl

}

infile . close();

}

void serchlanif()//圖書管理員信息函數

{

int n,I;

ifstream文件(" serchlanif . txt ");

if(file){ file & gt;& gtn;file . close();}

else { cout & lt& lt“沒有圖書管理員”;退出(0);}

ifstream是(" controlloer.txt ",IOs _ base::binary);

如果(為)

{

圖書管理員* A =新圖書管理員[n];

for(I = 0;我& ltn;i++)

{

is . read((char *)& amp;A[i],sizeof(A[I]);

}

for(I = 0;我& ltn;i++)

{

cout & lt& lt“沒有”< & lt\ t ' & lt& lt“服務年限”

cout & lt& lt甲[我]。get number()& lt;& lt" \ t " & lt& lt甲[我]。getjobage()& lt;& lt" \ t " & lt& lt甲[我]。getname()& lt;& lt" \ t " & lt& lt甲[我]。get wages()& lt;& ltendl

}

}

其他

{

cout & lt& lt"打開txt文件時出錯'"

}

is . close();

}

void library()//庫的全部信息

{

系統(“cls”);

系統(" color 2e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt“我校圖書館由本部圖書館和彭州校區圖書館組成,總面積* * * *平方米”;

cout & lt& lt“(圖書館現在有* * *萬冊書,* * *萬冊書,* * *萬冊書,* * *萬冊書* * * * *萬冊書),”;

cout & lt& lt“* * *現有圖書館工作人員姓名”;

cout & lt& lt“圖書館現有的現代化設備價值* * * *萬余元………………”< & ltendl

}

Void storelibrarian() //存儲新管理員的信息。

{

整數,n,數字,工資;

char name[20];

ifstream文件(" serchlanif . txt ");

if(file){ file & gt;& gtn;file . close();}

else { n = 0;}

cout & lt& lt"現有圖書館員的數量:";

cout & lt& ltn & lt& ltendl

cout & lt& lt請輸入新圖書管理員的編號、服務年限、姓名和工資:

CIN & gt;& gtnum & gt& gt年齡& gt& gt名稱& gt& gt工資;

圖書管理員A(人數、年齡、姓名、工資);

cout & lt& lt人數、服務年限、姓名和工資

cout & lt& lta . get number()& lt;& lt" " " & lt& lta . getjobage()& lt;& lt" " " & lt& lta . getname()& lt;& lt" " " & lt& lta . get wages()& lt;& ltendl

of stream outfile(" control loer . txt ",IOs _ base::app);

outfile . write((char *)& amp;A,sizeof(A));

outfile . close();

n++;

of stream tfile(" serchlanif . txt ");

tfile & lt& ltn;

tfile . close();

cout & lt& lt“保存成功!”;

}

Void reLaninf() //修改圖書管理員

{

int i,n,h,jobage,wage,j;

char name[20];

ifstream文件(" serchlanif . txt ");

if(file){ file & gt;& gtn;file . close();}

else { cout & lt& lt“沒有圖書管理員”;

退出(0);}

cout & lt& lt"現有圖書館員的數量:";

cout & lt& ltn & lt& ltendl

圖書管理員* A =新圖書管理員[n];

ifstream是(" controlloer.txt ",IOs _ base::binary);

如果(為)

{

for(I = 0;我& ltn;i++)

{

is . read((char *)& amp;A[i],sizeof(A[I]);

}

for(I = 0;我& ltn;i++)

{

cout & lt& lt人數、服務年限、姓名和工資

cout & lt& lt甲[我]。get number()& lt;& lt" " " & lt& lt甲[我]。getjobage()& lt;& lt" " " & lt& lt甲[我]。getname()& lt;& lt" " " & lt& lt甲[我]。get wages()& lt;& ltendl

}

}

其他

{

cout & lt& lt"打開文件時出錯"

}

is . close();

cout & lt& lt"請選擇您要修改的管理員號碼:";

CIN & gt;& gth;

cout & lt& lt輸入新的服務年限、姓名和薪金。

CIN & gt;& gtjobage & gt& gt名稱& gt& gt工資;

A[h-1]。reset jobage(jobage);

A[h-1]。resetname(名稱);

A[h-1]。工資;

cout & lt& lt"此管理員的修改名稱是:"

ofstream tfile("controlloer.txt ",IOs _ base::binary);

for(j = 0;j & ltn;j++)

{

tfile . write((char *)& amp;A[j],sizeof(A[j]);

}

tfile . close();

}

void EAD book()//添加新書

{

int num字符名稱[12];char writer[10];int n;

答:

ofstream fout("allbook.txt ",IOs::app);

cout & lt& lt"請輸入圖書信息:"

cout & lt& lt"標題"

CIN & gt;& gt姓名;fout & lt& lt名稱& lt& lt\ t ';

CIN & gt;& gtnumfout & lt& ltnum & lt& lt\ t ';

CIN & gt;& gt作家;fout & lt& lt作家& lt& lt\ n ';

fout . close();

cout & lt& lt“繼續進入嗎?1.是2。沒有"

CIN & gt;& gtn;

如果(n==1)

轉到a;

其他

{ void studentland();

student land();}

}

Void delate() //刪除函數

{ int m;

cout & lt& lt"選擇操作選項:"

cout & lt& lt"1.刪除所有信息"

cout & lt& lt"2.單壹刪除”

CIN & gt;& gtm;

如果(m==1)

{ofstream文件(" allbook.txt ",IOs::trunc);

cout & lt& lt“全部刪除,按任意鍵返回!”& lt& ltendl

file . close();

getch();

系統(“cls”);

void studentland();

student land();

}

char str[10][80],buf[20];

答:

int i=0,flag=100,c = 0;

ifstream fin(" all book . txt ");

如果(!fin){

cout & lt& lt"文件打開失敗!"& lt& ltendl

getch();

系統(“cls”);

void studentland();

student land();

}

cout & lt& lt"請輸入您想刪除的書名:"

CIN & gt;& gtbuf

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 & lt& lt“沒有您想刪除的書!再按1,否則0……”< & ltendl

int b;

CIN & gt;& gtb;

if(b==1)轉到a;

else c = 1;

}

if(c==0){

of stream fout(" all book . txt ");

for(int j = 0;j & lt我;j++){

if(j==flag)繼續;

fout & lt& ltstr[j]& lt;& ltendl

}

fout . close();

cout & lt& lt“妳要刪除的書的信息已經被刪除了。繼續按1,否則按0……”< & ltendl

int b;

CIN & gt;& gtb;

if(b==1)轉到a;

}

cout & lt& lt"操作已經結束,按任意鍵返回..."< & ltendl

getch();

系統(“cls”);

void studentland();

student land();

}

Void searchbook() //查找書籍

{

答:

ifstream fin

int flag=0,b,長度;

char string[20];

char f[200];char g[200];

fin . open(" all book . txt ");

如果(!鰭)

{

cout & lt& lt"打開f1.dat錯誤....."& lt& ltendl

退出(1);

}

while(1)

{

cout & lt& lt請輸入標題:“;

CIN & gt;& gtstr

strcat(str," \ t ");

length = strlen(str);

cout & lt& lt“-”& lt;& ltendl

while(fin.getline(f,199))

{

strcpy(g,f);

if(strncmp(str,f,length)==0)

{

flag = 1;

打破;

}

}

if(flag==1)

{

cout & lt& lt"查詢的書已經找到:"

cout & lt& lt“-”& lt;& ltendl

cout & lt& lt"標題"

cout & lt& ltg & lt& ltendl

cout & lt& lt“-”& lt;& ltendl

flag = 0;

cout & lt& lt要繼續查詢,請按1,否則請按0

CIN & gt;& gtb;

if(b = = 0)break;

}

其他

{

fin . close();

cout & lt& lt“如果沒有書,繼續按1,否則按0……”& lt& ltendl

CIN & gt;& gtb;

if(b = = 0)break;

轉到a;

}

}

fin . close();

cout & lt& lt"查詢結束後,按任意鍵返回..."< & ltendl

getch();

系統(“cls”);

void studentland();

student land();

}

void sea hreader()//查詢閱讀器信息

{

答:

ifstream fin

int flag=0,b,長度;

char string[20];

char f[200];char g[200];

fin . open(" reader num . txt ");

如果(!鰭)

{

cout & lt& lt“沒有這個信息檔案!”& lt& ltendl

退出(1);

}

while(1)

{

cout & lt& lt"請輸入您要查找的讀者的姓名:";

CIN & gt;& gtstr

strcat(str," \ t ");

length = strlen(str);

cout & lt& lt“-”& lt;& ltendl

while(fin.getline(f,199))

{

strcpy(g,f);

if(strncmp(str,f,length)==0)

{

flag = 1;

打破;

}

}

if(flag==1)

{

cout & lt& lt"已找到查詢的讀取器:"

cout & lt& lt“-”& lt;& ltendl

cout & lt& lt"名稱"

cout & lt& ltg & lt& ltendl

cout & lt& lt“-”& lt;& ltendl

flag = 0;

cout & lt& lt要繼續查詢,請按1,否則請按0

CIN & gt;& gtb;

if(b = = 0)break;

轉到a;

}

其他

{

fin . close();

cout & lt& lt“如果沒有這個人,繼續按1,否則按0……”& lt& ltendl

CIN & gt;& gtb;

if(b = = 0)break;

轉到a;

}

}

fin . close();

cout & lt& lt"查詢結束後,按任意鍵返回..."< & ltendl

getch();

系統(“cls”);

void studentland();

student land();

}

/* void sea hreader()//查詢讀者信息

{

int i,b,h = 0;

char a[20];

ifstream文件(" reader num . txt ");

if(file){ file & gt;& gtb;file . close();}

else { cout & lt& lt”沒有文件”;}

cout & lt& lt"現有讀者的數量:";

cout & lt& ltb & lt& ltendl

讀者* A =新讀者[b];

ifstream是(" reader.txt ",IOs _ base::binary);

如果(為)

{

for(I = 0;我& ltb;i++)

{

is . read((char *)& amp;A[i],sizeof(A[I]);

}

}

其他

{

cout & lt& lt"打開txt文件時出錯"

}

is . close();

cout & lt& lt"請輸入您要查找的讀者的姓名:";

CIN & gt;& gta;

for(I = 0;我& ltb;i++)

{

if(strcmp(A[i].getname(),a)==0)

{

cout & lt& lt“圖書的數量、年代、名稱和借閱情況”< & ltendl

cout & lt& lt甲[我]。get number()& lt;& lt" " " & lt& lt甲[我]。getage()& lt;& lt" " " & lt& lt甲[我]。getname()& lt;& lt" " " & lt& lt甲[我]。getborrowbook()& lt;& ltendl

h++;

}

}

if(h = = 0)cout & lt;& lt“沒有這樣的讀者!”;

}

*/

Void Librarianland() //管理員登錄函數

{

int q,l=1,I,h;

系統(“cls”);

系統(" color 2e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt要立即確認您的身份,請輸入密碼:

CIN & gt;& gt我;

當(l)

{

如果(i==00000)

{

系統(“cls”);

系統("顏色3e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt" | * * * * * * * " & lt& lt0,返回上壹級菜單。< & lt“* * * * * * * |”& lt;& ltendl

cout & lt& lt" " " & lt& lt" | * * * * * * * " & lt& lt1,查詢圖書管理員信息

cout & lt& lt" " " & lt& lt" | * * * * * * * " & lt& lt"2.存儲新的管理員信息。

cout & lt& lt" " " & lt& lt" | * * * * * * * " & lt& lt"3.修改圖書管理員的信息"

cout & lt& lt" " " & lt& lt" | * * * * * * * " & lt& lt“4、新書”

cout & lt& lt" " " & lt& lt" | * * * * * * * " & lt& lt“5、刪除書籍”

cout & lt& lt”請選擇要執行的操作:“;

CIN & gt;& gtq;

if(q & gt;= 0 & amp& ampq & lt6)

{

開關(q)

{

案例0:

l = 0;

打破;

案例1:serchlanif();

系統(“暫停”);

打破;

案例二:store librarian();

系統(“暫停”);

案例三:reLaninf();

系統(“暫停”);

打破;

案例4:

void aad book();

aadbook();

打破;

案例5:

void delate();

delate();

打破;

默認值:

打破;

}

}

其他

{

系統(“cls”);

系統("顏色4e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt“無效操作!”& lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

系統(“暫停”);

}

}

其他

{

系統(“cls”);

系統(" color 2e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt"身份確認失敗"

cout & lt& lt" " " & lt& lt“要不要再確認壹下!”& lt& ltendl

cout & lt& lt" " " & lt& lt“重新確認請按1,放棄請按0”< & lt;endl

cout & lt& lt" ";

CIN & gt;& gth;

if(h = = 0)l = 0;

如果(h==1)

{

系統(“cls”);

系統(" color 2e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt請再次輸入密碼:“;

CIN & gt;& gt我;

}

}

}

}

Void studentland() //學生登錄函數

{

int h;

char l = ' y

while(l=='y ')

{

系統(“cls”);

系統("顏色3e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt“* * * * * * *”& lt;& lt|要輸出庫信息,請按1 |。

cout & lt& lt" " " & lt& lt“* * * * * * *”& lt;& lt|關於圖書館的壹般信息,請按2 |。

cout & lt& lt" " " & lt& lt“* * * * * * *”& lt;& lt|要按標題查找書籍,請按3 |。

cout & lt& lt" " " & lt& lt“* * * * * * *”& lt;& lt|關於讀者的信息,請按4 |。

cout & lt& lt" " " & lt& lt“* * * * * * *”& lt;& lt|要返回上壹級菜單,請按0 |。

cout & lt& lt"請選擇您將執行的操作:";

CIN & gt;& gth;

如果(h & gt= 0 & amp& amph & lt5)

開關(h)

{

案例0:

l = ' n

打破;

案例1:outbook INF();

系統(“暫停”);

打破;

案例二:libary();

系統(“暫停”);

打破;

案例三:search book();

系統(“暫停”);

打破;

案例四:sea hreader();

系統(“暫停”);

打破;

}

其他

{

系統(“cls”);

系統("顏色4e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt“妳的操作無效!!!!"& lt& ltendl

系統(“暫停”);

}

}

}

Void main() //主函數

{

int h,l = 1;

當(l)

{

系統(“cls”);

系統("顏色7c ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt“圖書管理系統”

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt“-”& lt;& ltendl

cout & lt& lt" " " & lt& lt" ||請按1 | | " & lt;& ltendl

cout & lt& lt" " " & lt& lt" |||請按2 || "

cout & lt& lt" " " & lt& lt|||要退出系統,請按0 ||。

cout & lt& lt“-”& lt;& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt"請選擇登錄方式:";

CIN & gt;& gth;

如果(h & gt= 0 & amp& amph & lt3)

{

開關(h)

{

案例0:

cout & lt& lt“感謝您光臨我們的圖書館!”& lt& ltendl

退出(0);

案例1:

librarianland();

系統(“暫停”);

打破;

案例二:

student land();

系統(“暫停”);

打破;

}

}

其他

{

系統(“cls”);

系統("顏色4e ");

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& ltendl

cout & lt& lt" " " & lt& lt“妳的操作無效!!!!"& lt& ltendl

系統(“暫停”);

}

}

}

  • 上一篇:老先生傳信,化胡為佛是什麽意思?
  • 下一篇:搞笑文案爆笑。
  • copyright 2024歷史故事大全網