ͼÊé¹Ý¹ÜÀí³ÌÐò±¨¸æ

³ÌÐòÉè¼Æ×ۺϿγÌÉè¼Æ

void set_rtel(char *rt) //ÉèÖõ绰

{strcpy(rtel,rt);}

char *get_rtel() //»ñµÃµç»° {return rtel;}

void copy(Reader m) //¶ÁÕßReader½á¹¹Ìåcopyº¯Êý

{strcpy(rname,m.get_rname());strcpy(rclass,m.get_rclass());strcpy(rtel,m.get_rtel());}

};

//*********¶ÁÕß¹ÜÀí½á¹¹Ìå,ʵÏÖ¶Ô¶ÁÕßÓû§µÄ¹ÜÀí********* class ReaderManage {

Reader readers[50]; //¶¨Òå¶ÁÕ߽ṹÌåÊý×é¶ÔÏó,×î¶à50λ int length;

void readFile() //¶ÁÈ¡¶ÁÕßÎļþº¯Êý

{

ifstream fread; //¶¨ÒåÊäÈëÎļþÁ÷¶ÔÏófread

length=0; //¼ÆÊý if(!fread)

{cout<<\¶ÁÈ¡´ÅÅÌÎļþʧ°Ü!\

fread.open(ReaderFile,ios::binary);//ʹÎļþÁ÷ÓëÎļþ¹ØÁª,ÒÔ¶þ½øÖÆ·½Ê½´ò¿ª

int i=0;

while((fread.read((char *)&readers[i],sizeof(Reader))))//¼ÆËã²¢

·µ»ØËùÕ¼×Ö½ÚÊý

i++;

length=i;

fread.close();//¹Ø±Õ´ÅÅÌÎļþ

}

19

³ÌÐòÉè¼Æ×ۺϿγÌÉè¼Æ

void saveFile() //±£´æ¶ÁÕßÎļþ {

ofstream fwrite; //¶¨ÒåÊä³öÎļþÁ÷¶ÔÏófwrite

if(!fwrite)

{cout<<\Îļþ±£´æʧ°Ü!\\n\

fwrite.open(ReaderFile,ios::binary);//ʹÎļþÁ÷ÓëÎļþ¹ØÁª,ÒÔ¶þ

½øÖÆ·½Ê½´ò¿ª

fwrite.write((char *)readers,length*sizeof(Reader));//¼ÆËã²¢·µ

»ØËùÕ¼×Ö½ÚÊý

fwrite.close(); //¹Ø±Õ´ÅÅÌÎļþ

}

public:

ReaderManage() //¹¹Ô캯Êý,¶ÁÈ¡¶ÁÕßÎļþ

{readFile();}

~ReaderManage() //Îö¹¹º¯Êý,±£´æ¶ÁÕßÎļþ {saveFile();}

void add_reader(Reader r) //Ìí¼Ó¶ÁÕßÓû§º¯Êý

{

if(length>=50)

{cout<<\¶Ô²»Æð,×¢²áÈËÊýÒÑÂú!\\n\

readers[length].copy(r); //µ÷ÓöÁÕ߽ṹÌåcopyº¯Êý length++;

}

int search(char *rn) //°´ÐÕÃû²éÕÒ¶ÁÕߺ¯Êý {

for(int i=0;i

if(strcmp(readers[i].get_rname(),rn)==0)//ÅжÏÊÇ·ñÏàµÈ

return i;

return -1;

20

³ÌÐòÉè¼Æ×ۺϿγÌÉè¼Æ

}

bool revise(Reader reader,int i) //Ð޸ĶÁÕß×ÊÁϺ¯Êý { }

void delete_reader(int index) //ɾ³ý¶ÁÕߺ¯Êý { }

bool log_reader(Reader r) //µÇ¼ʱÅж϶ÁÕßÓû§ÊÇ·ñ´æÔÚº¯Êý { }

void reg_reader() //×¢²áÓû§º¯Êý {

char n[10]; //ÐÕÃûname char c[10]; //°à¼¶class char t[10]; //µç»°tel for(int i=0;i

if(strcmp(readers[i].get_rname(),r.get_rname())==0)

return true;

for(int i=index;i

readers[i].copy(readers[i+1]); //ÓúóÃæµÄµØÖ·¸²¸ÇÇ°ÃæµÄµØÖ· readers[i].copy(reader); //µ÷ÓöÁÕ߽ṹÌåcpoyº¯Êý return true;

length--;

return false;

Reader reader;

cout<<\ÇëÊäÈëÄúµÄÐÕÃû:\ cin>>n;

cout<<\ÇëÊäÈëÄúµÄËùÔڰ༶:\ cin>>c;

cout<<\ÇëÊäÈëÄúµÄÁªÏµµç»°:\

21

³ÌÐòÉè¼Æ×ۺϿγÌÉè¼Æ

cin>>t;

reader.set_rname(n); //µ÷ÓöÁÕ߽ṹÌåÉèÖöÁÕßÐÕÃûº¯Êý reader.set_rclass(c); //µ÷ÓöÁÕ߽ṹÌåÉèÖöÁÕ߰༶º¯Êý reader.set_rtel(t); //µ÷ÓöÁÕ߽ṹÌåÉèÖÃÁªÏµµç»°º¯Êý add_reader(reader); //µ÷ÓöÁÕ߽ṹÌåÌí¼Ó¶ÁÕߺ¯Êý

}

void show_reader() //²»´ø²ÎµÄÏÔʾ¶ÁÕßÐÅÏ¢º¯Êý {

cout<<\¶Á****Õß****ÐÅ****Ï¢****ÁÐ****cout<<\×¢²á³É¹¦!\

±í**********************\\n\\n\

cout<<\ÐÕÃû\\t\\t\\t°à¼¶\\t\\t\\tµç»°\\n\ for(int i=0;i

}

void show_reader(int i) //´ø²ÎµÄÏÔʾ¶ÁÕßÐÅÏ¢º¯Êý {

{ }

cout<

cout<<\cout<<\

cout<<\¶Á****Õß****ÐÅ****Ï¢****ÁÐ****±í**********************\\n\\n\

cout<<\ÐÕÃû\\t\\t\\t°à¼¶\\t\\t\\tµç»°\\n\ cout<

cout<<\ cout<<\

}

};

22

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)