宿舍信息管理系统

Posted RikkaTheWorld

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了宿舍信息管理系统相关的知识,希望对你有一定的参考价值。

随便写的,没有数据结构算法的核心,是函数的拼凑。


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<windows.h>
using namespace std;
#define MAX 100
int Total;
int domes[MAX][MAX];
struct edg{             //构造结构体,创建学生信息的结构体数组,其中的信息包含名字,宿舍房号以及学号 。 
    string name;
	int   domenumber;
	int  number;
}student[MAX];

void menu()            //主菜单的函数包含3个功能(新建,排序,查询)。 
{
     cout<<"\t\t                   ***                  "<<endl;
     cout<<"\t\t                 **   **                "<<endl;
     cout<<"\t\t              ***       ***             "<<endl;
     cout<<"\t\t           ***              ***         "<<endl;
     cout<<"\t\t        ***                    ***      "<<endl;
     cout<<"\t\t     ***                          ***   "<<endl;
     cout<<"\t\t  ***       欢迎进入宿舍管理系统     ***"<<endl;
     cout<<"\t\t  **************************************"<<endl;
     cout<<"\t\t  *     制作人:计算机1503 谢俊宏      *"<<endl;
     cout<<"\t\t  **************************************"<<endl;
     cout<<"\t\t  *        1.  新建宿舍名单            *"<<endl;
     cout<<"\t\t  *        2.  排序宿舍信息            *"<<endl;
     cout<<"\t\t  *        3.  查询宿舍信息            *"<<endl;
     cout<<"\t\t  *        4.  删除宿舍信息            *"<<endl;
     cout<<"\t\t  *        0.  退出系统                *"<<endl;
     cout<<"\t\t  **************************************"<<endl;
     cout<<endl<<endl;
     cout<<"请输入你想要进行操作的代号:";
}

void build()  //新建学生信息 
{
      int i;
      string a;
      int c,b;
      system("cls");
      
      cout<<"请输入要录入的人数:"<<endl;     //录入的人数为Total 
      cin>>Total;
      
      cout<<"请分别输入他们的信息:"<<endl;
      
      for(i=1;i<=Total;i++)                //为每个同学输入信息 
      {
      	cout<<"输入第"<<i<<"个学生的姓名:" ;
        cin>>a;
      	student[i].name=a;
      	cout<<"输入第"<<i<<"个学生的学号:" ;
        cin>>b;
        student[i].number=b;
        cout<<"输入第"<<i<<"个学生的宿舍号:" ;
        cin>>c;
        student[i].domenumber=c;
        cout<<endl;
      }
      return ;
}


int  binarynum(int left,int right,int key)    // 用递归二分的方法求出学号在结构体数组中的位置 
{
	if(left>right) return -1;
	int mid=(left+right)<<1;                //使用位运算<<1 让计算更有效率 
	if(student[mid].number==key) return mid;
	else if(student[mid].number<key) return binarynum(mid+1,right,key);
	else return binarynum(left,mid,key);
}

void paixumenu()                                         //排序函数 
{
    string choice;
    int i,m,j;
    system("cls"); 
     cout<<"请输入排序的方式(1:按学号排序,2:按房号排序,3:按名字排序):"<<endl;      //三个排序方法 
      while(1)                                           //对输入的信息进行容错处理,防止出现输入字母的情况 
	{
		m=0;
         cin>>choice;
	     if(strlen(choice.c_str())>1)
		 {
		  m=1;
	 	cout<<"输入错误,请重新输入";
	     } 
	  if(choice[0]>'3'||choice[0]<'1')
	   {
	  	cout<<"输入数字没有此选项请重新输入"<<endl;
		   m=1; 
	   }
	   if(m==0)
	   break;
	}
	
     if(choice[0]=='1')                                //进行以学号为关键字的排序 
     {
     	for(i=1;i<=Total;i++)                          //用冒泡排序法进行排序 
           for(j=1;j<Total-i+1; j++)
			if(student[j].number>=student[j+1].number)  
			 {
			 	edg temp=student[j]; 
			 	student[j]=student[j+1];
			 	student[j+1]=temp;
			 }
		cout<<"姓名\t\t学号\t\t宿舍号"<<endl;
		for(i=1;i<=Total;i++)
		{
			cout<<student[i].name<<"\t\t"<<student[i].number<<"\t\t"<<student[i].domenumber<<endl; 
		}
		cout<<endl;
     }
     
     if(choice[0]=='2')                             //以按宿舍号的关键字进行排序 
     {
       	for(i=1;i<=Total;i++)                       //用冒泡排序法进行排序    
           for(j=1;j<Total-i+1; j++)
			if(student[j].domenumber>=student[j+1].domenumber)
			 {
			 	edg temp=student[j];
			 	student[j]=student[j+1];
			 	student[j+1]=temp;
			 }
			 
		cout<<"姓名\t\t学号\t\t宿舍号"<<endl;
		for(i=1;i<=Total;i++)             
		{
			cout<<student[i].name<<"\t\t"<<student[i].number<<"\t\t"<<student[i].domenumber<<endl; 
		}
			cout<<endl;
     }
     
     if(choice[0]=='3')                             //以按学生姓名的关键字进行排序 
     {
       	for(i=1;i<=Total;i++) 
           for(j=1;j<Total-i+1; j++)                //用冒泡排序法进行排序    
			if(strcmp(student[j].name.c_str(),student[j+1].name.c_str())>=0)
			 {
			 	edg temp=student[j];
			 	student[j]=student[j+1];
			 	student[j+1]=temp;
			 }
			 
		cout<<"姓名\t\t学号\t\t宿舍号"<<endl;
		for(i=1;i<=Total;i++)
		{
			cout<<student[i].name<<"\t\t"<<student[i].number<<"\t\t"<<student[i].domenumber<<endl; 
		}
			cout<<endl;
     }
     
     return ;
}

void query()                              //查询函数 
{ 
    string choice;
    int m,i,j;
    string a,choice1;
    string b,c;
    system("cls");
     cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl;  //三个关键字进行查找 
     while(1)
    {
    	while(1)                       //对输入的信息进行容错处理,防止出现输入字母的情况 
	{
		m=0;
         cin>>choice;
	     if(strlen(choice.c_str())>1)
		 {
		  m=1;
	 	cout<<"输入错误,请重新输入";
	     } 
	  if(choice[0]>'3'||choice[0]<'1')
	   {
	  	cout<<"输入数字没有此选项请重新输入"<<endl;
		   m=1; 
	   }
	   if(m==0)
	   break;
	}
	
	 if(choice[0]=='1')                      //以 名字为关键字进行查询 
     {
     	cout<<"输入你想要查找学生的名字:";
     	cin>>a;
     	
     	for(i=1;i<=Total;i++)               
     	 {
     		if(strcmp(student[i].name.c_str(),a.c_str())==0)        //使用strcmp及.c_str进行比较 
     		break;
		 }
		 
		 if(i!=Total+1)
		 {
		 	cout<<"目标学生的学号为:"<<student[i].number<<"  宿舍号为"<<student[i].domenumber<<endl;
		 	cout<<"是否继续进行此操作(是为y,不是为n):";
		    cin>>choice1;
		    if(choice1[0]=='y'){cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl; continue;}
		    else break;
		 }
		 else 
		 {cout<<"你想要查找的学生没有记录入系统中,是否继续进行此操作(是为y,不是为n):";
		 cin>>choice1;
			if(choice1[0]=='y'){cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl<<endl; continue;}
		 else break;
	     }
	 }
	 
	 if(choice[0]=='2')                          //以按照学号的关键字进行查询 
     {
     	cout<<"输入你想要查找学生的学号:";
     	cin>>b;
     	int sss=0,k=1;                           //对输入的信息进行容错处理,防止出现输入字母的情况 
         int len=b.size();
         for(int j=len-1;j>=0;j--)
         {
         		sss+=((int)b[j]-48)*k;
         	k*=10;
		 }
     	if(binarynum(1,Total,sss)!=-1)           //使用二分的方法来找到位置,若return结果为-1则表示学号没有录入系统中 
     	{
     		cout<<"目标学生姓名为:"<<student[binarynum(1,Total,sss)].name
		    <<"学号为:"<<student[binarynum(1,Total,sss)].number<<"  宿舍号为"<<student[binarynum(1,Total,sss)].domenumber<<endl<<endl;
		 	cout<<"是否继续进行此操作(是为y,不是为n):";
		    cin>>choice1;
		    		 if(choice1[0]=='y'){cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl<<endl; continue;}
		    else break;
		 }
		  else 
		 {cout<<"你想要查找的学号没有记录入系统中,是否继续进行此查询操作(是为y,不是为n):";
		 cin>>choice1;
		 if(choice1[0]=='y'){cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl<<endl; continue;}
		 else break;
	     }
	 }
	 int flag=0;
	if(choice[0]=='3')                               //以按 宿舍号为关键字进行查找 
	{
	 cout<<"输入你要查询的宿舍号:";
	 cin>>c;
     	 int sss=0,k=1;                               //对输入的信息进行容错处理,防止出现输入字母的情况 
          int len=c.size();
         for(int j=len-1;j>=0;j--)
         {
         		sss+=((int)c[j]-48)*k;
         	k*=10;
		 }
	 for(i=1;i<=Total;i++)
	 {
	 		if(sss==student[i].domenumber&&flag==1)
	 	{
	 		cout<<student[i].name<<"\t"<<student[i].number<<"\t"<<student[i].domenumber<<endl;
		}
	 	if(sss==student[i].domenumber&&flag==0)
	 	{
	 		flag=1;
	 		cout<<"姓名\t学号\t房号"<<endl;
	 		cout<<student[i].name<<"\t"<<student[i].number<<"\t"<<student[i].domenumber<<endl;
		}
		cout<<endl;
		cout<<"是否继续进行此查询操作(是为y,不是为n):";
		cin>>choice1;
		 	 if(choice1[0]=='y'){cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl<<endl; continue;}
		else break;
	 }
	 if(flag==0)
	 {
	 	cout<<"你想要查找宿舍没有记录入系统中或者宿舍没有人进行登记,是否继续进行此查询操作(是为y,不是为n):";
		 cin>>choice1;
		 if(choice1[0]=='y'){cout<<"请输入查找的方式(1:按名字查找,2:按学号查找,3:按房号查找):"<<endl; continue;}
		 else break;
	 }
    }
    }
      return ;
}
void Delete()                  //删除函数 
{
	  string choice;
      int m,i,j;
      string a,choice1;
      string b,c;
      system("cls");
      cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl;  //三个关键字进行删除 
      while(1)
    {
    	while(1)                       //对输入的信息进行容错处理,防止出现输入字母的情况 
	{
		m=0;
         cin>>choice;
	     if(strlen(choice.c_str())>1)
		 {
		  m=1;
	 	cout<<"输入错误,请重新输入";
	     } 
	  if(choice[0]>'3'||choice[0]<'1')
	   {
	  	cout<<"输入数字没有此选项请重新输入"<<endl;
		   m=1; 
	   }
	   if(m==0)
	   break;
	}
	
	 if(choice[0]=='1')                      //以名字为关键字进行查询 并删除 
     {
     	cout<<"输入你想要删除学生的名字:";
     	cin>>a;
     	
     	for(i=1;i<=Total;i++)               
     	 {
     		if(strcmp(student[i].name.c_str(),a.c_str())==0)        //使用strcmp及.c_str进行比较 
     		break;
		 }
		 
		 if(i!=Total+1)
		 {
		    for(j=i;j<Total;j++)
		  {
			student[j]=student[j+1];
		  }
           Total--;
           cout<<"删除成功"<<endl<<endl; 
		 	cout<<"是否继续进行此删除操作(是为y,不是为n):";
		    cin>>choice1;
		    if(choice1[0]=='y'){cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl; continue;}
		    else break;
		 }
		 else 
		 {cout<<"你想要删除的学生没有记录入系统中,是否继续进行此操作(是为y,不是为n):";
		 cin>>choice1;
			if(choice1[0]=='y'){cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl<<endl; continue;}
		 else break;
	     }
	 }
	 
	 if(choice[0]=='2')                          //以按照学号的关键字进行删除 
     {
     	cout<<"输入你想要删除学生的学号:";
     	cin>>b;
     	int sss=0,k=1;                           //对输入的信息进行容错处理,防止出现输入字母的情况 
         int len=b.size();
         for(int j=len-1;j>=0;j--)
         {
         		sss+=((int)b[j]-48)*k;
         	k*=10;
		 }
     	if(binarynum(1,Total,sss)!=-1)           //使用二分的方法来找到位置,若return结果为-1则表示学号没有录入系统中 
     	{
     		int ii= binarynum(1,Total,sss);
		    for(j=ii;j<Total;j++)
		  {
			student[j]=student[j+1];
		  }
           Total--;
           cout<<"删除成功"<<endl<<endl;
		 	cout<<"是否继续进行此删除操作(是为y,不是为n):";
		    cin>>choice1;
		    		 if(choice1[0]=='y'){cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl<<endl; continue;}
		    else break;
		 }
		  else 
		 {cout<<"你想要删除的学号没有记录入系统中,是否继续进行此查询操作(是为y,不是为n):";
		 cin>>choice1;
		 if(choice1[0]=='y'){cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl<<endl; continue;}
		 else break;
	     }
	 }
	 int flag=0;
	if(choice[0]=='3')                               //以按 宿舍号为关键字进行删除
	{
	 cout<<"输入你要删除的宿舍号:";
	 cin>>c;
     	 int sss=0,k=1;                               //对输入的信息进行容错处理,防止出现输入字母的情况 
          int len=c.size();
         for(int j=len-1;j>=0;j--)
         {
         		sss+=((int)c[j]-48)*k;
         	k*=10;
		 }
	 for(i=1;i<=Total;i++)
	 {
	 	if(sss==student[i].domenumber&&flag==0)
	 	{
	 		flag=1;
	 		for(j=i;j<Total;j++)
		  {
		student[j]=student[j+1];
		  }
           Total--;
		}
	} 
		cout<<"删除成功!"<<endl; 
		cout<<endl;
		cout<<"是否继续进行此删除操作(是为y,不是为n):";
		cin>>choice1;
		if(choice1[0]=='y'){cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl<<endl; continue;}
		else break;
		
	 if(flag==0)
	 {
	 	cout<<"你想要查找宿舍没有记录入系统中或者宿舍没有人进行登记,是否继续进行此删除操作(继续为y,不继续进行操作为n):";
		 cin>>choice1;
		 if(choice1[0]=='y'){cout<<"请输入删除的方式(1:按名字删除,2:按学号删除,3:按房号删除):"<<endl; continue;}
		 else break;
	 }
    }
    }
    return ;
} 
int main()
{
    menu();
    int j,k,n,m;
    memset(domes,0,sizeof(domes));
    string choice,i;
    while(1)
  {  
      while(1)
	{
		m=0;
         cin>>choice;
	     if(strlen(choice.c_str())>1)
		 {
		  m=1;
	 	cout<<"输入错误,请重新输入";
	     } 
	  if(choice[0]>'4'||choice[0]<'1')
	   {
	  	cout<<"输入数字没有此选项请重新输入"<<endl;
		   m=1; 
	   }
	   if(m==0)
	   break;
	}
	   
        if(choice[0]=='1')
        {
            build();
            cout<<"新建完毕,是否进行下一步操作(返回菜单为y,退出系统为n):";
            cin>>choice;
            if(choice[0]=='y')
			{
				system("cls");
			menu(); 
		    }
			else break;
        }
        
        else if(choice[0]=='2')
        {
            paixumenu();
           cout<<"排序完毕,是否进行下一步操作(返回菜单为y,退出系统为n):";
            cin>>choice;
            if(choice[0]=='y')
			{
				system("cls");
			menu(); 
		    }
			else break;
        }
        
        else if(choice[0]=='3')
        {
            query();
             cout<<"排序完毕,是否进行下一步操作(返回菜单为y,退出系统为n):";
            cin>>choice;
            if(choice[0]=='y')
			{
				system("cls");
			menu(); 
		    }
			else break;
        }
		 
        else if(choice[0]=='4')
        {
            Delete();
             cout<<"删除完毕,是否进行下一步操作(返回菜单为y,退出系统为n):";
            cin>>choice;
            if(choice[0]=='y')
			{
				system("cls");
			menu(); 
		    }
			else break;
        }
        
        else if(choice[0]=='0')  break;
      }
       cout<<"退出系统"<<endl;
        system("pause");
        
  return 0;
}


以上是关于宿舍信息管理系统的主要内容,如果未能解决你的问题,请参考以下文章

c语言怎么二进制文件操作?

JavaWeb jsp+servlet学生宿舍管理系统001(源码+sql文件可运行《精品毕设》)主要功能:不同角色登录宿舍管理员管理学生信息管理宿舍信息管理学生缺勤管理修改密码和退出功能

宿舍管理系统的设计与实现/学生宿舍管理系统

JavaWeb项目-疫情环境下校园宿舍管理系统-附源码-毕业设计

《学生宿舍管理系统》日志二

SSM学生宿舍管理系统程序.rar(源码+数据库文件)