//19.7.11 重写的药品管理全部程序 //全部程序如下: #include using namespace std; class Date { public: Date():date(1){} Date(int number):date(number){} virtual ~Date(){}; int GetDate()const{return date;} virtual void print()const =0; private: int date; }; class Book:public Date { public: Book():Price(94){} Book(float Price,int number); virtual void print()const { cout<<"图书编号为:"<getDate(); else return NULL; } Date*List::operator[](int offset)const { Node*pn=head; if(!head) return NULL; if(offset>count) return NULL; for(int i=0;igetnext(); return pn->getDate(); } Date*List::find(int number)const { Node*pn=0; for(pn=head;pn!=NULL;pn=pn->getnext()) { if(pn->getDate()->GetDate()==number) break; } if(pn==NULL) return NULL; else return pn->getDate(); } void List::repeat()const { if(!head) return; Node*pn=head; do pn->getDate()->print(); while(pn=pn->getnext()); } void List::insert(Date*pDate) { Node*pn=new Node(pDate); Node*pNow=head; Node*pNext=0; int New=pDate->GetDate(); int next=0; count++; if(!head) { head=pn; return; } if(head->getDate()->GetDate()>New) { pn->setnext(head); head=pn; return; } for(;;) { if(!pNow->getnext()) { pNow->setnext(pn); return; } pNext=pNow->getnext(); next=pNext->getDate()->GetDate(); if(next>New) { pNow->setnext(pn); pn->setnext(pNext); return; } pNow=pNext; } } int main() { List pl; Date*pDate=0; int number; float value; int choice; while (1) { cout<<"(0)退出(1)图书(2)药品:"; cin>>choice; if(!choice) break; cout<<"请输入编号:"; cin>>number; if(choice==1) { cout<<"请输入图书价格:"; cin>>value; pDate=new Book(value,number); } else { cout<<"请输入药品价格:"; cin>>value; pDate=new medica(value,number); } pl.insert(pDate); } if(pl.getfirst()==0) { cout<<"程序结束\n"; } else { pl.repeat(); cout<<"请输入所要查找的编号:"<>number; if(pl.find(number)==0) cout<<"找不到该编号。\n"; else pl.find(number)->print(); } cout<<"该链表共有"<