當前位置:編程學習大全網 - 編程語言 - 高分懸賞急求壹段源代碼

高分懸賞急求壹段源代碼

#include<iostream>

#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=1;i<=10;i++)

{

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=0;i<n;i++)

{

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

}

for(i=0;i<n;i++)

{

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=0;i<n;i++)

{

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

}

for(i=0;i<n;i++)

{

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=0;j<n;j++)

{

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

}

tfile.close();

}

void aadbook() //新增圖書

{

int num;char name[12];char writer[10];int n;

a:

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

cout<<"請錄入圖書信息:"<<endl;

cout<<"書名"<<'\t'<<"書號"<<'\t'<<"作者"<<endl;

cin>>name;fout<<name<<'\t';

cin>>num;fout<<num<<'\t';

cin>>writer;fout<<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=0;j<i;j++){

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=0;i<b;i++)

{

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

}

}

else

{

cout<<"txt文件打開出錯"<<endl;

}

is.close();

cout<<"請輸入妳要查找讀者的名字:";

cin>>a;

for(i=0;i<b;i++)

{

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");

}

}

}

圖書館的管理系統。

  • 上一篇:有關於福爾摩斯的電影嗎?
  • 下一篇:各種螺帽的規格,牙距,對邊,高度等方面的知識?
  • copyright 2024編程學習大全網