rooms.h

来自「这是一个我的课后习题,要求编译一个酒店管理程序.做的不好~多多执教」· C头文件 代码 · 共 110 行

H
110
字号
#include <iostream.h>
#include <stdlib.h>
#include "Tags.h"

class Rooms
{
	//struct link list for rooms
	struct Node_tag
	{
		int reservation_Number;
	    int arrival_Day;
	    int departure_Day;
		
		Node_tag *next;
	};

private:
	//all fields
	int room_number;
	bool smoking;
	static int count;
	bool empty;

public:
    //two points to contain linked list
	Node_tag *head;
	Node_tag *tail;

    //constructor(Rooms)
    Rooms(bool s=false)
	{
		empty=true;
        room_number=count++;
	    smoking=s;
		head=tail=NULL;
	}

    //add a tag object into rooms linked list
    void enTags(Tags &a)
	{
		Node_tag *add=new Node_tag;
	    if(head==NULL)
		{
			head=add;
		}
		else
		{
			tail->next=add;
		}
		//copy all field to new node
        add->reservation_Number=a.get_Reservation_Number();
		add->arrival_Day=a.get_Arrival_day();
		add->departure_Day=a.get_Departure_day();
		add->next=NULL;
		tail=add;
	}
	
	//remove a tag from rooms linked list
    bool deTags(Tags &a)
	{
		//if linked list is empty
		if(head==NULL)
		{
			return false;
		}
		//not empty
		else
		{
			//if head is what we look for
			if(head->reservation_Number==a.get_Reservation_Number())
			{
				Node_tag *temp=new Node_tag();
				temp=head;
				head=head->next;
				delete temp;
			}
			//else
			else
			{
				Node_tag *add=head;
				Node_tag *temp=new Node_tag();
				temp=head->next;
				//go through to reach the node
                while(temp->reservation_Number!=a.get_Reservation_Number() && temp->next!=NULL)
				{
				    temp=temp->next;
					add=add->next;
				}
				//delete node
			    if(temp->reservation_Number==a.get_Reservation_Number())
				{
                    add->next=temp->next;
					delete temp;
					return true;
				}
				//cannnot found
				else
				{
					return false;
				}
			}
		}
		
	}

	//useful help method
	Node_tag *getHead(){return head;}
	Node_tag *getTail(){return tail;}
};
int Rooms::count=0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?