⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 我大一时候做的C++课程设计
💻 CPP
字号:
#include"person.h"
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip.h>

person *add();
bool jadge(person *head,person *q);
void paixu(person *head);
void print(person *head);
void create(person *head,person *tail);
void print_room(person *head);
void print11(person *head);
bool jsvoid(person *head);

int tt=0;
int count=0;
int room[60];
person a[60];

void main()
{
	
	person *head=NULL, *tail=NULL, *temp=NULL;
	head=tail=new person;
	tail->next=NULL;
	char s;
	
	for(int ii=0;; ii++)
	{
		cout <<"*****请选择1、登记  2、输出  3、退出*****" << endl;
		cin>>s;
		system("cls");
		if(s=='1')
		{
			if(tt==0)
				create(head,tail);
			else
			{
				temp=head;
				while(temp->next!=NULL)
				{
					temp=temp->next;
				}
				tail=temp;
				create(head,tail);
			}
			paixu(head);	
		}
		if(s=='2')
		{
			if(jsvoid(head))
			{
				cout <<"**************当前登记人员有:****************"<< endl;
				cout<<setw(10)<<"姓名"<<setw(10)<<"性别"<<setw(10)<<"年龄"<<setw(10)<<"房间号"<< endl;
				print(head);
			}
			else
				cout << "当前为空!"<< endl;
		}
			
		if(s=='3')
			break;
		system("pause");
	}	
}



person *add()
{
	person *p=new person;
	char name[20];
	char sex;
	int age;
	int room;
	cout << "请输入姓名、性别(m or f)、年龄和房间号:" << endl;
	cin >> name >> sex >> age >> room;
	p->set_inf(name,sex,age,room);
	return p;
}

bool jadge(person *head,person *q)
{
	for(person *t=head->next; t!=NULL; t=t->next)
	{
		if(t->get_room()==q->get_room())
			return false;		
	}
	return true;
}

/*void paixu(person *head)
{
	int max;
	
	person *p1, *p2,*t=NULL,*tp;
	for(p1=head->next;p1->next->next!=NULL; p1=p1->next)
	{
		max=head->next->get_room();
		for(p2=p1->next; p2->next!=NULL; p2=p2->next)
			if(max<p2->get_room())
			{
				max=p2->get_room();
				tp=p2;
			}
		*t=*p1;
		*p1=*tp;
		*tp=*t;
	}
}*/	
void paixu(person *head)
{
	int i=1;
	person *temp;
	temp=head->next;
	while(temp!=NULL)
	{
		a[i++]=*temp;
		temp=temp->next;
	}
	int min=a[1].get_room();
	int t;
	person tp;
	for(i=1; i<59; i++)
	{
		min=a[i].get_room();
		for(int j=i+1;j<60;j++)
		{
			if(min>=a[j].get_room())
			{
				min=a[j].get_room();
				t=j;
			}
		}
		tp=a[t];
		a[t]=a[i];
		a[i]=tp;
	}

/*	i=1;
	person *tail;
	tail=temp=head->next;	
	while(i<60)
	{
		tail->next=&a[i];
		tail=&a[i];
		tail->next=NULL;
		i++;
	}*/

	
}

void print(person *head)
{
	if(head->next!=NULL)
	{
		for(int t1=1; t1<=count; t1++)
			a[t1].print();
	}
	else
		cout << "当前为空!" <<endl;
}
void print11(person *head)
{
	person *temp;
	temp=head->next;
	for(int t=0; t<2;t++)
	{
		temp->print();
		temp=temp->next;
	}

}


void create(person *head,person *tail)
{
	int n;
	cout << "请输入本次登记的人数:" ;
	cin >> n;
	for(int i=0; i<n ;i++)
	{
		bool f=true;
		if(tt==0)
		{
			person *q=add();
			tail->next=q;
			tail=q;
			tail->next=NULL;
			count++;
		}
		else
		for(int t=0; ; t++)
		{
			f=true;
			person *q=add();
			f=jadge(head,q);
			if(f)
			{	
				tail->next=q;
				tail=q;
				tail->next=NULL;
				count++;
				break;
			}
			else
			{	
				cout << "此房间已被使用,请更换后重新输入!" << endl;
				print_room(head);
			}
			
		}
		tt++;
	}
	cout <<"登记完成!" << endl;

	
}

void print_room(person *head)
{
	int tcount=0;
	for(int i=1;i<60;i++)
		room[i]=0;
	person *temp;
	temp=head->next;
	while(temp!=0)
	{
		room[temp->get_room()]=1;
		temp=temp->next;

	}
	cout << "可用房间有:" << endl;
	for( i=1;i<60;i++)
	{
		if(room[i]==0)
		{
			cout << i <<"\t";
			tcount++;
		}
		if(tcount%10==0)
			cout << endl;
	}
	cout << endl;
}

bool jsvoid(person *head)
{
	bool f;
	if(head->next!=NULL)
		f=true;
	else
		f=false;
	return f;
}

⌨️ 快捷键说明

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