实现简单的学生宿舍基本信息管理,宿舍的基本信息包括楼号、房间号、面积、所容纳人数、已入住人数等,系统以文本菜单形式工作。
登录时:用户名为asd 密码任意
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <malloc.h>
#include <windows.h>
#define N sizeof(struct Student)
typedef struct Student
{
int buildnum; //宿舍楼栋号
int roomnum; //房间号
int brnum; //宿舍楼栋号+房间号
float area; //宿舍房间面积
int rnanum; //所容纳人数
char xy[100]; //学院
int bj; // 班级
int num; //学号
char name[20]; //姓名
char sex[10]; //性别
int date; //日期
struct Student *next;
}Stu,*stu;
int a[1000000];//记录寝室入住人数
void save_stu(stu p);
void login()
{
system("cls");
system("color 4E");
printf("\n\n\n\n\n\n\n############################~欢迎进入学生宿舍管理系统~##########################\n");
printf("\n\n\n\t\t\t\t ★ ★ ★ ★ ★");
printf("\n\n\n\n\t\t\t\t\t\tLoading");
for(int i=0;i<6;i++)
{
Sleep(400);
printf(".");
}
system("cls");
char username[10];
char password;
int p=0;
system("color 6E");
printf("\n\n\n ==============================欢迎使用=================================\n");
for(int i = 0; i < 3; i++)
{
printf("\n\n\n\t\t请输入用户名:[ ]\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%s",username);
if (strcmp(username,"asd") == 0)
{
printf("\t\t请输入密码: [ ]\b\b\b\b\b\b\b\b\b\b\b\b");
while((password=getch()) != '\r')//判断是否是回车
{
p++;
if(password == 8)//实现backspace键的功能,其中backspace键的ascii码是8
{
putchar('\b');
putchar(' ');
putchar('\b');
if(p>0) //最多只能删到没有字符
p--;
}
if(!isdigit(password)&&!isalpha(password))//判断是否是数字或字符
continue;
putchar('*'); //在屏幕上打印星号
}
printf("\n\n\n ===============================登陆成功=================================");
Sleep(600);
return;
system("pause");
}
else
{
if(i<2)
printf("用户名错误,请重新输入");
else
{
printf("\n 您已连续3次将用户名或密码输错,系统将退出!");
exit(0); //关闭所有文件,终止正在执行的进程
}
}
}
}
int menu_select() //主菜单选项
{
int a;
do
{
system("cls");
system("color 3E");
printf("\n\n\t======================学生宿舍管理系统※※※※※※※※※※※※\n\n");
printf("\t◆◆ 1. 添加学生信息 ◆◆\n\n");
printf("\t◆◆ 2. 显示学生信息 ◆◆\n\n");
printf("\t◆◆ 3. 对学生信息进行排序 ◆◆\n\n");
printf("\t◆◆ 4. 查找学生信息 ◆◆\n\n");
printf("\t◆◆ 5. 修改学生信息 ◆◆\n\n");
printf("\t◆◆ 6. 删除学生信息 ◆◆\n\n");
printf("\t◆◆ 0. 退出系统 ◆◆\n\n");
printf("\t※※※※※※※※※※※※※※※================================\n");
printf("\t请选择您要运行的选项按(0-6):");
scanf("%d",&a);
}while(a<0 || a>6);
return a;
}
stu ss() //将文件中的内容读出到链表中,返回值为表头地址
{
FILE *fp; //文件指针
int n = 0;
stu head = NULL;
stu p1,p,pr = NULL;
fp=fopen("student","ab+"); //以只读的方式打开文件
if(fp == NULL)
{
printf("文件打开失败 !\n");
}
else
{
while(!feof(fp)) //判断文件位置标志是否移动到文件末尾
{
n++;
p = (stu)malloc(N); //向内存申请一段空间
fread(p,N,1,fp); //将fp所指向的文件中的内容赋给p
if(n == 1)
{
head = p;
p1 = p;
}
else //创建链表
{
pr = p1;
p1->next = p;
p1 = p;
}
}
}
if(pr != NULL)
pr->next = NULL;
else
head = NULL;
fclose(fp); //关闭文件
return head; //返回头指针
}
Student *input(int n)
{
int i;
stu head,p,q;
if(n <= 0) return NULL;
p = (stu)malloc(sizeof(Stu));
printf("--------------------------------------------------------------------------------\n");
printf("楼栋号 房间