C语言课程设计监考系统

  • 代码
    (1)test.h
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <graphics.h>		// 引用图形库头文件
struct user//用户
{
	char UsName[30];//用户名(账号)
	char UsSecret[10];//用户密码
};
typedef struct
{
	char rooms[20];//教室名
	int seat;//座位
	int row;//排数
	int col;//列数
}ROOMS;//教室信息
typedef struct
{
	char num[20];//学号
	char name[10];//姓名
}STUDENT;//学生信息
typedef struct The_Stu
{
	char UserName[20];//学生姓名
	int num;//座位号
	char acc[16];//账号
	int secret;//密码
}STU;//学生用户信息


void WelcomeZc();//注册欢迎界面
void WelcomeDl();//登录欢迎界面
void WelcomeKw();//考位管理欢迎界面

void GotoSystemMenu();//1.进入系统菜单
void Operate();//监考系统操作界面
void GeneratePassword();//生成密码
void Set_File(char* examName, STUDENT s2[], STU s1[]);//创建文件,生成账号密码
void SeatAdministrate();//考位安排

int Register();//注册账号密码
int SignIn();//登录
int Verification(struct user* p);//检验账号密码是否一致

void SxRanking(STUDENT s2[]);//顺序排位
void JgRanking(STUDENT s2[]);//间隔排位
void SjRanking(STUDENT s2[]);//随机排位

(2)menu.cpp

#include "test.h"

void WelcomeZc()
{
	printf("**************************\n");
	printf("欢迎进入集美大学监考注册系统\n");
	printf("**************************\n");	
}
void WelcomeDl()
{
	printf("**************************\n");
	printf("欢迎进入集美大学监考登录系统\n");
	printf("**************************\n");

}
void WelcomeKw()
{
	
	printf("**************************\n");
	printf("欢迎进入集美大学监考考位管理系统\n");
	printf("**************************\n");	

}

(3)testmain.cpp

#include "test.h"
char* examName;//考试名字
STU s1[120];
STUDENT s2[120];
ROOMS c3[120];

int main(void)
{		
	GotoSystemMenu();//1.进入系统菜单
	return 0;
}

void GotoSystemMenu()//1.进入系统菜单
{
	int option;//系统选择
	int score;//满意度得分
	int flag1 = 0;//是否注册成功变量
	int flag2 = 0;//是否登录成功
	printf("******************************************\n");
	printf("欢迎进入“集美大学监考系统”\n");
	printf("******************************************\n");
	printf("1.注册您的专属账号\n");
	printf("2.登录系统\n");
	printf("3.考位管理系统\n");
	printf("4.退出系统\n");
	printf("请输入您的选择:");
	scanf("%d", &option);
	system("cls");//清屏
	while(1){
		system("cls");//清屏
		switch (option)
		{
		case 1:WelcomeZc(); Register(); break;//注册
		
		case 2:WelcomeDl(); flag2 = SignIn(); break;//登录
		case 3: 	
			WelcomeKw(); Operate(); break;//考位管理
		
		case 4://退出系统
			printf("希望用户能给个十分满意得好评哈!\n");
			printf("请输入您对本产品得评价分(满分10分):");
			scanf("%d", &score);
			printf("本次使用到此结束,欢迎您下次使用!\n");
			Sleep(1000);
		
			free(examName);
			exit(0);
		default:
			printf("\n您输入的有误,只能输入1,2,3,4,请重新输入哈!\n");
			Sleep(2000);
			
		}
		printf("1.注册您的专属账号\n");
		printf("2.登录系统\n");
		printf("3.考位管理系统\n");
		printf("4.退出系统\n");
		printf("请输入您的选择:");
		scanf("%d", &option);
		system("cls");
	} 
}
void Operate()
{	
	FILE* fd1;//学生文件指针
	FILE* fd2;//教室文件指针
	int i = 0;//学生人数
	int j = 0;//教室数量
	int op;
	examName = (char*)malloc(100);
	fd1 = fopen("c:\\student.txt", "r");
	fd2 = fopen("c:\\rooms.txt", "r");
	printf("请输入考试名:");
	scanf("%s", examName);
	if (fd1 == NULL)
	{
		printf("Open file error\n");
		exit(0);
	}
	if (fd2 == NULL)
	{
		printf("Open file error\n");
		exit(0);
	}
	while (!feof(fd1))//输入学生信息
	{
		fscanf(fd1, "%s%s", &s2[i].num, &s2[i].name);
		//printf("%s%s\n", s2[i].num, s2[i].name);
		i++;
	}
	while (!feof(fd2))//导入教室信息
	{
		fscanf(fd2, "%s%d%d%d", &c3[j].rooms, &c3[j].seat, &c3[j].row, &c3[j].col);
		//printf("%s%d%d%d\n", c3[j].rooms, c3[j].seat, c3[j].row, c3[j].col);
		j++;
	}
	fclose(fd1);
	fclose(fd2);

	printf("\n以下是机房情况:");
	printf("1.陆大206\n");
	printf("2.陆大208\n");
	printf("3.陆大216\n");
	printf("4.陆大218\n");
	printf("5.陆大303\n");
	printf("排序方式:1.顺序,2间隔,3随机,4返回\n");
	printf("请选择座位排序方式:");
	getchar();
	
	do
	{
		scanf("%d", &op);
		system("cls");

		switch (op)
		{
		case 1:SxRanking(s2); break;
		case 2:JgRanking(s2); break;
		case 3:SjRanking(s2); break;
		case 4:GotoSystemMenu(); break;
		default:printf("您的输入有误,请重新输入:1-4\n");
		}
	} while (op < 1 || op>4);
	Set_File(examName, s2, s1);
	//SeatAdministrate();

}
void Set_File(char* examName, STUDENT s2[], STU s1[])//创建文件,生成账号密码
{
		FILE* fp;	
		strcat(examName, "账号密码");
		fp = fopen(examName, "w");
		int i = 0;
		int secret;//随机生成的密码
		fprintf(fp, "学生姓名      座位号      考试账号      密码\n");
		while (i < 60)
		{
			secret = 10000000 + rand() % 90000000;//随机生成密码
			s1[i].num = i + 1;
			s1[i].secret = secret;
			fprintf(fp, "%4s     %4d     jmu%s     %d\n", s2[i].name, s1[i].num, s2[i].num, s1[i].secret);
			i++;
		}
		fclose(fp);
	}

(4)可视化

// ConsoleApplication2.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "test.h"
void SxRanking(STUDENT s2[])//顺序(60人)
{
	int i, j;
	int num = 0;//座位号
	int a = 0;//人名顺序
	TCHAR ch[120];
	initgraph(515, 620);	// 创建绘图窗口60人座位
	setbkcolor(LIGHTGRAY);
	// 用背景色清空屏幕
	cleardevice(); 
	setlinecolor(RGB(84, 255, 159)); //设置划线(画笔)的颜色
	setlinestyle(PS_SOLID, 3); //设置线条为实线,  设置线宽为3像素
	settextstyle(25, 10, _T("微软雅黑"));  //设置字体样式
	settextcolor(RGB(83, 134, 139));   //设置字体颜色  
	rectangle(217, 10, 297, 60); //左x,上y, 右x,下y 绘制讲台
	outtextxy(247, 25, _T("讲台")); //特殊位置,单独写
	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 6; j++)
		{
			roundrect(5 + j * 85, 70 + i * 55, 85 + j * 85, 120 + i * 55, 2, 1);//依次画圆角矩阵
			num++;
			_stprintf(ch, _T("%d"), num);//将数字转换成字符
			outtextxy(40 + j * 85, 75 + i * 55, ch);//座位号
			outtextxy(15 + j * 85, 95 + i * 55, s2[a++].name);//姓名
		}
	}
	system("pause");
	closegraph();// 关闭图形界面

}
void JgRanking(STUDENT s2[])//间隔(120人)
{
	int i, j;
	int num = 0;
	int x = 0;
	TCHAR ch[120];
	initgraph(1575, 335);	//创建绘图窗口120人座位
	setbkcolor(LIGHTGRAY); //设置背景色
	cleardevice(); //用背景色清空整个屏幕
	setlinecolor(RGB(84, 255, 159)); //设置划线(画笔)的颜色
	setlinestyle(PS_SOLID, 3); //设置线条为实线,  设置线宽为3像素
	settextstyle(25, 10, _T("微软雅黑"));  //设置字体样式
	settextcolor(RGB(83, 134, 139));   //设置字体颜色  
	rectangle(780, 10, 880, 40); //左x,上y, 右x,下y 绘制讲台
	outtextxy(810, 15, _T("讲台")); //特殊位置,单独写
	for (i = 0; i < 8; i++)
	{
		for (j = 0; j < 15; j++)
		{
			if (j % 2 == 0)//第一个位置不安排
			{
				num++;
				_stprintf(ch, _T("%d"), num);//座位号不变,仍然从1-60
				outtextxy(10 + j * 105, 55 + i * 35, ch);//座位号
				outtextxy(40 + j * 105, 55 + i * 35, s2[x++].name);//姓名
			}
			roundrect(5 + j * 105, 50 + i * 35, 105 + j * 105, 80 + i * 35, 2, 1);//依次输出圆角矩形
		}
	}
	system("pause");
	closegraph();// 关闭图形界面

}
void SjRanking(STUDENT s2[])//随机排60人
{
	int i, j;
	int num = 0;//座位号
	int value;
	int a[60] = {0};//人名顺序
	TCHAR ch[120];
	initgraph(515, 620);	// 创建绘图窗口60人座位
	setbkcolor(LIGHTGRAY);
	// 用背景色清空屏幕
	cleardevice();
	setlinecolor(RGB(84, 255, 159)); //设置划线(画笔)的颜色
	setlinestyle(PS_SOLID, 3); //设置线条为实线,  设置线宽为3像素
	settextstyle(25, 10, _T("微软雅黑"));  //设置字体样式
	settextcolor(RGB(83, 134, 139));   //设置字体颜色  
	rectangle(217, 10, 297, 60); //左x,上y, 右x,下y 绘制讲台
	outtextxy(247, 25, _T("讲台")); //特殊位置,单独写
	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 6; j++)
		{
			roundrect(5 + j * 85, 70 + i * 55, 85 + j * 85, 120 + i * 55, 2, 1);//依次画圆角矩阵
			value = rand() % 60;
			while (a[value] != 0)//重复出现,再生成一次
			{
				value = rand() % 60;
			}
			a[value] += 1;//控制下标(人)出现次数
			num++;
			_stprintf(ch, _T("%d"), num);
			outtextxy(40 + j * 85, 75 + i * 55, ch);//座位号
			outtextxy(15 + j * 85, 95 + i * 55, s2[value].name);//姓名

		}
	}
	system("pause");
	closegraph();// 关闭图形界面
}
/*void SeatAdministrate()调试图形用
{
        int i, j,k;
        int num = 0;//座位号
        int value = 0;//教室个数
        TCHAR ch[100];
        FILE* fp;
        

        for (i = 0; i < 8; i++)//行
        {
            for (j = 0; j < 15; j++)//列
            {
                fillroundrect(5+j*85, 50+i*35, 85+j*85, 80+i*35, 2, 1);
            }
        
        initgraph(515, 620);//创建绘图窗口60人座位
        // 设置背景色为黑色
        setbkcolor(LIGHTGRAY);
        // 用背景色清空屏幕
        cleardevice();
        // 设置绘图色为红色
        setcolor(RED);
        roundrect(217, 10, 297, 60, 2, 1);
        for (i = 0; i < 10; i++)
        {
            for (j = 0; j < 6; j++)
            {

                settextcolor(GREEN);
                num++;
                _stprintf(ch, _T("%d"), num);
                outtextxy(40 + j * 85, 75 + i * 55, ch);
                roundrect(5 + j * 85, 70 + i * 55, 85 + j * 85, 120 + i * 55, 2, 1);
            }
        }

        system("pause");
        closegraph();//关闭绘图窗口

}*/

(5)system.cpp

#include "test.h"

int Register()//注册
{
	struct user p;
	getchar();
	printf("请输入您的账号:");
	scanf("%s", p.UsName);
	printf("请输入您的密码:");
	scanf("%s",p.UsSecret);
	FILE* fp;
	fp = fopen("user.txt", "a");
	if (fp == NULL) 
	{
		printf("Open file error\n");
		exit(0);
	}
	fprintf(fp, "%s %s\n", p.UsName, p.UsSecret);//将账号密码写入文件
	if (fclose(fp))
	{
		printf("Can't close file succeesfully!|n");
		exit(0);
	}
	printf("您已成功注册账号,可以进行登录操作,进入监考系统啦!\n");
	return 1;
}
int SignIn()//登录
{
	struct user p;
	printf("请输入您的账号:");
	scanf("%s", p.UsName);
	printf("请输入您的密码:");
	scanf("%s", p.UsSecret);
	if (Verification(&p) == 1)
	{
		system("cls");
		printf("输入正确,登录成功啦!可以进入考位管理系统,进行排位!\n");
		return 1;
	}
	else
	{
		system("cls");
		printf("很抱歉您的输入有误,进不了监考系统啦!\n");
		return 0;
	}
}
int Verification(struct user* p)//检验账号密码是否一致
{
	
	FILE* fp;
	char userp[40];//注册时的账号密码
	char user[30];//储存输入的账号
	char secret[10];//储存输入的密码
	int flag = 0;//检查账号密码是否一致的标志
	strcpy(user, p->UsName);//复制
	strcpy(secret, p->UsSecret);
	strcat(user, " ");//用空格将账号密码分隔开
	strcat(user, secret);//将账号和密码连起来,便于观看
	strcat(user, "\n");
	fp = fopen("user.txt", "r");
	if (fp == NULL)
	{
		printf("Open file error\n");
		exit(0);
	}
	while (!feof(fp))
	{
		fgets(userp, 40, fp);
		if (strcmp(userp, user) == 0)//输入正确,可以登录
		{
			flag = 1;
			break;
		}
	}
		if (fclose(fp))
		{
			printf("Sorry, close file error!\n");
			exit(0);
		}
	
	return flag;
}


原文地址:https://www.cnblogs.com/zxcvbnmlk/p/15015749.html