一、Dev-C++配置EasyX库
EasyX 是针对 C/C++ 的图形库,可以帮助使用C/C++语言的程序员快速上手图形和游戏编程。比如,可以用 EasyX 很快的用几何图形画一个房子,或者一辆移动的小车,可以编写俄罗斯方块、贪吃蛇、黑白棋等小游戏,可以练习图形学的各种算法,等等。
安装
下载地址:https://www.easyx.cn/downloads/
下载后解压缩
将easyx.h 和 graphics.h 拷贝到Dev-C++安装路径\MinGW64\x86_64-w64-mingw32\include
将lib32中的libeasyx.a拷贝到Dev-C++安装路径\MinGW64\x86_64-w64-mingw32\lib32
将lib64中的libeasyx.a拷贝到Dev-C++安装路径\MinGW64\x86_64-w64-mingw32\lib
配置编译环境
创建新项目:菜单 -> 新建 -> 项目,选择 Console Application,项目名称 如项目1(根据自己的情况填写),语言选择 C++,点击确定,参见下图:
测试``
#include <graphics.h>
#include <conio.h>
int main()
{
initgraph(640, 480);
circle(400, 240, 100);
getch();
closegraph();
return 0;
}
设置链接库:菜单 项目-> 项目属性…,选择选项卡参数,然后在 链接 区域点按钮 逐个添加:libeasyx.a、libgdi32.a、libole32.a,或者也可以直接输入 -leasyx -lgdi32 -lole32,完成。
编译后结果
二、考勤管理系统的搭建
1.功能描述
该考勤系统使用图形化编程实现了包括浏览学生考勤信息,对学生考勤信息排序,查询学生考勤信息,删除学生考勤信息,修改学生考勤信息,求平均,旷课次数最多与最少同学等功能。
2.代码
代码如下(示例):
#include <bits/stdc++.h>
#include<graphics.h>
using namespace std;
#define manx 800
#define NAME 20
#define SEX 10
#define KDAYS 20
#define ADDR 30
#define NUMBER 12
#define DAK 10
#define CLASS 30
#define STUDENTMAX 1000 //学生最大人数
int CurrentNumber=9;//当前人数
FILE*fp=NULL;
void BackTitle();
void load();
void Prt();
void Search();
void Sorted();
void BackSorted();
void ToSorted();
void ChSorted();
void MaSorted();
void EnSorted();
void ReviseInfo();
void DeleteInfo();
void AddInfo();
void ComputeInfo();
struct studentinfo //学生个人信息结构
{
char name [NAME]; //学生姓名
char number [NUMBER]; //学生学号
char clas [CLASS];
char day[DAK];
int ch;
int en;
int math;
int total ;
}stu[manx];
void FirstPage ()
{
//窗口大小
initgraph(760, 760);
setfillcolor(RED);//用于给矩形框填充颜色。
// 加载图片
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");//自己图片地址
//大标题
char MainTitle[20] = { "学生考勤管理系统" };
settextstyle(60, 0, "楷体"); //字体高度60宽度 自适应
outtextxy(150, 100,MainTitle); // 在指定的位置内打印文本
//副标题
char subheading0[20] = { "添加学生信息" };
char subheading1[20] = { "浏览考勤信息" };
char subheading2[20] = { "查询个人信息" };
char subheading3[20] = { "修改个人信息" };
char subheading4[20] = { "按考勤次数排序" };
char subheading5[20] = { "删除个人信息" };
char subheading6[20] = { "退出" };
char subheading7[20] = { "计算平均值" };
//设置6个矩形框
fillrectangle(230, 205, 560, 250);
fillrectangle(230, 265, 560, 310);
fillrectangle(230, 325, 560, 370);
fillrectangle(230, 385, 560, 430);
fillrectangle(230, 445, 560, 490);
fillrectangle(230, 505, 560, 550);
fillrectangle(230, 565, 560, 610);
fillrectangle(230, 625, 560, 670);
//设置字体
setbkmode(TRANSPARENT);
settextcolor(RGB(255,255,0));
settextstyle(40, 0, "楷体");
//书写内容
outtextxy(240, 210, subheading7);
outtextxy(240, 270, subheading0);
outtextxy(240, 330, subheading1);
outtextxy(240, 390, subheading2);
outtextxy(240, 450, subheading3);
outtextxy(240, 510, subheading4);
outtextxy(240, 570, subheading5);
outtextxy(240, 630, subheading6);
//鼠标操作1
MOUSEMSG m1;
while (1)
{
m1 = GetMouseMsg();//获取鼠标操作
if (m1.x >= 230 && m1.x <= 560 && m1.y >= 325 && m1.y <= 370)//浏览
{
//setlinecolor(RED);//设置电击时为红色
//rectangle(230, 325, 560, 370);
if (m1.uMsg == WM_LBUTTONDOWN) //右键单击一次触发
{
//浏览
load();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 385 && m1.y <= 430)//普通用户界面
{
//setlinecolor(RED);
//rectangle(230, 385, 560, 430);
if (m1.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//查询
Search();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 505 && m1.y <= 550)//普通用户界面230, 505, 560, 550
{
//setlinecolor(RED);
//rectangle(230, 385, 560, 430);
if (m1.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//排序
Sorted();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 445 && m1.y <= 490)//普通用户界面230, 505, 560, 550
{
//setlinecolor(RED);
//rectangle(230, 385, 560, 430);
if (m1.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//修改
ReviseInfo();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 565 && m1.y <= 610)//普通用户界面230, 505, 560, 550
{
//setlinecolor(RED);
//rectangle(230, 385, 560, 430);
if (m1.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//删除
DeleteInfo();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 265 && m1.y <= 310)//普通用户界面230, 505, 560, 550
{
//setlinecolor(RED);
//rectangle(230, 385, 560, 430);
if (m1.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//添加
AddInfo();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 205 && m1.y <= 250)//普通用户界面230, 505, 560, 550
{
//setlinecolor(RED);
//rectangle(230, 385, 560, 430);
if (m1.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//添加
ComputeInfo();
}
}
else if (m1.x >= 230 && m1.x <= 560 && m1.y >= 625 && m1.y <= 670)//退出
{
//setlinecolor(RED);
// rectangle(230, 565, 560, 610);
if (m1.uMsg == WM_LBUTTONDOWN)
{
exit(0);
}
}
}
system("pause");
closegraph();
}
void load ()
{ int x=0,y=0;
initgraph(860, 760);
fp=fopen("C:/短学期人工智能程序设计/代码/student.txt","r+");
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
rewind(fp);
settextcolor(RGB(255,255,0));
settextstyle(20, 0, "楷体");
outtextxy(x, y,"学号");
outtextxy(x+150, y,"姓名");
outtextxy(x+250, y,"班级");
outtextxy(x+400, y,"日期");
outtextxy(x+500, y,"语文");
outtextxy(x+600, y,"数学");
outtextxy(x+700, y,"英语");
outtextxy(x+800, y,"总计");
y+=60;
for (int i=0;i<CurrentNumber;i++)
{
settextcolor(RGB(255,255,255));
settextstyle(18, 0, "黑体");
fscanf(fp, "%s %s %s %s %d %d %d %d", stu[i].number, stu[i].name,stu[i].clas,stu[i].day, &stu[i].ch,&stu[i].math,&stu[i].en,&stu[i].total);
char str1[10], str2[10], str3[10],str4[10];
sprintf(str1, "%d", stu[i].ch);
sprintf(str2, "%d", stu[i].math);
sprintf(str3, "%d", stu[i].en);
sprintf(str4, "%d", stu[i].total);
outtextxy(x, y,stu[i].number);
outtextxy(x+150, y,stu[i].name);
outtextxy(x+250, y,stu[i].clas);
outtextxy(x+400, y,stu[i].day);
outtextxy(x+500, y,str1);
outtextxy(x+600, y,str2);
outtextxy(x+700, y,str3);
outtextxy(x+800, y,str4);
y=y+50;
x=0;
}
setfillcolor(RED);
fillrectangle(230, 685, 560, 730);
setbkmode(TRANSPARENT);
settextstyle(40, 0, "楷体");
char Select1[20] = { "返回" };
outtextxy(350, 685, Select1);
MOUSEMSG m3;
while (1)
{
m3 = GetMouseMsg();//获取鼠标操作
if (m3.x >= 230 && m3.x <= 560 && m3.y >= 685 && m3.y <= 730)//选项1
{
if (m3.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
FirstPage();
}
}
}
}
void Prt ()
{
int x=0,y=0;
settextcolor(RGB(255,255,0));
settextstyle(20, 0, "楷体");
outtextxy(x, y,"学号");
outtextxy(x+150, y,"姓名");
outtextxy(x+250, y,"班级");
outtextxy(x+400, y,"日期");
outtextxy(x+500, y,"语文");
outtextxy(x+600, y,"数学");
outtextxy(x+700, y,"英语");
outtextxy(x+800, y,"总计");
y+=60;
for (int i=0;i<CurrentNumber;i++)
{
settextcolor(RGB(255,255,255));
settextstyle(18, 0, "黑体");
char str1[10], str2[10], str3[10],str4[10];
sprintf(str1, "%d", stu[i].ch);
sprintf(str2, "%d", stu[i].math);
sprintf(str3, "%d", stu[i].en);
sprintf(str4, "%d", stu[i].total);
outtextxy(x, y,stu[i].number);
outtextxy(x+150, y,stu[i].name);
outtextxy(x+250, y,stu[i].clas);
outtextxy(x+400, y,stu[i].day);
outtextxy(x+500, y,str1);
outtextxy(x+600, y,str2);
outtextxy(x+700, y,str3);
outtextxy(x+800, y,str4);
y=y+50;
x=0;
}
}
void Search ()
{
initgraph(860, 760);
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
fillrectangle(0, 0,760, 240);
settextstyle(30, 0, "楷体");
outtextxy(0,0, "*----------------------------------------------------*\n");
outtextxy(0,30, "* 成绩查询菜单 *\n");
outtextxy(0,60, "*----------------------------------------------------*\n");
outtextxy(0,90, "* 1: 按学号查询 *\n");
outtextxy(0,120, "* 2: 按姓名查询 *\n");
//outtextxy(0,150, "* 3: 全班排名查询 *\n");
outtextxy(0,150, "* 0: 退出查询系统,返回主系统 *\n");
outtextxy(0,180, "*----------------------------------------------------*\n");
outtextxy(0,210, "选择操作<0-2> \n");
char ReceInput[64];//存放查找数据
TCHAR InputWindowFI[] = _T("请选择操作:");
InputBox(ReceInput, 10, InputWindowFI);
settextstyle(20, 0, "楷体");
settextcolor(RGB(255,255,0));
if (strcmp("1", ReceInput) == 0)
{
char ReceInput1[64];//存放查找数据
TCHAR InputWindowFI1[] = _T("请输入学号(10位):");
InputBox(ReceInput1, 20, InputWindowFI1);
for (int i=0;i<CurrentNumber;i++)
{
if (strcmp(stu[i].number,ReceInput1) == 0)
{
int x=0,y=300;
char str1[10], str2[10], str3[10],str4[10];
sprintf(str1, "%d", stu[i].ch);
sprintf(str2, "%d", stu[i].math);
sprintf(str3, "%d", stu[i].en);
sprintf(str4, "%d", stu[i].total);
outtextxy(x, y,stu[i].number);
outtextxy(x+150, y,stu[i].name);
outtextxy(x+250, y,stu[i].clas);
outtextxy(x+400, y,stu[i].day);
outtextxy(x+500, y,str1);
outtextxy(x+600, y,str2);
outtextxy(x+700, y,str3);
outtextxy(x+800, y,str4);
break;
}
else continue;
}
// outtextxy(230, 560,"查无此人");
}
else
{
if (strcmp("2", ReceInput) == 0)
{
char ReceInput2[64];//存放查找数据
TCHAR InputWindowFI2[] = _T("请输入姓名:");
InputBox(ReceInput2, 20, InputWindowFI2);
for (int i=0;i<CurrentNumber;i++)
{
if (strcmp(stu[i].name,ReceInput2) == 0)
{
int x=0,y=300;
char str1[10], str2[10], str3[10],str4[10];
sprintf(str1, "%d", stu[i].ch);
sprintf(str2, "%d", stu[i].math);
sprintf(str3, "%d", stu[i].en);
sprintf(str4, "%d", stu[i].total);
outtextxy(x, y,stu[i].number);
outtextxy(x+150, y,stu[i].name);
outtextxy(x+250, y,stu[i].clas);
outtextxy(x+400, y,stu[i].day);
outtextxy(x+500, y,str1);
outtextxy(x+600, y,str2);
outtextxy(x+700, y,str3);
outtextxy(x+800, y,str4);
break;
}
else continue;
}
//outtextxy(230, 560,"查无此人");
}
else outtextxy(230, 560,"查无此人");
}
BackTitle();
}
void Sorted ()
{
initgraph(860, 760);
setfillcolor(RED);//用于给矩形框填充颜色。
// 加载图片
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
//副标题
char subheading1[20] = { "按语文缺勤次数排序" };
char subheading2[20] = { "按数学缺勤次数排序" };
char subheading3[20] = { "按英语缺勤次数排序" };
char subheading4[20] = { "按总计缺勤次数排序" };
/*sort(stu,stu+CurrentNumber,cmp);
Prt();*/
fillrectangle(690, 90, 850, 140);
fillrectangle(690, 190, 850, 240);
fillrectangle(690, 290, 850, 340);
fillrectangle(690, 390, 850, 440);
fillrectangle(690, 490, 850, 540);
//设置字体
setbkmode(TRANSPARENT);
settextcolor(RGB(255,255,0));
settextstyle(30, 0, "楷体");
outtextxy(700, 0, "排序方式");
outtextxy(700, 100, "按语文排序");
outtextxy(700, 200, "按数学排序");
outtextxy(700, 300, "按英语排序");
outtextxy(700, 400, "按总分排序");
outtextxy(700, 500, "返回");
//鼠标操作1
MOUSEMSG m2;
while (1)
{
m2 = GetMouseMsg();//获取鼠标操作
if (m2.x >= 690 && m2.x <= 850 && m2.y >= 90 && m2.y <=140)
{
//setlinecolor(RED);//设置电击时为红色
//rectangle(690, 325, 560, 370);
if (m2.uMsg == WM_LBUTTONDOWN) //右键单击一次触发
{
//按语文缺勤次数排序
ChSorted();
}
}
else if (m2.x >= 690 && m2.x <= 850 && m2.y >= 190 && m2.y <= 240)//普通用户界面
{
//setlinecolor(RED);
//rectangle(690, 385, 560, 430);
if (m2.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//按数学缺勤次数排序
MaSorted();
}
}
else if (m2.x >= 690 && m2.x <= 850 && m2.y >= 290 && m2.y <= 340)//普通用户界面690, 505, 560, 550
{
//setlinecolor(RED);
//rectangle(690, 385, 560, 430);
if (m2.uMsg == WM_LBUTTONDOWN)
{
// cleardevice();
//按英语缺勤次数排序
EnSorted();
}
}
else if (m2.x >= 690 && m2.x <= 850 && m2.y >=390 && m2.y <= 440)//退出
{
//setlinecolor(RED);
// rectangle(690, 565, 560, 850);
if (m2.uMsg == WM_LBUTTONDOWN)
{
//按总计缺勤次数排序
ToSorted();
}
}
else if (m2.x >= 690 && m2.x <= 850 && m2.y >=490 && m2.y <= 540)//退出
{
//setlinecolor(RED);
// rectangle(690, 565, 560, 850);
if (m2.uMsg == WM_LBUTTONDOWN)
{
FirstPage();
}
}
}
}
bool Tocmp (studentinfo a,studentinfo b)
{
if (a.total<b.total) return 1;
else return 0;
}
void ToSorted ()
{
initgraph(860, 760);
// 加载图片
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
sort(stu,stu+CurrentNumber,Tocmp);
Prt();
BackSorted();
}
bool Chcmp (studentinfo a,studentinfo b)
{
if (a.ch<b.ch) return 1;
else return 0;
}
void ChSorted ()
{
initgraph(760, 760);
// 加载图片
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
sort(stu,stu+CurrentNumber,Chcmp);
Prt();
BackSorted();
}
bool Macmp (studentinfo a,studentinfo b)
{
if (a.math<b.math) return 1;
else return 0;
}
void MaSorted ()
{
initgraph(860, 760);
// 加载图片
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
sort(stu,stu+CurrentNumber,Macmp);
Prt();
BackSorted();
}
bool Encmp (studentinfo a,studentinfo b)
{
if (a.en<b.en) return 1;
else return 0;
}
void EnSorted ()
{
initgraph(760, 760);
// 加载图片
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
sort(stu,stu+CurrentNumber,Encmp);
Prt();
BackSorted();
}
void ReviseInfo ()
{
initgraph(860, 760);
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
fillrectangle(0, 0,760, 240);
settextstyle(30, 0, "楷体");
outtextxy(0,0, "*----------------------------------------------------*\n");
outtextxy(0,30, "* 成绩查询菜单 *\n");
outtextxy(0,60, "*----------------------------------------------------*\n");
outtextxy(0,90, "* 1: 按学号查询 *\n");
outtextxy(0,120, "* 2: 按姓名查询 *\n");
outtextxy(0,150, "* 3: 全班排名查询 *\n");
//outtextxy(0,180, "* 0: 退出查询系统,返回主系统 *\n");
outtextxy(0,180, "*----------------------------------------------------*\n");
outtextxy(0,210, "选择操作<0-2> \n");
char ReceInput[64];//存放查找数据
TCHAR InputWindowFI[] = _T("请选择查询的方式:");
InputBox(ReceInput, 10, InputWindowFI);
settextstyle(20, 0, "楷体");
settextcolor(RGB(255,255,0));
if (strcmp("1", ReceInput) == 0)
{
char ReceInput1[64];//存放查找数据
TCHAR InputWindowFI1[] = _T("请输入学号(10位):");
InputBox(ReceInput1, 20, InputWindowFI1);
for (int i=0;i<CurrentNumber;i++)
{
if (strcmp(stu[i].number,ReceInput1) == 0)
{
char ReceInput4[64];//存放查找数据
TCHAR InputWindowFI4[] = _T("请输入你要修改的科目(1.语文;2.数学;3.英语):");
InputBox(ReceInput4, 20, InputWindowFI4);
char ReceInput3[64];//存放查找数据
TCHAR InputWindowFI3[] = _T("请输入你修改的次数:");
InputBox(ReceInput3, 20, InputWindowFI3);
if (strcmp("1",ReceInput4)==0)
{
stu[i].ch=atoi(ReceInput3);
}
else
{
if (strcmp("2",ReceInput4)==0)
{
stu[i].math=atoi(ReceInput3);
}
else
{
if (strcmp("3",ReceInput4)==0)
{
stu[i].en=atoi(ReceInput3);
}
// else outtextxy(230, 560,"输入错误");
}
}
int x=0,y=300;
stu[i].total=stu[i].ch+stu[i].math+stu[i].en;
char str1[10], str2[10], str3[10],str4[10];
sprintf(str1, "%d", stu[i].ch);
sprintf(str2, "%d", stu[i].math);
sprintf(str3, "%d", stu[i].en);
sprintf(str4, "%d", stu[i].total);
outtextxy(x, y,stu[i].number);
outtextxy(x+150, y,stu[i].name);
outtextxy(x+250, y,stu[i].clas);
outtextxy(x+400, y,stu[i].day);
outtextxy(x+500, y,str1);
outtextxy(x+600, y,str2);
outtextxy(x+700, y,str3);
outtextxy(x+800, y,str4);
break;
}
else continue;
}
}
else
{
if (strcmp("2", ReceInput) == 0)
{
char ReceInput2[64];//存放查找数据
TCHAR InputWindowFI2[] = _T("请输入姓名:");
InputBox(ReceInput2, 20, InputWindowFI2);
for (int i=0;i<CurrentNumber;i++)
{
if (strcmp(stu[i].name,ReceInput2) == 0)
{
char ReceInput4[64];//存放查找数据
TCHAR InputWindowFI4[] = _T("请输入你要修改的科目(1.语文;2.数学;3.英语):");
InputBox(ReceInput4, 20, InputWindowFI4);
char ReceInput3[64];//存放查找数据
TCHAR InputWindowFI3[] = _T("请输入你修改的次数:");
InputBox(ReceInput3, 20, InputWindowFI3);
if (strcmp("1",ReceInput4)==0)
{
stu[i].ch=atoi(ReceInput3);
}
else
{
if (strcmp("2",ReceInput4)==0)
{
stu[i].math=atoi(ReceInput3);
}
else
{
if (strcmp("3",ReceInput4)==0)
{
stu[i].en=atoi(ReceInput3);
}
//else outtextxy(230, 560,"输入错误");
}
}
int x=0,y=300;
char str1[10], str2[10], str3[10],str4[10];
stu[i].total=stu[i].ch+stu[i].math+stu[i].en;
sprintf(str1, "%d", stu[i].ch);
sprintf(str2, "%d", stu[i].math);
sprintf(str3, "%d", stu[i].en);
sprintf(str4, "%d", stu[i].total);
outtextxy(x, y,stu[i].number);
outtextxy(x+150, y,stu[i].name);
outtextxy(x+250, y,stu[i].clas);
outtextxy(x+400, y,stu[i].day);
outtextxy(x+500, y,str1);
outtextxy(x+600, y,str2);
outtextxy(x+700, y,str3);
outtextxy(x+800, y,str4);
break;
}
else continue;
}
}
}
BackTitle();
}
void DeleteInfo()
{
int x ,len1;
initgraph(860, 760);
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
char ReceInput6[64];//存放查找数据
TCHAR InputWindowFI6[] = _T("您想删除同学学号(10位):");
InputBox(ReceInput6, 20, InputWindowFI6);
len1=strlen(ReceInput6);
if (len1==10)
{
for (int i=0;i<CurrentNumber;i++)
{
if (strcmp(stu[i].number,ReceInput6)==0) x=i;
else continue;
}
for (int j=x;j<CurrentNumber;j++)
{
stu[j]=stu[j+1];
}
CurrentNumber--;
Prt();
}
else
{
int flg1=1;
while (flg1)
{
char ReceInput[64];
TCHAR InputWindowFI[] = _T("输入错误(请重新输入):");
InputBox(ReceInput, 20, InputWindowFI);
len1=strlen(ReceInput);
if (len1==10)
{
for (int i=0;i<CurrentNumber;i++)
{
if (strcmp(stu[i].number,ReceInput6)==0) x=i+1;
else continue;
}
for (int j=x;j<CurrentNumber;j++)
{
stu[j]=stu[j+1];
}
CurrentNumber--;
Prt();
flg1=0;
}
else flg1=1;
}
}
BackTitle();
}
void AddInfo()
{
initgraph(860, 760);
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
int i=CurrentNumber,len1=0,len2=0,len3=0,len4=0;
char ReceInput1[64];
TCHAR InputWindowFI1[] = _T("请输入添加同学的学号(10位):");
InputBox(ReceInput1, 20, InputWindowFI1);
len1=strlen(ReceInput1);
if (len1==10)
{
strcpy(stu[i].number,ReceInput1);//赋值
}
else
{
int flg1=1;
while (flg1)
{
char ReceInput[64];
TCHAR InputWindowFI[] = _T("输入错误(请重新输入):");
InputBox(ReceInput, 20, InputWindowFI);
len1=strlen(ReceInput);
if (len1==10)
{
strcpy(stu[i].number,ReceInput);//赋值
flg1=0;
}
else flg1=1;
}
}
char ReceInput2[64];
TCHAR InputWindowFI2[] = _T("请输入添加同学的姓名:");
InputBox(ReceInput2, 20, InputWindowFI2);
strcpy(stu[i].name,ReceInput2);
char ReceInput3[64];
TCHAR InputWindowFI3[] = _T("请输入添加同学的班级(计算机1401):");
InputBox(ReceInput3, 20, InputWindowFI3);
strcpy(stu[i].clas,ReceInput3);
char ReceInput7[64];
TCHAR InputWindowFI7[] = _T("请输入添加同学的日期:");
InputBox(ReceInput7, 20, InputWindowFI7);
strcpy(stu[i].day,ReceInput7);
char ReceInput4[64];
TCHAR InputWindowFI4[] = _T("请输入添加同学的语文缺勤次数:");
InputBox(ReceInput4, 20, InputWindowFI4);
stu[i].ch =atoi(ReceInput4);
char ReceInput5[64];
TCHAR InputWindowFI5[] = _T("请输入添加同学的数学缺勤次数:");
InputBox(ReceInput5, 20, InputWindowFI5);
stu[i].math =atoi(ReceInput5);
char ReceInput6[64];
TCHAR InputWindowFI6[] = _T("请输入添加同学的英语缺勤次数:");
InputBox(ReceInput6, 20, InputWindowFI6);
stu[i].en = atoi(ReceInput6);
stu[i].total=stu[i].ch+stu[i].math+stu[i].en;
CurrentNumber++;
Prt();
BackTitle();
}
void ComputeInfo()
{
initgraph(860, 760);
loadimage(0,"C:\\Users\\s\\Pictures\\Camera Roll\\学生考勤.jpg");
int sum=0,sumc=0,summ=0,sume=0;
double average=0,averagec=0,averagem=0,averagee=0;
for (int i=0;i<CurrentNumber;i++)
{
sum+=stu[i].total;
sumc+=stu[i].ch;
summ+=stu[i].math;
sume+=stu[i].en;
}
average=1.0*(sum/CurrentNumber);
averagec=1.0*(sumc/CurrentNumber);
averagem=1.0*(summ/CurrentNumber);
averagee=1.0*(sume/CurrentNumber);
char str1[10], str2[10], str3[10],str4[10];
char s[]="平均旷课次数:";
settextstyle(20, 0, "楷体");
settextcolor(RGB(255,255,0));
sprintf(str1, "%.2lf", average);
strcat(s, str1);
outtextxy(0, 100,s);
sort(stu,stu+CurrentNumber,Tocmp);
char d[]="旷课最多的同学:";
strcat(d, stu[CurrentNumber-1].name);
outtextxy(0, 150,d);
char c[]="旷课最少的同学:";
strcat(c, stu[0].name);
outtextxy(300, 150,c);
outtextxy(0, 200,"旷课低于平均值的同学:");
int x=210;
for (int i=0;i<CurrentNumber;i++)
{
if (stu[i].total<average)
{
outtextxy(x, 200,stu[i].name);
x+=70;
}
else break;
}
BackTitle();
}
void BackSorted ()
{
setfillcolor(RED);
fillrectangle(230, 685, 560, 730);
setbkmode(TRANSPARENT);
settextstyle(40, 0, "楷体");
char Select1[20] = { "返回" };
outtextxy(350, 685, Select1);
MOUSEMSG m4;
while (1)
{
m4 = GetMouseMsg();//获取鼠标操作
if (m4.x >= 230 && m4.x <= 560 && m4.y >= 685 && m4.y <= 730)//选项1
{
if (m4.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
Sorted();
}
}
}
}
void BackTitle()
{
setfillcolor(RED);
fillrectangle(230, 685, 560, 730);
setbkmode(TRANSPARENT);
settextstyle(40, 0, "楷体");
char Select1[20] = { "返回" };
outtextxy(350, 685, Select1);
MOUSEMSG m4;
while (1)
{
m4 = GetMouseMsg();//获取鼠标操作
if (m4.x >= 230 && m4.x <= 560 && m4.y >= 685 && m4.y <= 730)//选项1
{
if (m4.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
FirstPage();
}
}
}
}
//void main()
int main()
{
fp=fopen("C:/代码/student.txt","r+");//自己的测试数据地址
rewind(fp);
for (int i=0;i<CurrentNumber;i++)
{
fscanf(fp, "%s %s %s %s %d %d %d %d", stu[i].number, stu[i].name, stu[i].clas,stu[i].day, &stu[i].ch,&stu[i].math,&stu[i].en,&stu[i].total);
}
FirstPage();
return 0;
}
测试数据
3140608002 小明 计算机1401 8月23日 3 4 7 14
3140602002 小红 计算机1401 8月23日 2 3 5 10
3140602003 小东 计算机1401 8月23日 0 2 1 3
3140618001 小兰 软件1401 8月23日 5 0 0 5
3140618002 小字 软件1401 8月23日 2 0 1 3
3140618003 小宇 软件1401 8月23日 8 0 0 8
3140608026 小秋 环境1401 8月24日 0 1 2 3
3140608027 小敏 环境1401 8月24日 0 0 1 1
3140608028 小伟 环境1401 8月24日 2 2 0 4