本文首发于2023年6月11日18:00
欢迎各位提出问题,又问必答,有需者可分享项目文件,下方有源码分享。
目录
开发初衷
学生虽然可以查看自己的学生成绩和绩点,但是不能清楚的查看自己的学分,所以我就想开发一个,学生基本信息和学生学分信息动态化绑定,管理员与学生操作相结合的学生信息管理系统
部分运行效果
视频演示
系统演示
程序框图 (不完全)
代码实现
主框架
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<graphics.h>
#define RecordNums 42//结构体数组数量——可以记录学生数据最大容量
#define Transverse 173//信息表格横向
#define longitudinal 38//信息表格纵向
#define Transverse_s 145//学分表格横向
#define longitudinal_s 39//学分表格纵向
int nowstudentnums=0;//学生信息数据个数
char code[20] = "666666";//管理员密码
int interdict=0;//阻断循环变量
typedef struct Student//学生信息结构体定义
{
char s_studentID[15];//学号
char s_Name[15];//姓名
char s_gender[15];//性别
char s_faculty[15];//院系
char s_speciality[15];//专业
char s_grade[15];//年级
char s_number[15];//手机号
}Student;
//创建学生信息结构体数组
Student information[RecordNums];
typedef struct Score//学生学分结构体定义
{
char studentID[15];//学号
char Name[15];//姓名
char compulsory[6];//必修
char select[6];//选修
char morality[6];//德育
char innovate[6];//创新
char other[6];//其它
char sum[6];//总和
}Score;
//创建学生学分结构体数组
Score credit[RecordNums];
typedef struct app//学生信息缓冲结构体
{
char s_studentID[15];//学号
char s_Name[15];//姓名
char s_gender[15];//性别
char s_faculty[15];//院系
char s_speciality[15];//专业
char s_grade[15];//年级
char s_number[15];//手机号
}app;
app information_buffer;
typedef struct add//学生学分缓冲结构体
{
char studentID[15];//学号
char Name[15];//姓名
char compulsory[6];//必修
char select[6];//选修
char morality[6];//德育
char innovate[6];//创新
char other[6];//其它
char sum[6];//总和
}add;
add credit_buffer;
void main();//主窗口
void password();//管理员认证
void managewindows();//管理员
void summary();//对学生数据进行操作
void information_homepage();//首页学生信息表
void information_secondarypage();//次页学生信息表
void credit_homepage();//首页学分表
void credit_secondarypage();//次页学分表
void information_secondarypage_final();//尾页学生信息表
void credit_secondarypage_final();//尾页学生学分表
void increase();//录入学生信息
void erasure();//删除学生信息
void view();//查找学生信息
void correct();//修改学生信息
void studentwindows();//学生窗口
void student_registration();//学生注册
void student_login();// 学生登录
void main()//主窗口的建立
{
int support = 1;//点赞循环变量
char support_s[100];//点赞数组
initgraph(1280, 720);
IMAGE host_a;
loadimage(&host_a, "./界面图片/首页.png", 1280,720);
HWND hnd = GetHWnd();
SetWindowText(hnd, "郑轻天机团队最新项目——学生信息管理系统");
putimage(0, 0, &host_a);
settextcolor(WHITE);//设置字体颜色为白色
setbkmode(TRANSPARENT);//消除字体背景颜色
settextstyle(40,0,_T("Consolas"));//设置字体大小
while (1)//时刻获取鼠标信息
{
if (MouseHit())//如果有消息
{
MOUSEMSG host_b = GetMouseMsg();//设置变量引入消息
switch (host_b.uMsg)//判断是什么信息
{
case WM_LBUTTONDOWN://左键
if (host_b.x > 667.02 && host_b.x < 854.47 && host_b.y>401.39 && host_b.y < 454.68)
{
password();//进入管理员界面
break;
}
else if (host_b.x > 683.65 && host_b.x< 837.08 && host_b.y> 495.50 && host_b.y < 549.17)
{
studentwindows();//进入学生界面
break;
}
else if (host_b.x > 18.14 && host_b.x < 53.66 && host_b.y>2.19 && host_b.y < 62.36)
{
clearrectangle(66, 27, 142, 55);
sprintf(support_s, "%d", support);
outtextxy(70,20, support_s);
support++;//获取点赞信息
}
}
}
}
}
void password()//管理员认证
{
char password_a[15];
TCHAR password_s[] = _T("输入管理员密码");
InputBox(password_a, 15, password_s);
if (strcmp(code, password_a) == 0)
{
managewindows();
}
else
{
HWND hnd = GetHWnd();
int isok=MessageBox(hnd, "输入密码错误,请重新输入", "错误提示", MB_OKCANCEL);
if (isok == IDOK)
{
password();
}
else if (IDCANCEL == isok)
{
main();
}
}
}
管理员模块
显示所有学生数据
void managewindows()//管理员
{
IMAGE manage_a;
loadimage(&manage_a, "./界面图片/管理员操作界面.png", 1280,720);
putimage(0, 0, &manage_a);
FILE* informationfile_s;//定义存取学生信息文件指针
FILE* creditfile_s;//定义存取学分信息文件指针
//打开文档进行分析操作
informationfile_s = fopen("./学生信息.txt", "r");
creditfile_s = fopen("./学生学分.txt", "r");
//提取学生学分数据
for (nowstudentnums = 0; nowstudentnums < 42; nowstudentnums++)
{
//判断数据是否读完
if (feof(informationfile_s) == 1)
{
break;
}
//将文件数据保存在结构数组中
fscanf(informationfile_s, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
&information[nowstudentnums].s_studentID,
&information[nowstudentnums].s_Name,
&information[nowstudentnums].s_gender,
&information[nowstudentnums].s_faculty,
&information[nowstudentnums].s_speciality,
&information[nowstudentnums].s_grade,
&information[nowstudentnums].s_number);
fscanf(creditfile_s, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
&credit[nowstudentnums].studentID,
&credit[nowstudentnums].Name,
&credit[nowstudentnums].compulsory,
&credit[nowstudentnums].select,
&credit[nowstudentnums].morality,
&credit[nowstudentnums].innovate,
&credit[nowstudentnums].other,
&credit[nowstudentnums].sum);
}
fclose(informationfile_s);//关闭文件
fclose(creditfile_s);//关闭文件
while (1)//时刻获取鼠标信息
{
if (MouseHit())//如果有消息
{
MOUSEMSG manage_b = GetMouseMsg();//设置变量引入消息
switch (manage_b.uMsg)//判断是什么信息
{
case WM_LBUTTONDOWN://左键
if (manage_b.x > 703.68 && manage_b.x < 1038.89 && manage_b.y>351.12 && manage_b.y < 410.83)
{
credit_homepage();//首页学分表
break;
}
else if (manage_b.x >681.00 && manage_b.x <1054.38&& manage_b.y>507.21 && manage_b.y < 567.31)
{
summary();//对学生数据进行操作
break;
}
else if (manage_b.x > 21.92 && manage_b.x < 122.82 && manage_b.y>19.28 && manage_b.y < 80.88)
{
main();//主窗口
break;
}
}
}
}
}
void credit_homepage()//首页学分表
{
IMAGE creditpicture_s;//定义界面图片指针
loadimage(&creditpicture_s, "./界面图片/首页学生学分表.png", 1280, 720);
putimage(0, 0, &creditpicture_s);
settextstyle(25, 0, _T("Consolas"));//设置字体大小
settextcolor(WHITE);//设置字体颜色为白色
setbkmode(TRANSPARENT);//消除字体背景颜色
//冒泡排序法——总分排序
int i = 0, j;
for (i; i < nowstudentnums; i++)
{
for (j = 0; j < nowstudentnums - i - 1; j++)
{
if (atof(credit[j].sum) > atof(credit[j + 1].sum))
{
strcpy(credit_buffer.sum, credit[j].sum);
strcpy(credit[j].sum, credit[j + 1].sum);
strcpy(credit[j + 1].sum, credit_buffer.sum);
strcpy(credit_buffer.studentID, credit[j].studentID);
strcpy(credit[j].studentID, credit[j + 1].studentID);
strcpy(credit[j + 1].studentID, credit_buffer.studentID);
strcpy(credit_buffer.Name, credit[j].Name);
strcpy(credit[j].Name, credit[j + 1].Name);
strcpy(credit[j + 1].Name, credit_buffer.Name);
strcpy(credit_buffer.compulsory, credit[j].compulsory);
strcpy(credit[j].compulsory, credit[j + 1].compulsory);
strcpy(credit[j + 1].compulsory, credit_buffer.compulsory);
strcpy(credit_buffer.select, credit[j].select);
strcpy(credit[j].select, credit[j + 1].select);
strcpy(credit[j + 1].select, credit_buffer.select);
strcpy(credit_buffer.morality, credit[j].morality);
strcpy(credit[j].morality, credit[j + 1].morality);
strcpy(credit[j + 1].morality, credit_buffer.morality);
strcpy(credit_buffer.innovate, credit[j].innovate);
strcpy(credit[j].innovate, credit[j + 1].innovate);
strcpy(credit[j + 1].innovate, credit_buffer.innovate);
strcpy(credit_buffer.other, credit[j].other);
strcpy(credit[j].other, credit[j + 1].other);
strcpy(credit[j + 1].other, credit_buffer.other);
}
}
}
//输出数据
for (int b = 0; b < 14; b++)
{
//将结构数组中数据输出到主表格
outtextxy(63, 113 + b * longitudinal_s, credit[b].studentID);
outtextxy(245, 113 + b * longitudinal_s, credit[b].Name);
outtextxy(352, 113 + b * longitudinal_s, credit[b].compulsory);
outtextxy(352+Transverse_s, 113 + b * longitudinal_s, credit[b].select);
outtextxy(352 +2 * Transverse_s , 113+ b * longitudinal_s, credit[b].morality);
outtextxy(352 + 3 * Transverse_s, 113 + b * longitudinal_s, credit[b].innovate);
outtextxy(352 +4 * Transverse_s , 113 + b * longitudinal_s, credit[b].other);
outtextxy(352 + 5* Transverse_s, 113 + b * longitudinal_s, credit[b].sum);
}
//按键的响应
while (1)//时刻获取鼠标信息
{
if (MouseHit())//如果有消息
{
MOUSEMSG credit_s = GetMouseMsg();//设置变量引入消息
switch (credit_s.uMsg)//判断是什么信息
{
case WM_LBUTTONDOWN://左键
//(返回)按钮
if (credit_s.x > 21.54 && credit_s.x < 102.04 && credit_s.y>661.42 && credit_s.y < 706.39)
{
managewindows();//管理员界面
break;
}
//(显示学生基本信息)按钮
else if (credit_s.x > 915.69 && credit_s.x < 1094.07 && credit_s.y>661.8 && credit_s.y < 706.39)
{
information_homepage();//首页学生信息表
break;
}
//(下一页)按钮
else if (credit_s.x > 1114.1 && credit_s.x < 1221.42 && credit_s.y>661.8 && credit_s.y < 706.39)
{
credit_secondarypage();//次页学分表
break;
}
}
}
}
}
void information_homepage()//首页学生信息表
{
IMAGE informationpicture_s;//定义界面图片指针
loadimage(&informationpicture_s, "./界面图片/首页学生信息表.png", 1280, 720);
putimage(0, 0, &informationpicture_s);
settextstyle(25, 0, _T("Consolas"));//设置字体大小
settextcolor(WHITE);//设置字体颜色为白色
setbkmode(TRANSPARENT);//消除字体背景颜色
//冒泡排序法——学号排序
int i = 0, j;
for (i; i < nowstudentnums; i++)
{
for (j = 0; j < nowstudentnums - i - 1; j++)
{
if (atof(information[j].s_studentID) > atof(information[j + 1].s_studentID))
{
strcpy(information_buffer.s_studentID, information[j].s_studentID);
strcpy(information[j].s_studentID, information[j + 1].s_studentID);
strcpy(information[j + 1].s_studentID, information_buffer.s_studentID);
strcpy(information_buffer.s_Name, information[j].s_Name);
strcpy(information[j].s_Name, information[j + 1].s_Name);
strcpy(information[j + 1].s_Name, information_buffer.s_Name);
strcpy(information_buffer.s_gender, information[j].s_gender);
strcpy(information[j].s_gender, information[j + 1].s_gender);
strcpy(information[j + 1].s_gender, information_buffer.s_gender);
strcpy(information_buffer.s_faculty, information[j].s_faculty);
strcpy(information[j].s_faculty, information[j + 1].s_faculty);
strcpy(information[j + 1].s_faculty, information_buffer.s_faculty);
strcpy(information_buffer.s_speciality, information[j].s_speciality);
strcpy(information[j].s_speciality, information[j + 1].s_speciality);
strcpy(information[j + 1].s_speciality, information_buffer.s_speciality);
strcpy(information_buffer.s_grade, information[j].s_grade);
strcpy(information[j].s_grade, information[j + 1].s_grade);
strcpy(information[j + 1].s_grade, information_buffer.s_grade);
strcpy(information_buffer.s_number, information[j].s_number);
strcpy(information[j].s_number, information[j + 1].s_number);
strcpy(information[j + 1].s_number, information_buffer.s_number);
}
}
}
//输出数据
for (int a = 0; a < 14; a++)
{
//将结构数组中数据输出到表格
outtextxy(33.25, 118 + a * longitudinal, information[a].s_studentID);
outtextxy(33.25+ Transverse, 118 + a * longitudinal, information[a].s_Name);
outtextxy(33.25 + 2 * Transverse, 118 + a * longitudinal, information[a].s_gender);
outtextxy(33.25 + 3 * Transverse, 118 + a * longitudinal, information[a].s_faculty);
outtextxy(33.25+ 4 * Transverse, 118+ a * longitudinal, information[a].s_speciality);
outtextxy(33.25 + 5 * Transverse, 118 + a * longitudinal, information[a].s_grade);
outtextxy(33.25 + 6 * Transverse, 118 + a * longitudinal, information[a].s_number);
}
//按键的响应
while (1)//时刻获取鼠标信息
{
if (MouseHit())//如果有消息
{
MOUSEMSG information_s = GetMouseMsg();//设置变量引入消息
switch (information_s.uMsg)//判断是什么信息
{
case WM_LBUTTONDOWN://左键
//(返回)按钮
if (information_s.x > 21.24 && information_s.x < 122.44 && information_s.y>663.31 && information_s.y < 706.77)
{
managewindows();//管理员界面
break;
}
//(显示学分)按钮
else if (information_s.x > 956.13 && information_s.x < 1085.75 && information_s.y>663.31 && information_s.y < 706.77)
{
credit_homepage();//首页学分表
break;
}
//(下一页)按钮
else if (information_s.x > 1122.41 && information_s.x < 1227.47 && information_s.y>633.31 && information_s.y < 706.77)
{
information_secondarypage();//次页学生信息表
break;
}
}
}
}
}
void information_secondarypage()//次页学生信息表
{
IMAGE informationpicture_c;//定义界面图片指针
loadimage(&informationpicture_c, "./界面图片/次页学生信息表.png", 1280, 720);
putimage(0, 0, &informationpicture_c);
settextstyle(25, 0, _T("Consolas"));//设置字体大小
settextcolor(WHITE);//设置字体颜色为白色
setbkmode(TRANSPARENT);//消除字体背景颜色
int b=0;
//输出数据
for (int a = 14; a <28 ; a++)
{
//将结构数组中数据输出到表格
outtextxy(33.26, 90 + b * longitudinal, information[a].s_studentID);
outtextxy(33.26 + Transverse, 90 + b * longitudinal, information[a].s_Name);
outtextxy(33.26 + 2 * Transverse, 90 + b * longitudinal, information[a].s_gender);
outtextxy(33.26 + 3 * Transverse, 90 + b * longitudinal, information[a].s_faculty);
outte