• 高校教室管理系统


                   设计目的在于,利用学习的数据结构和c语言知识,研究大学空闲教室管理系统的开发途径和应用方法。与其他学习阶段相比,大学课程相对较少,合理利用空闲教室显得尤为重要。为了让广大在校师生,在空闲时间有个教室去自习,去做自己想做的事情,因此开发一套空闲教室管理系统是势在必行的。通过高校教室管理系统,广大师生可以随时随地查看空闲教室,作为老师可以添加后台数据即默认空教室。同时,高校空闲教室管理系统设计是具有具体化,合理化性,也是为了提高空闲教室的可利用性。

                   创建教室结构体,包括教室编号、教室位置、教室容量,再通过创建单链表向链表中添加教室信息。通过单链表的删除操作实现删除某一教室信息,通过输入某一教室编号实现对某一教室信息的修改,通过输入教室位置、容量、时间段,可以分别找到满足用户需求的空闲教室。

    #include<stdio.h>  //输入输出 
    #include<string.h> //字符串处理 
    #include<stdlib.h> // 程序工具 
    #include<iostream> //输入输出流 
    typedef struct Node {			//定义表结点
    	char classRoomNum[10];	    //教室编号 
    	char freeTime1[10];			//空闲时间段 1
    	char freeTime2[10];			//空闲时间段 2 
    	char freeTime3[10];			//空闲时间段 3 
    	char freeTime4[10];			//空闲时间段 4 把一天分为四个时间段 
    	char set[10];				//教室地点 
        int volume;				    //容量 
    	struct Node *next;
    } SLNode;
    
    typedef struct {				//定义教室信息 
    	char classRoomNum[10];	    //教室编号 
    	char freeTime1[10];			//空闲时间段 1
    	char freeTime2[10];			//空闲时间段 2 
    	char freeTime3[10];			//空闲时间段 3 
    	char freeTime4[10];			//空闲时间段 4
    	char set[10];				//教室地点 
        int volume;				    //容量 
        SLNode *head;
    } classRoom;
    
    void ListInitiate(SLNode **head) {	    //链表初始化
    	if ((*head = (SLNode *)malloc(sizeof(SLNode))) == NULL)
    		exit(1);						//初始化失败,则返回错误信息
    	(*head)->next = NULL;				//初始化成功则构造一个空表,头节点指针域置空 
    }
    void allQuery(SLNode *head);            //函数声明 
    void linkView(SLNode *head);
    void Exit();
    void classRoomInfor();
    void mainMenu();  
    void classRoomAdd(SLNode *head, classRoom x);  
    void classRoomQuery(SLNode *head);   
    SLNode *classRoomInsert(SLNode *head, classRoom x);
    void printclassRoom(SLNode *p); 
    void queryMenu(); 
    void classRoomQuery(SLNode *head);
    void timeSlotQuery(SLNode *head);
    void siteQuery(SLNode *head); 
    void volumeQuery(SLNode *head);
    void classRoomRevise(SLNode *head);
    void classRoomDel(SLNode *head);
    int main() {                   //**主函数 ** 
    	int i;
    	int flog = 0;//等于一退出系统 
    	classRoom x = { 0 };
    	SLNode *head;       //头节点 
    	ListInitiate(&head);//链表初始化 
    
    	while (1) {
    		system("color f0");//背景色 
    		printf( "
    		 当前日期: ");
    		(100);
    		system("DATE	[/T]");
    		(100);
    		printf( "
    		 当前时间: ");
    		(100);
    		system("TIME	[/T]");
    		printf ("
    
    
    			 欢  ");
    		printf("迎   ");
    		printf("进  ");
    		printf("入 
    
    
    			");
    		system("pause");//暂停,等待用户信号 
    		system("cls");  //清除屏幕
    		while(1) {
            	mainMenu(); 
    			printf("
    请输入0-5选择子菜单:");
    			scanf("%d", &i);
    			switch (i) {
    				case 0:
    					Exit();
    					printf("
    您已退出系统,谢谢使用!
    ");
    					flog = 1;
    					break;
    				case 1:
    					classRoomAdd(head,x);//添加教室信息 
    					break;
    				case 2:
    				    allQuery(head);//遍历输出 
    					break;
    				case 3:classRoomRevise(head);//修改教室信息 
    				    break;
    			    case 4:
    				     classRoomDel(head);//删除教室信息 
    					break;
    				case 5:
    					classRoomQuery(head);//教室查找,,分三种方式
    					break; 
    				default:
    					printf("
    您的输入有误,请输入0-5之间的数字!
    ");
    					break;
    			}
    			if (flog == 1)
    				break;          //退出系统 
    		}
    return 0;
    	}
    	system("pause");
    	system("cls");              //清除屏幕
    }
    
    void mainMenu() {
    		printf("
    --------------------------------------------------------------------------------");
    			printf("
    ");
    			printf("
    			   空闲教室管理系统
    ");
    			printf("
    				主菜单
    ");
    			printf("
    		1.录入教室信息		2.显示全部教室信息
    ");
    			printf("
    		3.修改教室信息		4.删除教室信息
    ");
    			printf("
    		5.查找空闲教室
    ");
    			printf("
    		0.退出系统
    ");
    			printf("
    
    --------------------------------------------------------------------------------");
    }
    
    
    SLNode *classroomInsert(SLNode *head, classRoom x) {//按教室号升序录入教室信息函数
    	SLNode *p, *q, *s;
    	p = head->next;//
    	q = (SLNode *)malloc(sizeof(SLNode));//分配空间 
    	if (q == NULL) exit(1);				//存储空间分配失败
    	q->volume = x.volume;
    	strcpy(q->classRoomNum, x.classRoomNum);//字符串复制 
    	strcpy(q->freeTime1, x.freeTime1);
    	strcpy(q->freeTime2, x.freeTime2); 
    	strcpy(q->freeTime3, x.freeTime3);
    	strcpy(q->freeTime4, x.freeTime4);
    	strcpy(q->set, x.set);
    	if (head->next == NULL) {//为空 
    		head->next = q;		
    		head->next->next = NULL;
    	} else  {			    //非空 
    		for (; p; p->next) {//p指针从第一个数据往后移动,直到p为空 
    			if (p->next != NULL) {	//录入的教室编号在已录入的两个工号之间
    				if (strlen(p->classRoomNum) < strlen(x.classRoomNum) && strlen(p->next->classRoomNum) >strlen(x.classRoomNum)) {
    					s = p->next;
    					p->next = q;
    					q->next = s;
    					break;
    				} else if (strcmp(p->classRoomNum ,x.classRoomNum)==0) {
    					printf("教室号为%s的教室已存在!
    ", p->classRoomNum);
    					break;
    				}
    			} else if (strlen(p->classRoomNum) <strlen(x.classRoomNum) && p->next == NULL) {//如果在排序中为最后一个
    				p->next = q;
    				q->next = NULL;		//尾插法 
    				break;
    			}
    			if (strlen(p->classRoomNum) >= strlen(x.classRoomNum)) {	//头插法 
    				s = head->next;
    				head->next = q;
    				q->next = s;
    				break;
    			}
    		}
    
    	}
    	printf("该录入完毕!");
    	return head;
    }
    
    void classRoomInfor() {						//教室包含的 属性 
    	printf("
    教室编号			空闲时间段			教室地点			教室容量
    ");
    }
    
    void classRoomRevise(SLNode *head) {     //修改操作
    	classRoom x;
    	char n[10];
    	SLNode *p;
    	p = head->next;
    	system("cls");
    	printf("
    请输入要修改信息的教室号:");
    	scanf("%s", &n);
    	for (; p; p = p->next) {
    		if (strcmp(p->classRoomNum, n)==0) {
    			printf("
    请输入该教室的新信息!");
    			printf("请输入教是号:");
    			scanf("%s", x.classRoomNum);
    			printf("请输入空闲时间段:");
    			scanf("%s", x.freeTime1);
    			printf("请输入空闲时间段:");
    			scanf("%s", x.freeTime2);
    			printf("请输入空闲时间段:");
    			scanf("%s", x.freeTime3);
    			printf("请输入空闲时间段:");
    			scanf("%s", x.freeTime4);
    			printf("请输入教室地点:");
    			scanf("%s", x.set);
    			printf("请输入教室容量:");
    			scanf("%d", &x.volume);
    			p->volume = x.volume;
    			strcpy(p->classRoomNum, x.classRoomNum);
    			strcpy(p->freeTime1, x.freeTime1);
    			strcpy(p->freeTime2, x.freeTime2);
    			strcpy(p->freeTime3, x.freeTime3);
    			strcpy(p->freeTime4, x.freeTime4);
    			strcpy(p->set, x.set);
    			printf("
    教室信息修改成功!");
    			break;
    		}
    	}
    	if (p == NULL)
    		printf("
    该教室不存在!
    ");
    }
    
    void classRoomDel(SLNode *head) {     //删除操作
    	SLNode *p, *s;
    	char x[10];
    	s = head;//初始化s 
    	p = head->next;
    	if (head->next == NULL) {
    		printf("
    系统中无教室信息!
    ");
    	} else {
    		system("cls");
    		printf("
    请输入要删除的教室的编号:");
    		scanf("%s", &x);
    		for (; p; p = p->next) {
    			if (strcmp(p->classRoomNum, x)==0) {
    				s->next = p->next;
    				free(p);
    				printf("
    删除成功!请继续!
    ");
    				break;
    			}
    			s = p;
    		}
    		if (p == NULL)
    			printf("
    系统中无此教室信息!
    ");
    	}
    }
    
    void classRoomAdd(SLNode *head, classRoom x) {   //录入操作
    	int nu;
        system("cls");
      
    	printf("
    请输入您要录入的教室数:");
    	scanf("%d", &nu);
    	for (int n = 0; n < nu; n++) {   
    	    printf("
    
    ");
    		printf("请输入教室编号:");
    		scanf("%s", x.classRoomNum );
    	    printf("请输入教室地点:");
    		scanf("%s", x.set);
    		printf("请输入教室容量:");
    		scanf("%d", &x.volume);
    		printf("请输入空闲时间段一:");
    		scanf("%s", x.freeTime1);
    		printf("请输入空闲时间段二:");
    		scanf("%s", x.freeTime2);
    		printf("请输入空闲时间段三:");
    		scanf("%s", x.freeTime3);
    		printf("请输入空闲时间段四:");
    		scanf("%s", x.freeTime4);
    		head = classroomInsert(head, x);
    	}
    
    	printf("
    录入完毕!
    ");
    }
    
    
    
    void allQuery(SLNode *head) {					//查询所有教室信息
    	linkView(head);
    }
    
    
    void printclassRoom(SLNode *p) {
    	    printf("****************************
    ");
    		printf("教 室 编 号 :%s	
    ", p->classRoomNum);
            printf("教 室 地 点 :%s	
    ", p->set);
    		printf("教 室 容 量 :%d	
    ", p->volume);
    	    printf("空闲时间段一:%s	
    ", p->freeTime1);
    		printf("空闲时间段二:%s	
    ", p->freeTime2);
    		printf("空闲时间段三:%s	
    ", p->freeTime3);
    		printf("空闲时间段四:%s	
    ", p->freeTime4);
    		
    }
    
    
    void  linkView(SLNode *head) {              //显示所有教室信息
    	SLNode *p = head;
        while (p->next) {
    		p = p->next;
    		printclassRoom(p);
    
    	}
    }
    
    
    void Exit() { //退出程序
    	int k;
    	char s = 'Y';
    	if (k) { //判断数据是否修改,如已经修改按指定路径保存至txt文档(D盘) 
    		printf("
    确定退出?(y/n):
    ");
    		scanf("%d",&s);
    		if (s == 'y' || s == 'Y') {
             
    			printf("
    已安全退出!
    ");
    		}
    		exit(0);
    	}
    }
    
    
    void queryMenu() {//查询教室菜单 
    	printf("
    
    --------------------------------------------------------------------------------");
    	printf("
    
    
    ");
    	printf("
    				查询菜单
    ");
    	printf("
    		1.以指定时间查询		2.以指定地点查询
    ");
    	printf("
    		3.以指定教室容量查询		
    ");
    	printf("
    		0.回到主菜单");
    	printf("
    
    --------------------------------------------------------------------------------");
    }
    
    void classRoomQuery(SLNode *head) {	//定义教室查询函数,三种查询方式 
    	system("cls");
    	if (head->next == NULL)//如果链表为空 
    		printf("
    系统中无教室信息!
    ");
    	else {
    		int j;
    
    		while (1) {
    			int flog = 0;
    			queryMenu();
    			printf("
    请输入0-3选择查询方式:");
    			scanf("%d", &j);
    			switch (j) {
    				case 0:
    					printf("
    您已退出查询菜单!
    ");
    					flog = 1;
    					break;
    				case 1:
    					timeSlotQuery(head);//时间段 
    					break;
    				case 2:
    				    siteQuery(head);//地点 
    					break;
    				case 3:
    			        volumeQuery(head);//容量 
    					break;
    				default:
    					printf("
    您的输入有误,请输入1-3之间的数字!
    ");
    					break;
    			}
    			if (flog)
    				break;
    		}
    	}
    }
    void timeSlotQuery(SLNode *head) {	 
        FILE *fp; 				//按时间段查询
        fp = fopen("D:\timeData.txt", "w");
        SLNode *p;
    	char x[30];
    	int m = 0;
    	p = head->next;
    	system("cls");
    	printf("
    请输入要查询的时间段:");
    	scanf("%s", x);
    	for (; p; p = p->next) {
    		if ((strcmp(p->freeTime1, x)==0)||//strcmp函数,相等返回0 ,只要有一个时间段满足则查询成功 
    		    (strcmp(p->freeTime2, x)==0)||
    		    (strcmp(p->freeTime3, x)==0)||
    		    (strcmp(p->freeTime4, x)==0)) {
    		    printclassRoom(p);
    		    fprintf(fp,"%s	%s	%s	%s	%s	%s	%d	
    ", p->classRoomNum,p->freeTime1,p->freeTime2,p->freeTime3,p->freeTime4, p->set, p->volume);//写入文本 
    			m = 1;
    
    		}
    	}
    	if (m == 0)
    		printf("对不起,此时间段无空闲教室!");
    		fclose(fp);
    }
    void siteQuery(SLNode *head) {					//按地点查询
    	SLNode *p;
    	FILE *fp; 
    	fp = fopen("D:\siteData.txt", "w");
    	char x[30];
    	int m = 0;
    	p = head->next;
    	system("cls");
    	printf("
    请输入要查询的地点:");
    	scanf("%s", x);
    	for (; p; p = p->next) {
    		if (strcmp(p->set, x)==0) {
    			printclassRoom(p);
    		    fprintf(fp,"%s	%s	%s	%s	%s	%s	%d	
    ", p->classRoomNum,p->freeTime1,p->freeTime2,p->freeTime3,p->freeTime4, p->set, p->volume);//写入文本 
    			m = 1;
    	
    		}
    	}
    	if (m == 0)
    		printf("对不起,此地点无空闲教室!");
    		fclose(fp);
    }
    
    void volumeQuery(SLNode *head) {					//按容量查询
    	SLNode *p;
    	FILE *fp; 
    	fp = fopen("D:\volumeData.txt", "w");
    	int n;
    	int m=0;
    	p = head->next;
    	system("cls");
    	printf("
    请输入要查询的空闲教室容量:
    ");
    	scanf("%d", &n );
    	for (; p ; p= p->next) {
    		if (p->volume == n) {
    			printclassRoom(p);
    			fprintf(fp,"%s	%s	%s	%s	%s	%s	%d	
    ", p->classRoomNum,p->freeTime1,p->freeTime2,p->freeTime3,p->freeTime4, p->set, p->volume);//写入文本 
    		
    		m = 1;
    	
    		}
    	}
    	if (m == 0)
    		printf("对不起,无空闲教室!", n);
    		fclose(fp);
    }
    

      

    每个人都会有一段异常艰难的时光 。 生活的压力 , 工作的失意 , 学业的压力。 爱的惶惶不可终日。 挺过来的 ,人生就会豁然开朗。 挺不过来的 ,时间也会教你 ,怎么与它们握手言和 ,所以不必害怕的。 ——杨绛
  • 相关阅读:
    oracle 绿色版本 instantclient 使用说明
    response 后刷新页面,点击按钮后,禁用该按钮
    模式对话框里的CheckedChanged事件
    PDF合并
    Android手机上抓包神器
    春社日的推算方法
    Web APi入门之Self-Host(二)
    Web Api之Cors跨域以及其他跨域方式(三)
    Web APi入门之基本操作(一)
    Self Host WebApi服务传输层SSL加密(服务器端+客户端调用)
  • 原文地址:https://www.cnblogs.com/zhai1997/p/11197327.html
Copyright © 2020-2023  润新知