diff --git a/宠物交易系统.cpp b/宠物交易系统.cpp new file mode 100644 index 0000000..bd0aa20 --- /dev/null +++ b/宠物交易系统.cpp @@ -0,0 +1,422 @@ +#include +#include +#include +#include +#include"list" +using namespace std; +class Data// ÈÕÆÚÀà +{ +public: + void set_time( ); + void show_time( ); +private: + bool is_time(int, int, int); + int year; + int month; + int day; +}; +void Data::set_time( ) +{ + char c1,c2; + cout<<"ÇëÊäÈëÈÕÆÚ(¸ñʽÄê-ÔÂ-ÈÕ)"<>year>>c1>>month>>c2>>day; + if(c1!='-'||c2!='-') + cout<<"¸ñʽ²»ÕýÈ·£¬ÇëÖØÐÂÊäÈë"<PetList;//ʹÓÃË«ÏòÁ´±í +//Ìí¼Ó³èÎïÐÅÏ¢ +void PetAnimals::Insert() +{ + PetAnimals Pet; + char ch; + int symbol=0;//ÅжϳèÎïÐÅÏ¢ÊÇ·ñ´æÔÚ + list::iterator first,last; + first=PetList.begin();//begin()Ö¸Á´±í¿ªÊ¼´¦ + last=PetList.end();//end()Ö¸Á´±í½áβ´¦ +do{ + cout<<"¡¾ÇëÊäÈë³èÎïÏà¹ØÐÅÏ¢£¡¡¿"<>Pet.Cnumber; + cout<<"Ãû³Æ:"; + cin>>Pet.Cname; + cout<<"ÄêÁä:"; + cin>>Pet.Cage; + cout<<"ÖØÁ¿:"; + cin>>Pet.Cweight; + cout<<"ÖÖÀà:"; + cin>>Pet.Ctype; + cout<<"¼Û¸ñ:"; + cin>>Pet.Cprice; + cout<<"Ö÷ÈË:"; + cin>>Pet.Cpeople; + for( ; first != last ; ++first ) + { + if((Pet.Cname==(*first).Cname)&&(Pet.Cprice==(*first).Cprice) + &&(Pet.Ctype==(*first).Ctype))//¼ÙÉè³èÎï¿ÉÒÔÖØÃû + { + symbol=1;// Èç¹û´æÔڴ˳èÎï + cout<>ch; + } +while(ch=='Y'||ch=='y'); + } + +//²éÕÒ³èÎïÐÅÏ¢ +bool PetAnimals::Look() +{ + string name,price,type; + int symbol=0; + int option; + list ::iterator first,last; + do + { + cout<<"\t¡¾ÇëÊäÈëÄã²éÕҵķ½Ê½¡¿£¡"<>option; + switch(option) + { + case 1: cout<<"ÇëÊäÈëÃû³Æ£º"; + cin>>name;break; + case 2: cout<<"ÇëÊäÈë¼Û¸ñ£º"; + cin>>price;break; + case 3: cout<<"ÇëÊäÈëÖÖÀࣺ"; + cin>>type;break; + case 4:break; + } + first=PetList.begin(); + last=PetList.end(); + for(;first!=last;++first) + { + if((name==(*first).Cname)&&(option==1)) + { + symbol=1; + cout<<"³èÎïÃû³ÆÎª"+(*first).Cname+"³èÎïÐÅÏ¢ÈçÏ£º"<>name; + cout<<"ÇëÊäÈë¼Û¸ñ:"; + cin>>price; + cout<<"ÇëÊäÈëÖÖÀà:"; + cin>>type; + list ::iterator first,last; + first=PetList.begin(); + last=PetList.end(); + for(;first!=last;++first) + { + if((name==(*first).Cname)&&(price==(*first).Cprice)&&(type==(*first).Ctype)) + { + symbol=1; + cout<>pet.Cage; + cout<<"ÖØÁ¿:"; + cin>>pet.Cweight; + + cout<<"Ö÷ÈË:"; + cin>>pet.Cpeople; + pet.Cname=name; + pet.Cprice=price; + pet.Ctype=type; + for(;first!=last;++first) + { + if((name==(*first).Cname)&&(price==(*first).Cprice)&&(type==(*first).Ctype)) + { + (*first)=pet; + } + } + return true; + } + else + { + cout<<"ûÓиóèÎïÐÅÏ¢!"; + return false; + } +} + +//ÏÔʾËùÓгèÎïÐÅÏ¢ +void PetAnimals::Show() +{ + list ::iterator first,last,it; + first=PetList.begin(); + last=PetList.end(); + for(;first!=last;++first) + { + cout<<"******************ÄúµÄ³èÎïÐÅÏ¢**********************"<>FileName; + if(FileName.find (".")>FileName.length()) + { + FileName=FileName+".txt"; + } + //°ÑStringÐ͵Ä×Ö·û´®×ª»»³Échar*Ð͵Ä×Ö·û´® + strcpy(file,FileName.c_str()); + ofstream fout(file); + if(!fout) + { + cout<<"¡ïÎļþдÈëʧ°Ü!Çë¼ì²éÄúµÄÎļþÃû!"<::iterator first,last; + first=PetList.begin(); + last=PetList.end(); + for(;first!=last;++first) + { + fout<>FileName; + if(FileName.find (".")>FileName.length()) + { + FileName=FileName+".txt"; + } + strcpy(file,FileName.c_str()); + ifstream fin(file); + int index; + if(!fin) + { + cout<<"ÎļþдÈëʧ°Ü!Çë¼ì²éÄúµÄÎļþÃû£¡"<>str; + index=str.find(":");//Òª":"ºóµÄÄÚÈÝ + pet.Cnumber =str.substr(index+1);//Òª":"ºóµÄÊ£ÏÂ×Ö·û´® + fin>>str; + index=str.find (":"); + pet.Cname =str.substr(index+1); + fin>>str; + index=str.find (":"); + pet.Cage =str.substr(index+1); + fin>>str; + index=str.find (":"); + pet.Cweight =str.substr(index+1); + fin>>str; + index=str.find (":"); + pet.Ctype =str.substr(index+1); + + fin>>str; + index=str.find (":"); + pet.Cprice=str.substr(index+1); + fin>>str; + index=str.find (":"); + pet.Cpeople =str.substr(index+1); + PetList.insert(PetList.end(),pet); + + } + + cout<<" Îļþ¶ÁÈ¡³É¹¦! "<>option; + switch(option)//Ñ¡Ôñ²»Í¬º¯Êý¹¦ÄÜ + { + case 1: { pet.Insert(); break; } + case 2: { pet.Look(); break; } + case 3: { pet.Change(); break; } + case 4: { pet.Show(); break; } + + case 5: { pet.Write(); break; } + case 6: { pet.Read(); break; } + case 7: { break ; } + } + } + while(option != 8); + return 0; +}