用C语言+EasyX写学生成绩管理系统
从一个啥也不会,只会在控制台黑框框里写简单的C,然后为了完成学生成绩管理系统课程设计作业,从0开始学习Easy X,最后写成能上交的作业。所以想在这里做个总结,也为后来者提供点思路。下面直接先看看效果吧。
? 主界面
? 成绩录入界面
若学号重复则提示
? 成绩查询界面:可以通过姓名或学生学号查询
若没有查询到,则提示查无此人
? 成绩修改界面:可以通过姓名或学生学号修改
? 成绩删除界面:可以通过姓名或学生学号删除
若查询到后会提示是否确认删除 若查询不到,则提示查无此人 ? 成绩打印界面:打印所有的学生信息和成绩
下面附上代码
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<string.h>
#include<ctype.h>
int nowstu_num = 0;
typedef struct Student
{
char s_Num[30];
char s_Name[30];
char s_computer[30];
char s_Math[30];
}Student;
Student s[30];
void SaveInfor();
void ReadInfor();
void Showall();
void InputInfor();
void ModiInfor();
void PrintUI();
void Dele();
void Printfind();
void SaveInforModi();
int R[] = { 150,50,650,150 };
int r1[] = { 200,200,600,250 };
int r2[] = { 200,270,600,320 };
int r3[] = { 200,340,600,390 };
int r4[] = { 200,410,600,460 };
int r5[] = { 200,480,600,530 };
int r6[] = { 200,550,600,600 };
void menu()
{
ReadInfor();
initgraph(800, 620);
ExMessage m1;
cleardevice();
IMAGE img;
loadimage(&img, "C:\\Users\\86182\\source\\repos\\学生成绩管理系统2.0\\Camera Roll\\file.jpg", 800, 620);
putimage(0, 0, &img);
setbkmode(TRANSPARENT);
setfillcolor(WHITE);
fillrectangle(r1[0], r1[1], r1[2], r1[3]);
fillrectangle(r2[0], r2[1], r2[2], r2[3]);
fillrectangle(r3[0], r3[1], r3[2], r3[3]);
fillrectangle(r4[0], r4[1], r4[2], r4[3]);
fillrectangle(r5[0], r5[1], r5[2], r5[3]);
fillrectangle(r6[0], r6[1], r6[2], r6[3]);
RECT R1 = { R[0],R[1],R[2],R[3] };
RECT R2 = { r1[0],r1[1],r1[2],r1[3] };
RECT R3 = { r2[0],r2[1],r2[2],r2[3] };
RECT R4 = { r3[0],r3[1],r3[2],r3[3] };
RECT R5 = { r4[0],r4[1],r4[2],r4[3] };
RECT R6 = { r5[0],r5[1],r5[2],r5[3] };
RECT R7 = { r6[0],r6[1],r6[2],r6[3] };
LOGFONT f;
gettextstyle(&f);
f.lfHeight = 60;
_tcscpy(f.lfFaceName, _T("宋体"));
f.lfQuality = ANTIALIASED_QUALITY;
settextstyle(&f);
setbkmode(TRANSPARENT);
settextcolor(BLACK);
drawtext("学生成绩管理系统", &R1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("成绩录入", &R2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("成绩查询", &R3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("成绩修改", &R4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("成绩删除", &R5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("成绩打印", &R6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("退出系统", &R7, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
while (1)
{
m1 = getmessage();
if (m1.x > r1[0] && m1.x < r1[2] && m1.y>r1[1] && m1.y < r1[3]) {
setlinecolor(RED);
rectangle(r1[0], r1[1], r1[2], r1[3]);
if (m1.message == WM_LBUTTONDOWN)
{
InputInfor();
}
}
else if (m1.x >= r2[0] && m1.x <= r2[2] && m1.y >= r2[1] && m1.y <= r2[3]) {
setlinecolor(RED);
rectangle(r2[0], r2[1], r2[2], r2[3]);
if (m1.message == WM_LBUTTONDOWN)
{
Printfind();
}
}
else if (m1.x >= r3[0] && m1.x <= r3[2] && m1.y >= r3[1] && m1.y <= r3[3]) {
setlinecolor(RED);
rectangle(r3[0], r3[1], r3[2], r3[3]);
if (m1.message == WM_LBUTTONDOWN)
{
ModiInfor();
}
}
else if (m1.x >= r4[0] && m1.x <= r4[2] && m1.y >= r4[1] && m1.y <= r4[3]) {
setlinecolor(RED);
rectangle(r4[0], r4[1], r4[2], r4[3]);
if (m1.message == WM_LBUTTONDOWN) {
Dele();
}
}
else if (m1.x >= r5[0] && m1.x <= r5[2] && m1.y >= r5[1] && m1.y <= r5[3]) {
setlinecolor(RED);
rectangle(r5[0], r5[1], r5[2], r5[3]);
if (m1.message == WM_LBUTTONDOWN) {
Showall();
}
}
else if (m1.x >= r6[0] && m1.x <= r6[2] && m1.y >= r6[1] && m1.y <= r6[3]) {
setlinecolor(RED);
rectangle(r6[0], r6[1], r6[2], r6[3]);
if (m1.message == WM_LBUTTONDOWN) {
closegraph();
}
}
else {
setlinecolor(WHITE);
rectangle(r1[0], r1[1], r1[2], r1[3]);
rectangle(r2[0], r2[1], r2[2], r2[3]);
rectangle(r3[0], r3[1], r3[2], r3[3]);
rectangle(r4[0], r4[1], r4[2], r4[3]);
rectangle(r5[0], r5[1], r5[2], r5[3]);
rectangle(r6[0], r6[1], r6[2], r6[3]);
}
}
}
void InputInfor()
{
while (1)
{
InputBox(s[nowstu_num].s_Num, 9, "请输入该学生的学号");
int FlagInput2 = 0;
int nums = strlen(s[nowstu_num].s_Num);
if (FlagInput2 == 0)
{
int FlagInput1 = 0;
for (int i = 0; i < nowstu_num; i++)
{
if (strcmp(s[nowstu_num].s_Num, s[i].s_Num) == 0)
{
FlagInput1 = 1;
}
}
if (FlagInput1 == 1)
{
HWND hwndInput1 = GetHWnd();
int isok = MessageBox(hwndInput1, "该学生已经存在,请重新输入", "提示", MB_OK);
}
if (FlagInput1 == 0)
{
break;
}
}
}
InputBox(s[nowstu_num].s_Name, 10, "请输入该学生的姓名");
InputBox(s[nowstu_num].s_Math, 4, "请输入该学生的数学成绩");
InputBox(s[nowstu_num].s_computer, 4, "请输入该学生的计算机成绩");
SaveInfor();
}
void SaveInfor()
{
if (strlen(s[nowstu_num].s_Num) != 0 && strlen(s[nowstu_num].s_Name) != 0)
{
FILE* fp = fopen("StudentInfo.txt", "a");
if (fp == NULL)
{
return;
}
fprintf(fp, "%s\t%s\t%s\t%s\n",
s[nowstu_num].s_Num,
s[nowstu_num].s_Name,
s[nowstu_num].s_Math,
s[nowstu_num].s_computer);
fclose(fp);
nowstu_num++;
}
}
void ReadInfor()
{
FILE* fp = fopen("StudentInfo.txt", "r");
if (fp == NULL)
{
return;
}
for (int i = 0; i < 15; i++)
{
fscanf(fp, "%s\t%s\t%s\t%s\t\n",
s[i].s_Num,
s[i].s_Name,
s[i].s_computer,
s[i].s_Math);
}
int FileStudentNums = 0;
for (int j = 0; j < 15; j++)
{
if (strlen(s[j].s_Name) != 0)
{
nowstu_num = ++FileStudentNums;
}
}
fclose(fp);
}
int cha()
{
char Input[30];
InputBox(Input, 10, "请输入学生的姓名或学号");
for (int k = 0; k < nowstu_num; k++)
{
if (strcmp(s[k].s_Name, Input) == 0 || strcmp(s[k].s_Num, Input) == 0)
{
return k;
}
}
return -1;
}
void PrintUI(int q)
{
ExMessage m2;
initgraph(640, 480);
IMAGE img1;
loadimage(&img1, "C:\\Users\\86182\\source\\repos\\学生成绩管理系统2.0\\Camera Roll\\file.jpg", 640, 480);
putimage(0, 0, &img1);
setfillcolor(WHITE);
fillrectangle(300, 380, 380, 410);
setbkmode(TRANSPARENT);
settextcolor(BLACK);
settextstyle(20, 0, "黑体");
outtextxy(40, 100, "学号");
outtextxy(200, 100, "姓名");
outtextxy(300, 100, "计算机");
outtextxy(380, 100, "数学");
outtextxy(320, 380, "返回");
outtextxy(40, 140, s[q].s_Num);
outtextxy(200, 140, s[q].s_Name);
outtextxy(300, 140, s[q].s_computer);
outtextxy(380, 140, s[q].s_Math);
while (1) {
m2 = getmessage();
if (m2.x > 300 && m2.x < 380 && m2.y>380 && m2.y < 410) {
setlinecolor(RED);
rectangle(300, 380, 380, 410);
}
else {
setlinecolor(WHITE);
rectangle(300, 380, 380, 410);
}
if (m2.message == WM_LBUTTONDOWN) {
menu();
}
}
}
void Printfind()
{
int fan1 = cha();
if (fan1 == -1)
{
HWND hndtipsF = GetHWnd();
int isok = MessageBox(hndtipsF, "查无此人!", "提示", MB_OK);
}
else
{
PrintUI(fan1);
}
}
void ModiInfor()
{
int fan2 = cha();
if (fan2 == -1)
{
HWND hndtipsM = GetHWnd();
int isok = MessageBox(hndtipsM, "查无此人!", "提示", MB_OK);
}
else
{
while (1)
{
char modi[30];
InputBox(modi, 9, "请输入需要修改的学生的学号");
if (strcmp(modi, s[fan2].s_Num) == 0)
{
break;
}
else
{
int flag = 0;
int nums = strlen(modi);
for (int i = 0; i < nowstu_num; i++)
{
if (strcmp(modi, s[i].s_Num) == 0)
{
flag = 1;
break;
}
}
if (flag == 1)
{
HWND hwndInput4 = GetHWnd();
int isok = MessageBox(hwndInput4, "该学生已经存在,请重新输入", "提示", MB_OK);
}
else if (flag == 0)
{
memcpy(s[fan2].s_Num, modi, nums);
break;
}
}
}
InputBox(s[fan2].s_Name, 8, "请输入该学生的姓名");
InputBox(s[fan2].s_computer, 10, "请输入该学生的计算机成绩");
InputBox(s[fan2].s_Math, 10, "请输入该学生的数学成绩");
}
SaveInforModi();
}
void Dele()
{
int dele = cha();
if (dele == -1)
{
HWND hndtipsD = GetHWnd();
int isok = MessageBox(hndtipsD, "查无此人!", "提示", MB_OK);
}
else
{
HWND hndtipsDS = GetHWnd();
int isok = MessageBox(hndtipsDS, "确定删除?", "提示", MB_OKCANCEL);
if (isok == IDOK)
{
for (int n = dele; n < nowstu_num; n++)
{
s[n] = s[n + 1];
}
nowstu_num--;
SaveInforModi();
}
else if (isok == IDCANCEL)
{
}
}
}
void SaveInforModi()
{
remove("StudentInfo.txt");
FILE* fp = fopen("StudentInfo.txt", "a");
if (fp == NULL)
{
return;
}
for (int i = 0; i < nowstu_num; i++)
{
if (strlen(s[i].s_Num) != 0 && strlen(s[i].s_Name) != 0)
{
fprintf(fp, "%s\t%s\t%s\t%s\n",
s[i].s_Num,
s[i].s_Name,
s[i].s_computer,
s[i].s_Math);
}
}
fclose(fp);
}
void Showall()
{
ExMessage m3;
initgraph(640, 480);
IMAGE img2;
loadimage(&img2, "C:\\Users\\86182\\source\\repos\\学生成绩管理系统2.0\\Camera Roll\\file.jpg", 640, 480);
putimage(0, 0, &img2);
setfillcolor(WHITE);
fillrectangle(300, 430, 380, 460);
setbkmode(TRANSPARENT);
settextcolor(BLACK);
settextstyle(20, 0, "黑体");
outtextxy(40, 20, "学号");
outtextxy(200, 20, "姓名");
outtextxy(300, 20, "计算机");
outtextxy(380, 20, "数学");
outtextxy(320, 440, "返回");
for (int q = 0;q <= nowstu_num;q++) {
outtextxy(40, 60 + q * 20, s[q].s_Num);
outtextxy(200, 60 + q * 20, s[q].s_Name);
outtextxy(300, 60 + q * 20, s[q].s_computer);
outtextxy(380, 60 + q * 20, s[q].s_Math);
}
while (1) {
m3 = getmessage();
if (m3.x > 300 && m3.x < 430 && m3.y>380 && m3.y < 460) {
setlinecolor(RED);
rectangle(300, 430, 380, 460);
}
else {
setlinecolor(WHITE);
rectangle(300, 430, 380, 460);
}
if (m3.message == WM_LBUTTONDOWN) {
menu();
}
}
}
int main(void)
{
menu();
return 0;
}
如果对你有一定的帮助,记得点赞收藏啊!!
|