• 第十九章 10 图书 药品管理系统 简单


    /*
    #include <iostream>
    using namespace std;
    
    //定认枚举形常量
    enum{small,large, same};
    class Date
    {
    public:
    	Date(int i):date(i){}
    	~Date(){}
    	int compare(const Date&);
    	void print(){ cout<<date<<endl;}
    private:
    	int date;
    };
    
    int Date::compare(const Date& two)
    {
    	if(date < two.date)
    	     return small;
    	if(date > two.date){
    	     return large;
    	}else{
    	    return same;
    	}
    }
    
    //链表类
    class Node
    {
    public:
    	Node(){}
    	virtual ~Node(){}
    	virtual Node* insert(Date *one) = 0;
    	//只有拥有一个线纯虚函数的类就是抽像类,所以说Node类是一个抽像类
        virtual void print() = 0;
    private:
    };
    
    class InterNode:public Node
    {
    public:
    	InterNode(Date*one, Node*next);
    	~InterNode(){ delete Next; delete thisdate;}
    	virtual Node*insert(Date*one);
    	virtual void print(){ thisdate->print(); Next->print(); }
    private:
    	Date *thisdate;
    	Node *Next;
    };
    InterNode::InterNode(Date*one, Node*next):thisdate(one),Next(next)
    {
    
    }
    
    Node*InterNode::insert(Date*one)
    {
    	int result = thisdate->compare(*one);
    	switch(result){
    	    case same:
    		case large:
    			{
    				InterNode *NodeDate = new InterNode(one,this);
    				return NodeDate;				   
    			}
    			break;
    		case small:
    			Next = Next->insert(one);
    			return this;
    			break;		
    	}
    	return this;
    	//InterNode *NodeDate = new InterNode(one,this);
    	//return NodeDate;
    }
    
    class TailNode:public Node
    {
    public:
    	virtual Node*insert(Date*one);
    	virtual void print(){}
    private:
    };
    
    Node* TailNode::insert(Date*one)
    {
        InterNode *datenode = new InterNode(one, this);
    	return datenode;
    }
    
    class HeadNode:public Node
    {
    public:
    	HeadNode();
    	~HeadNode(){ delete Next;}
    	virtual Node*insert(Date*one);
    	virtual void print(){ Next->print(); }
    private:
    	Node *Next;
    };
    Node* HeadNode::insert(Date*one)
    {
    	Next = Next->insert(one);
    	return this;
    }
    
    HeadNode::HeadNode()
    {
    	Next = new TailNode; //尾节点指针
    }
    
    //Label类
    class Label
    {
    public:
    	Label();
    	~Label(){ delete head;} //删除头节点
    	void insert(Date*one);
    	void printall(){ head->print(); }
    private:
    	HeadNode *head; //头节点类指向头节点地址,该类我们后面定义
    	//这个标签包含了一个指向头节点的指针,我们可以通过这个指针找到头节点,HeadNode代表头节点类,该类我们稍候定义,head则是指向头节点的指针,我们用这个指针保存头节点对像的地址,那么就可以通过该地址找到头节点
    };
    Label::Label()
    {
    	head = new HeadNode;
    }
    //插入函数
    void Label::insert(Date *one)
    {
    	head->insert(one); //插入到头节点的插入函数
    }
    //该类中完成4件事,
    //1 创建头节点,并用一个指针指向它
    //2 利用头节点的插入函数将数据插入到头节点
    //3 利用头节的输出函数输出该节点保存的数据
    //4 删除头节点
    //因为链表是由头节点,中间节点和尾节点组成的,就像足球运动员是由前锋,中锋,后卫,守门员组成的一样,前锋和后卫虽然分工不同,但是都有足球运动员的特征,所以要从足球运动员这个类派生,头节点,中间节点和尾节点分工也不一样,不过有链表的特征,所以也要从链表类派生
    
    
    
    
    
    
    
    int main()
    {
    	Date *pdate;
    	int val;
    	Label ll;
    	for(;;)
    	{
    	     cout<<"什么值? (0为停止): ";
    		 cin>>val;
    		 if(!val)
    		 {
    		      break;
    		 }
    		 pdate = new Date(val);
    		 ll.insert(pdate);
    	}
    	ll.printall();
        return 0;
    }*/
    

      

  • 相关阅读:
    20210131
    20210130
    20210129
    20210128
    20210127
    例3-7
    例3-5
    例3-4
    例3-3
    例3-2
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2709106.html
Copyright © 2020-2023  润新知