suan.h文件代码
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#undef UNICODE
#undef _UNICODE
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <time.h>
#include <conio.h>
#include<iostream>
#include<cstring>
#include<utility>
using namespace std;
#define MaxSize 300
/*
1.按成绩总分由高到低显示所有记录。
2.统计汇总(即两次考试中,校,班的各科平均分,最高分,最低分,不及格人数,第二次考试缺考名单等所有数据)。
3.查询数据(即输入姓名或学号可查询该生的所有成绩与排名,最好支持模糊查询,即输入“李”可查询所有名字中含有“李”字学生的成绩;)
4.修改数据。
5.成绩补录。(能找出第二次缺考考生的全部名单,进行成绩补录,考试成绩自定)
6.删除数据。(按学号,或按姓名删除指定记录)
7.能按成绩总分降序排列然后再赋与名次(班排名与校排名),分数相同名次相同。(如果有两个第二名,则没有第三名了)
8.能看到学生最近考试成绩的总分升降情况,能按进步排名进行降序排列(相对上次次考试)。
9.其它功能等。(自己自由发挥)
核心:增,删,查,改,导入,导出数据
*/
//学生结构体的定义
typedef struct student
{
int clas; //班级
char no[14]; //学号
char name[20]; //姓名
double score[6]; //六门功课的成绩
double sum; //总分
int school_rank; //校排名
int class_rank; //班排名
int rises; //班级进步
int rise; //学校进步
//.......
} stud;
typedef struct
{
stud data[MaxSize];
int length; //长度,学生的人数
int cla1; double scor1; //一班现在排名最高,分数
int cla2; double scor2; //二班
double maxx[6], averge[6], minn[6], que[6]; int noo[6];//分别为单科最高平均最低不及格缺考人(分)
int chi; //考试次数
}SqList;
//0-5分别是一班一次,一班二次,二班一次,二班二次,校一次,校二次成绩;
SqList* L[6];
char daochuming[6][19] = { "xclass11.txt","xclass12.txt","xclass21.txt","xclass22.txt","xschoo11.txt","xschoo12.txt" };//导出文件名分别是一班一次,一班二次,二班一次,二班二次,校一次,校二次成绩;
//初始化
void InitList(SqList*& L)
{
L = new SqList;
L->length = 0;
}
//建表
void CreateList(SqList*& L, const char* na)
{
FILE* fp;
if ((fp = fopen(na, "r")) == NULL) //用只读的方式打开文件,并让文件指针fp指向它
{
printf("打开的文件不存在!");
exit(0);
}
int i = L->length; //记录学生人数
while (!feof(fp))
{
fscanf(fp, "%s%s", L->data[i].no, L->data[i].name);
L->data[i].clas = L->data[i].no[10] - '0';
for (int j = 0; j <= 5; j++)
fscanf(fp, "%lf", &L->data[i].score[j]);
i++; //人数加1
}
L->length = i - 1;
fclose(fp); //关闭文件
}
//统计汇总(即两次考试中,校,班的各科平均分,最高分,最低分,不及格人数,第二次考试缺考名单等所有数据),计算总分
void Score(SqList*& L)
{
memset(L->minn, 0, sizeof(L->minn));
memset(L->averge, 0, sizeof(L->averge));
memset(L->noo, 0, sizeof(L->noo));
memset(L->que, 0, sizeof(L->que));
for (int j = 0; j < 6; j++)
{
L->minn[j] = 101;
}
for (int i = 0; i < L->length; i++)
{
L->data[i].sum = 0;
for (int j = 0; j < 6; j++)
{
L->data[i].sum += L->data[i].score[j];//计算总分
if (L->data[i].score[j] < 60 && L->data[i].score[j]>0)//计算不及格人数
{
L->noo[j]++;
}
if (L->data[i].score[j] <= 0 || L->data[i].score[j] > 100)//计算缺考人数
{
L->que[j]++;
}
else
{
L->averge[j] += L->data[i].score[j];//计算平均分
L->minn[j] = min(L->data[i].score[j], L->minn[j]);//计算单科最低分
L->maxx[j] = max(L->data[i].score[j], L->maxx[j]);//计算单科最高分
}
}
}
return;
}
//输出顺序表的内容
void DispList(SqList* L, char* na) //把顺序表L中的内容输出到文件na中
{
FILE* fp;
if ((fp = fopen(na, "w+")) == NULL) //用写的方式打开文件,并让文件指针fp指向它
{
printf("打开的文件不存在!");
exit(0);
}
fprintf(fp, "%-17s%-10s%6s%6s%6s%6s%6s%6s%10s%7s%7s%7s%7s%7s\n", "学号", "姓名", "数据结构", "高数", "英语", "线代", "思修", "体育", "总分", "校排名", "班排名", "校进步", "班进步", "班级");
fprintf(fp, "平均成绩 % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % \n ", L->averge[0] / (L->length - L->que[0]), L->averge[1] / (L->length - L->que[1]), L->averge[2] / (L->length - L->que[2]), L->averge[3] / (L->length - L->que[3]), L->averge[4] / (L->length - L->que[4]), L->averge[5] / (L->length - L->que[5]));
fprintf(fp, "最高成绩 % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf \n ", L->maxx[0], L->maxx[1], L->maxx[2], L->maxx[3], L->maxx[4], L->maxx[5]);
fprintf(fp, "最低成绩 % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf \n ", L->minn[0], L->minn[1], L->minn[2], L->minn[3], L->minn[4], L->minn[5]);
fprintf(fp, "不及格人数 %6d%6d%6d%6d%6d%6d\n", L->noo[0], L->noo[1], L->noo[2], L->noo[3], L->noo[4], L->noo[5]);
for (int i = 0; i < L->length; i++)
{
fprintf(fp, "%-17s%-10s", L->data[i].no, L->data[i].name);
fprintf(fp, "%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%8.1lf%7d%7d%7d%7d%7d\n", L->data[i].score[0], L->data[i].score[1], L->data[i].score[2], L->data[i].score[3], L->data[i].score[4], L->data[i].score[5], L->data[i].sum, L->data[i].school_rank, L->data[i].class_rank, L->data[i].rise, L->data[i].rises, L->data[i].clas);
}
fclose(fp);
}
// 交换两个学生的位置
void swap1(stud& a, stud& b)
{
stud temp = a;
a = b;
b = temp;
}
// 划分函数,用于确定分区点的位置
int partition(stud arr[], int low, int high)
{
double pivot = arr[high].sum; // 选择最后一个元素作为分区点
int i = low - 1;
for (int j = low; j <= high - 1; j++)
{
if (arr[j].sum >= pivot)
{
i++;
swap1(arr[i], arr[j]); // 将大于等于分区点的元素交换到左侧
}
}
swap1(arr[i + 1], arr[high]); // 将分区点放到正确的位置
return (i + 1);
}
// 使用快速排序算法对学生进行排序
void quickSort(stud arr[], int low, int high)
{
if (low < high)
{
int pivot = partition(arr, low, high); // 获取分区点
quickSort(arr, low, pivot - 1); // 对左子数组进行快速排序
quickSort(arr, pivot + 1, high); // 对右子数组进行快速排序
}
}
//计算排名
void calculateRanks(SqList* list)
{
int i, j, k;
int rank = 1;
list->data[0].school_rank = rank;
for (i = 0, j = 0, k = 0; i < list->length; i++)
{
// 计算校级排名
if (list->data[i].sum < list->data[i - 1].sum)
{
rank = i + 1;
}
list->data[i].school_rank = rank;
// 计算班级排名
if (list->data[i].clas == 0)
{
if (list->data[i].sum == list->scor1)
{
list->data[i].class_rank = j; j++;
}
else
{
j++; list->data[i].class_rank = j; list->cla1 = j; list->scor1 = list->data[i].sum;
}
}
else if (list->data[i].clas == 2)
{
if (list->data[i].sum == list->scor2)
{
list->data[i].class_rank = k; k++;
}
else
{
k++; list->data[i].class_rank = k; list->cla2 = k; list->scor2 = list->data[i].sum;
}
}
}
}
//插入学生
void insertStudent(SqList* list, stud newStudent)
{
int position;
int r = 0, s = list->length - 1, mid, k = 0;
while (r <= s)
{
mid = r + (s - r) / 2;
if (list->data[mid].sum > newStudent.sum)
r = mid + 1;
else if (list->data[mid].sum < newStudent.sum)
s = mid - 1;
else
{
k = 1;
r = mid;
break;
}
}
position = r;
if (position < 1 || position > list->length + 1)
{
printf("无效的插入位置\n");
return;
}
if (list->length >= MaxSize)
{
printf("学生列表已满,无法插入\n");
return;
}
list->length += 1; int clap = 0; bool t = 1;
// 将插入位置及其之后的学生向后移动一位
for (int i = list->length - 2; i >= position; i--)
{
list->data[i + 1] = list->data[i];
if (newStudent.sum != list->data[i + 1].sum)
{
list->data[i + 1].school_rank += 1;
if (newStudent.clas == list->data[i + 1].clas)
{
list->data[i + 1].class_rank += 1;
clap = list->data[i + 1].class_rank;
if (t)
{
if (newStudent.clas == 1)
list->cla1 = list->data[i + 1].class_rank;
else
list->cla2 = list->data[i + 1].class_rank;
t = 0;
}
}
}
}
// 在指定位置插入新学生
if (newStudent.sum != list->data[position + 2].sum)
{
newStudent.class_rank = clap - 1;
newStudent.school_rank = list->data[position + 2].school_rank;
}
list->data[position + 1] = newStudent;
printf("成功插入学生\n");
}
//删除学生
int deleteStudent(SqList*& list, string a)
{
int t = 0, clas = 11;
double x;
// 将删除位置之后的学生向前移动一位
for (int i = 0; i < list->length; i++)
{
if (list->data[i].no == a)
{
t = 1;
x = list->data[i].sum;
clas = list->data[i].clas;
}
if (t)
{
list->data[i - 1] = list->data[i];
if (list->data[i - 1].sum != x)
{
list->data[i - 1].school_rank--;
if (clas == list->data[i - 1].clas)
list->data[i - 1].class_rank--;
}
}
}
if (t)
list->length--;
if (t) {
printf("成功删除学生\n");
return 1;
}
printf("没有此学生\n");
return 0;
}
// 修改指定学生的成绩
void modifyScore(SqList* list, stud change)
{
int t = 0, clas, pai;
double x;
for (int i = 0; i < list->length; i++)
{
//比较
if (strcmp(change.name, list->data[i].name) == 0 || strcmp(change.no, list->data[i].no) == 0)
{
t = 1;
x = list->data[i].sum;
clas = list->data[i].clas;
}
if (t)
{
if (change.sum < list->data[i].sum)
{
list->data[i - 1] = list->data[i];
if (list->data[i - 1].sum != x)
{
list->data[i - 1].school_rank--;
if (clas == list->data[i - 1].clas)
{
list->data[i - 1].class_rank--;
pai = list->data[i - 1].class_rank;
}
}
}
else if (change.sum == list->data[i].sum)
{
list->data[i] = change;
}
else
{
change.class_rank = list->data[i - 1].class_rank + 1;
change.school_rank = list->data[i - 1].school_rank + 1;
if (clas == 1 && change.sum > list->scor1)
list->scor1 = change.sum;
else if (clas == 2 && change.sum > list->scor2)
list->scor2 = change.sum;
}
}
}
}
//模糊查找学生
void searchStudent(SqList* list, const char* keyword)
{
int found = 0;
for (int i = 0; i < list->length; i++)
{
if (strstr(list->data[i].name, keyword) != NULL || strcmp(list->data[i].no, keyword) == 0)
{
found = 1;
printf("学生姓名: %s\n", list->data[i].name);
printf("学号: %s\n", list->data[i].no);
printf("各科成绩:\n");
for (int j = 0; j < 6; j++)
{
printf("第%d门成绩: %.2f\n", j + 1, list->data[i].score[j]);
}
printf("总分: %.2f\n", list->data[i].sum);
printf("校排名: %d\n", list->data[i].school_rank);
printf("班排名: %d\n", list->data[i].class_rank);
printf("\n");
}
}
if (!found)
{
printf("未找到符合条件的学生\n");
}
}
//精确查找1
int searc1(SqList* list, const char* keyword)
{
int found = 0;
for (int i = 0; i < list->length; i++)
{
if (strcmp(list->data[i].no, keyword) == 0)
{
return list->data[i].school_rank;
}
}
}
//精确查找2
int searc2(SqList* list, const char* keyword)
{
int found = 0;
for (int i = 0; i < list->length; i++)
{
if (strcmp(list->data[i].no, keyword) == 0)
{
return list->data[i].class_rank;
}
}
}
//查询返回学生
pair<bool, stud> searc3(SqList* list, string keyword)
{
bool found = 0;
pair<bool, stud>aa;
aa.first = 0;
for (int i = 0; i < list->length; i++)
{
if (list->data[i].no == keyword || list->data[i].name == keyword)
{
aa.first = 1; aa.second = list->data[i];
cout << "成功";
return aa;
}
}
return aa;
}
//进步名次
void jinbu(SqList* L1, SqList*& L2)
{
for (int i = 0; i < L2->length; i++)
{
int t = searc1(L1, L2->data[i].no) - L2->data[i].school_rank;
L2->data[i].rise = t;//学校班级进步名次
int m = searc2(L1, L2->data[i].no) - L2->data[i].class_rank;
L2->data[i].rises = m;
}
}
//预处理
void yuchuli(SqList*& L5)
{
Score(L5);//计算总分,统计汇总(即两次考试中,校,班的各科平均分,最高分,最低分,不及格人数,第二次考试缺考名单等所有数据)
quickSort(L5->data, 0, L5->length);//排序
calculateRanks(L5);//排名
}
jiemian.h代码
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#undef UNICODE
#undef _UNICODE
#include <graphics.h>
#include <conio.h>
#include"suan.h"
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
#define tulen 1300
#define tude 700
typedef struct REC {
int left;
int top;
int right;
int bottom;
} REC;
int xunhuan(POINT cursorPos);
int xunhuan1(MOUSEMSG cursorPos);
//按钮1
void anniu1(int x1, int y1, int x2, int y2, const char* text, REC*& Box)
{
Box = new REC{ x1,y1,x2,y2 };
setbkcolor(WHITE);
rectangle(Box->left, Box->top, Box->right - 200, Box->bottom);
settextcolor(BLACK);
rectangle(Box->right - 200, Box->top, Box->right, Box->bottom);
settextcolor(BLACK);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box->left + 1, Box->top + 8, text);
}
//按钮2
void anniu2(int x1, int y1, int x2, int y2, const char* text, REC*& Box)
{
Box = new REC{ x1,y1,x2,y2 };
setbkcolor(WHITE);
rectangle(Box->left, Box->top, Box->right - 400, Box->bottom);
setbkcolor(WHITE);
rectangle(Box->right - 400, Box->top, Box->right - 200, Box->bottom);
setbkcolor(WHITE);
rectangle(Box->right - 200, Box->top, Box->right, Box->bottom);
settextcolor(BLACK);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box->left + 1, Box->top + 8, text);
}
//初始界面
void chushimian()
{
IMAGE img;
loadimage(&img, "back1.png", tulen, tude); // 替换 "back" 为你的图片文件路径
putimage(0, 0, &img);
rectangle(0, 0, 1300, 65);// 绘制矩形
settextstyle(50, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(450, 10, "学生成绩查询系统");//文字
char a[9][20] = { "校排名","1班排名" ,"2班排名" ,"查找成绩" ,"删除成绩" ,"修改成绩","增加学生","导入成绩","导出成绩" };
for (int i = 0; i < 9; i++)
{
rectangle(0, 65 * (i + 1), 100, 65 * (i + 2));// 绘制矩形
settextstyle(18, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(20, 65 * (i + 1) + 20, a[i]);
}//文字
rectangle(0, 65 * (9 + 1), 100, 700);// 绘制矩形
settextstyle(18, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(20, 65 * (9 + 1) + 20, "关闭");
}
//初始控制界面
int kongzhi()
{
int t = 0;
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
// 检测鼠标左键按下事件
POINT cursorPos;
GetCursorPos(&cursorPos);
for (int i = 1; i <= 9; i++)
if (cursorPos.x > 0 && cursorPos.x < 100 && cursorPos.y >65 * i && cursorPos.y < 65 * (i + 1)) {
if (i <= 9)
{
cout << i;
return i;
}
return 0;
}
}
if (_kbhit()) {
// 检测键盘按键事件
char key = _getch();
if (key == 27) { // 按下Esc键退出循环
break;
}
}
}
return t;
}
// 绘制按钮
int Button(int x1, int y1, int x2, int y2, const char* text, int keys) {
rectangle(x1, y1, x2, y2);
settextstyle(25, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(x1 + 5, y1 + 10, text);
int key = 0;
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
// 检测鼠标左键按下事件
POINT cursorPos;
GetCursorPos(&cursorPos);
int rr=xunhuan(cursorPos);
//cin >> key;
if (!rr)
return 0;
if (cursorPos.x > x1 && cursorPos.x < x2 && cursorPos.y >y1 && cursorPos.y < y2 || key == 123) {
key = 123;
cout << key;
return key;
}
//cout << key;
// Sleep(1);
}
}
return key;
}
//下一页
void drawPage(const char* text, int pageStartIndex, int pageLength, SqList*& L1)
{
// 清空窗口
cleardevice();
chushimian();
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(103, 70, text + pageStartIndex);
char gg[200];
sprintf(gg, "平均成绩%25.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf \n ", L1->averge[0] / (L1->length - L1->que[0]), L1->averge[1] / (L1->length - L1->que[1]), L1->averge[2] / (L1->length - L1->que[2]), L1->averge[3] / (L1->length - L1->que[3]), L1->averge[4] / (L1->length - L1->que[4]), L1->averge[5] / (L1->length - L1->que[5]));
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(103, 16 + 70, gg);
sprintf(gg, "最高成绩%26.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf \n ", L1->maxx[0], L1->maxx[1], L1->maxx[2], L1->maxx[3], L1->maxx[4], L1->maxx[5]);
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(103, 32 + 70, gg);// 绘制页码
sprintf(gg, "最低成绩% 25.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf % 6.1lf \n ", L1->minn[0], L1->minn[1], L1->minn[2], L1->minn[3], L1->minn[4], L1->minn[5]);
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(103, 16 + 32 + 70, gg);// 绘制页码
sprintf(gg, "不及格人数%20d%6d%6d%6d%6d%6d\n", L1->noo[0], L1->noo[1], L1->noo[2], L1->noo[3], L1->noo[4], L1->noo[5]);
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(103, 64 + 70, gg);// 绘制页码
settextcolor(BLACK);
char pageNumText[16];
sprintf_s(pageNumText, "Page: %d", (pageStartIndex / pageLength) + 1);
setbkmode(TRANSPARENT);
outtextxy(103, 680, pageNumText);
for (int j = 0, i = pageStartIndex * 32; i < (pageStartIndex + 1) * 32; i++, j++)
{
if (i == L1->length)
break;
char student[200];
sprintf(student, "%-17s%-10s%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6d%6d%6d%6d\n", L1->data[i].no, L1->data[i].name, L1->data[i].score[0], L1->data[i].score[1], L1->data[i].score[2], L1->data[i].score[3], L1->data[i].score[4], L1->data[i].score[5], L1->data[i].sum, L1->data[i].school_rank, L1->data[i].class_rank, L1->data[i].rises, L1->data[i].clas);
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(103, 16 * 4 + 85 + 16 * j, student);
}
}
//排名界面
void jiemian2(int x)
{
//const char* longText = "This is a long text. It can span across multiple pages in the graphics window. Press 'Enter' to go to the next page.";
char studentInfo[100];
sprintf(studentInfo, "%-17s%-10s%6s%6s%6s%6s%6s%6s%6s%8s%7s%7s%7s\n", "学号", "姓名", "数据结构", "高数", "英语", "线代", "思修", "体育", "总分", "校排名", "班排名", "上升名", "班级");
/*settextstyle(6, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(105, 70, studentInfo);*/
const char* longText = studentInfo;
int pageStartIndex = 0;
int pageLength = 1;
// outtextxy(103, 680, pageNumText);
while (true) {
drawPage(longText, pageStartIndex, pageLength, L[x]);
// 等待用户按下键盘事件
/*const int buttonX1 = 180;
const int buttonY1 = 670;
const int buttonX2 = 228;
const int buttonY2 = 695;
const char* buttonText = "下一页";*/
int key = 0;
key = Button(900, 630, 1000, 680, "下一页", 123);
if (key == 0)
return;
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(183, 680, "下一页按enter");
if (key == 123) { // 切换到下一页
pageStartIndex += pageLength;
if (pageStartIndex >= (L[x]->length + 31) / 32) {
pageStartIndex = 0; // 已经到达文本末尾,重新从第一页开始
}
}
//panduan();
}
}
// 模糊查找学生
void searchStudent1(SqList* list, const std::string& keyword)
{
int found = 0;
int x1 = 102, y1 = 180;
if (keyword.size() == 0)
{
printf("未找到符合条件的学生\n");
settextstyle(15, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(x1, y1, "未找到符合条件的学生\n");
return;
}
for (int i = 0; i < list->length; i++)
{
if (strstr(list->data[i].name, keyword.c_str()) != NULL || list->data[i].no == keyword)
{
found = 1;
char student[200];
sprintf(student, "%-17s%-10s%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6.1lf%6d%6d%6d%6d\n", list->data[i].no, list->data[i].name, list->data[i].score[0], list->data[i].score[1], list->data[i].score[2], list->data[i].score[3], list->data[i].score[4], list->data[i].score[5], list->data[i].sum, list->data[i].school_rank, list->data[i].class_rank, list->data[i].rises, list->data[i].clas);
settextstyle(15, 0, _T("宋体"));
setbkmode(WHITE);
settextcolor(BLUE);
outtextxy(x1, y1, student);
printf("学生姓名: %s\n", list->data[i].name);
printf("学号: %s\n", list->data[i].no);
printf("各科成绩:\n");
for (int j = 0; j < 6; j++)
{
printf("第%d门成绩: %.2f\n", j + 1, list->data[i].score[j]);
}
printf("总分: %.2f\n", list->data[i].sum);
printf("校排名: %d\n", list->data[i].school_rank);
printf("班排名: %d\n", list->data[i].class_rank);
printf("\n");
y1 += 16;
}
}
if (!found)
{
printf("未找到符合条件的学生\n");
settextstyle(15, 0, _T("宋体"));
setbkmode(WHITE);
settextcolor(BLUE);
outtextxy(x1, y1, "未找到符合条件的学生\n");
}
}
//按钮
char* Button1(int x1, int y1, int x2, int y2, const char* xx) {
rectangle(x1, y1, x2, y2);
rectangle(700, 120, 800, 170);
settextstyle(25, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(700 + 5, y1 + 10, xx);
static char aa[35]; // 使用静态数组
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
// 检测鼠标左键按下事件
POINT cursorPos;
GetCursorPos(&cursorPos);
int rr=xunhuan(cursorPos);
if (!rr)
return 0;
if (cursorPos.x > x1 && cursorPos.x < x2 && cursorPos.y >y1 && cursorPos.y < y2) {
std::cin >> aa;
settextstyle(25, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLACK);
outtextxy(x1 + 5, y1 + 10, aa);
return aa;
}
}
}
return aa;
}
//搜索界面
void sousuo()
{
chushimian();
char* aa = Button1(200, 120, 700, 170, "搜索");
if (aa == 0)
return;
int x1 = 700, y1 = 120, x2 = 780, y2 = 170;
// 创建搜索按钮
int key = 0;
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
// 检测鼠标左键按下事件
POINT cursorPos;
GetCursorPos(&cursorPos);
// cin >> key;
if (cursorPos.x > x1 && cursorPos.x < x2 + 100 && cursorPos.y >y1 - 20 && cursorPos.y < y2 + 20) {
key = 123;
printf("Input box selected.\n");
searchStudent1(L[5], aa);
cout << key;
}
xunhuan(cursorPos);
// Sleep(1);
}
}
}
//删除界面
void shanchu1()
{
chushimian();
char* aa = Button1(200, 120, 700, 170, "删除");
if (aa == 0)
return;
int x1 = 700, y1 = 120, x2 = 780, y2 = 170;
// 创建搜索按钮
int key = 0;
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
// 检测鼠标左键按下事件
POINT cursorPos;
GetCursorPos(&cursorPos);
// cin >> key;
if (cursorPos.x > x1 && cursorPos.x < x2 + 100 && cursorPos.y >y1 - 20 && cursorPos.y < y2 + 20) {
key = 123;
printf("已删除\n");
//searchStudent1(L1, inputText);
int tt = 0;
tt = deleteStudent(L[5], aa);
if (tt) {
settextstyle(25, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(340, 190, "已删除");
}
else
{
settextstyle(25, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(340, 190, "没有此学生");
}
cout << key;
xunhuan(cursorPos);
}
// Sleep(1);
}
}
}
//修改界面2
void change2(stud aa)
{
chushimian();
char b[6][15] = { "数据结构", "高数", "英语", "线代", "思修", "体育" };
char a[9][55];
settextcolor(BLACK);
settextstyle(35, 0, _T("宋体"));
outtextxy(240, 90, "将需要修改的内容重新输入到对于的输入框内");
int x1 = 160, x2 = 580, y1 = 130, y2 = 180, height = 50;
sprintf(a[0], "学号%s", aa.no);
sprintf(a[1], "名字%s", aa.name);
sprintf(a[8], "班级%d", aa.clas);
for (int i = 0; i < 6; i++)
{
sprintf(a[i + 2], "%s%.1lf", b[i], aa.score[i]);
}
REC* Box[10];
Box[9] = new REC{ 650,150,715,200 };
setbkcolor(WHITE);
rectangle(Box[9]->left, Box[9]->top, Box[9]->right, Box[9]->bottom);
settextcolor(RED);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[9]->left + 10, Box[9]->top + 8, "提交");
for (int i = 0; i < 9; i++)
{
anniu1(x1, y1, x2, y1 + height, a[i], Box[i]);
y1 += height + 10;
}
// 监听鼠标点击事件
MOUSEMSG m;
while (true)
{
m = GetMouseMsg();
int rr=xunhuan1(m);
if (!rr)
return;
// 确定当前活动的输入框
int activeInput = -1;
for (int i = 0; i <= 9; i++)
{
if (m.uMsg == WM_LBUTTONDOWN &&
m.x >= Box[i]->left && m.x <= Box[i]->right &&
m.y >= Box[i]->top && m.y <= Box[i]->bottom)
{
if (i < 2)
{
char chang[20];
cin >> chang;
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, chang);
if (i == 0)
strcpy(aa.no, chang);
else
strcpy(aa.name, chang);
cout << "成功";
}
else if (i < 9)
{
int scaress;
cin >> scaress;
char changes[20];
sprintf(changes, "%d", scaress);
cout << changes;
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, changes);
if (i >= 2 && i < 8)
{
aa.score[i - 2] = scaress;
}
else
aa.clas = scaress;
cout << "成功";
}
else
{
modifyScore(L[5], aa);
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[9]->left, Box[9]->top + 100, "修改成功");
cout << "修改成功";
return;
}
}
}
}
}
//修改界面1
void change()
{
chushimian();
char* aa = Button1(200, 120, 700, 170, "修改学生");
if (aa == 0)
return;
int x1 = 700, y1 = 120, x2 = 780, y2 = 170;
// 创建搜索按钮
int key = 0;
while (true) {
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
// 检测鼠标左键按下事件
POINT cursorPos;
GetCursorPos(&cursorPos);
int rr = xunhuan(cursorPos);
if (!rr)
return;
if (cursorPos.x > x1 && cursorPos.x < x2 + 100 && cursorPos.y >y1 - 20 && cursorPos.y < y2 + 20) {
key = 123; int flag = 0;
pair<bool, stud>tt;
tt = searc3(L[5], aa);
if (tt.first)
{
change2(tt.second);
flag = 1;
}
if (!flag)
{
settextstyle(25, 0, _T("宋体"));
setbkmode(TRANSPARENT);
settextcolor(BLUE);
outtextxy(340, 190, "没有此学生");
}
}
cout << key;
}
// Sleep(1);
}
}
//增加界面
void add()
{
stud aa;
chushimian();
char a[9][15] = { "学号","名字", "数据结构", "高数", "英语", "线代", "思修", "体育","班级" };
settextcolor(BLACK);
settextstyle(35, 0, _T("宋体"));
outtextxy(240, 90, "将需要补录学生的信息输入到对于的输入框内");
int x1 = 160, x2 = 580, y1 = 130, y2 = 180, height = 50;
REC* Box[10];
Box[9] = new REC{ 650,150,715,200 };
setbkcolor(WHITE);
rectangle(Box[9]->left, Box[9]->top, Box[9]->right, Box[9]->bottom);
settextcolor(RED);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[9]->left + 10, Box[9]->top + 8, "提交");
for (int i = 0; i < 9; i++)
{
anniu1(x1, y1, x2, y1 + height, a[i], Box[i]);
y1 += height + 10;
}
// 监听鼠标点击事件
MOUSEMSG m;
while (true)
{
m = GetMouseMsg();
int rr = xunhuan1(m);
if (!rr)
return;
// 确定当前活动的输入框
int activeInput = -1;
for (int i = 0; i <= 9; i++)
{
if (m.uMsg == WM_LBUTTONDOWN &&
m.x >= Box[i]->left-10 && m.x <= Box[i]->right+20 &&
m.y >= Box[i]->top && m.y <= Box[i]->bottom)
{
if (i < 2)
{
char chang[20];
cin >> chang;
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, chang);
if (i == 0)
strcpy(aa.no, chang);
else
strcpy(aa.name, chang);
cout << "成功";
}
else if (i < 9)
{
int scaress;
cin >> scaress;
char changes[20];
sprintf(changes, "%d", scaress);
cout << changes;
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, changes);
if (i >= 2 && i < 8)
{
aa.score[i - 2] = scaress;
}
else
aa.clas = scaress;
cout << "成功";
}
else
{
insertStudent(L[5], aa);
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[9]->left, Box[9]->top + 100, "增加成功");
cout << "增加成功";
}
xunhuan1(m);
}
}
}
}
//导入界面
void daoru1()
{
chushimian();
char a[6][30] = { "导入一班一次成绩", "导入一班二次成绩", "导入二班一次成绩", "导入二班二次成绩","导入学校一次成绩", "导入学校二次成绩" };
settextcolor(BLACK);
settextstyle(35, 0, _T("宋体"));
outtextxy(240, 90, "将需要导入的文件名输入到对于的输入框内");
int x1 = 240, x2 = 880, y1 = 130, y2 = 180, height = 50;
REC* Box[6];
for (int i = 0; i < 6; i++)
{
anniu2(x1, y1, x2, y1 + height, a[i], Box[i]);
y1 += height + 10;
}
// 监听鼠标点击事件
MOUSEMSG m;
while (true)
{
m = GetMouseMsg();
int rr = xunhuan1(m);
if (!rr)
return;
// 确定当前活动的输入框
int activeInput = -1;
for (int i = 0; i < 6; i++)
{
bool t = 0;
if (m.uMsg == WM_LBUTTONDOWN &&
m.x >= Box[i]->left && m.x <= Box[i]->right - 200 &&
m.y >= Box[i]->top && m.y <= Box[i]->bottom)
{
char chang[20];
cin >> chang;
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 398, Box[i]->top + 8, chang);
cout << chang;
InitList(L[i]);
CreateList(L[i], chang);
L[i]->chi = 2;
yuchuli(L[i]);
t = 1;
if (t)
{
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, "导入成功");
cout << 123;
}
else
{
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, "导入失败");
cout << 123;
}
}
}
}
}
//导出界面
void daochu()
{
chushimian();
char a[6][30] = { "导出一班一次成绩", "导出一班二次成绩", "导出二班一次成绩", "导出二班二次成绩","导出第一次校成绩","导出第二次校成绩" };
int x1 = 200, x2 = 780, y1 = 120, y2 = 170, height = 50;
REC* Box[6];
for (int i = 0; i < 6; i++)
{
anniu1(x1, y1, x2, y1 + height, a[i], Box[i]);
y1 += height + 10;
}
// 监听鼠标点击事件
MOUSEMSG m;
while (true)
{
m = GetMouseMsg();
int rr = xunhuan1(m);
if (!rr)
return;
// 确定当前活动的输入框
int activeInput = -1;
for (int i = 0; i < 6; i++)
{
if (m.uMsg == WM_LBUTTONDOWN &&
m.x >= Box[i]->left && m.x <= Box[i]->right &&
m.y >= Box[i]->top && m.y <= Box[i]->bottom)
{
settextcolor(BLUE);
settextstyle(25, 0, _T("宋体"));
outtextxy(Box[i]->right - 198, Box[i]->top + 8, "导出成功");
activeInput = i;
DispList(L[i], daochuming[i]);
break;
}
}
}
}
//初始化界面
void chushi()
{
initgraph(1300, 700); // 初始化图形窗口
int tt = 111;
chushimian();
tt = kongzhi();
//对应"校排名","1班排名" ,"2班排名" ,"查找成绩" ,"删除成绩" ,"修改成绩","增加学生","导入成绩","导出成绩"
if (tt == 1)
{
jiemian2(5);
}
else if (tt == 2)
{
jiemian2(1);
}
else if (tt == 3)
{
jiemian2(3);
}
else if (tt == 4)
{
sousuo();
}
else if (tt == 5)
{
shanchu1();
}
else if (tt == 6)
{
change();
}
else if (tt == 7)
{
add();
}
else if (tt == 8)
{
daoru1();
}
else if (tt == 9)
{
daochu();
}
else if (tt == 0)
closegraph(); // 关闭窗口
return;
}
int xunhuan(POINT cursorPos)
{
for (int i = 1; i <=10; i++)
if (cursorPos.x > 0 && cursorPos.x < 100 && cursorPos.y >65 * i && cursorPos.y < 65 * (i + 1)) {
if (i == 0)
{
closegraph();
return 0;
}
if (i == 1)
{
jiemian2(5);
return 0;
}
if (i == 2)
{
jiemian2(1);
return 0;
}
if (i == 3)
{
jiemian2(3);
return 0;
}
if (i == 4)
{
sousuo();
return 0;
}
if (i == 5)
{
shanchu1();
return 0;
}
if (i == 6)
{
change();
return 0;
}
if (i == 7)
{
add();
return 0;
}
if (i == 8)
{
daoru1();
return 0;
}
if (i == 9)
{
daochu();
return 0;
}
if (i == 10)
{
closegraph();
return 0;
}
}
return 1;
}
int xunhuan1(MOUSEMSG cursorPos)
{
for (int i = 1; i <= 9; i++)
if (cursorPos.uMsg == WM_LBUTTONDOWN && cursorPos.x > 0 && cursorPos.x < 100 && cursorPos.y >65 * i && cursorPos.y < 65 * (i + 1)) {
if (i == 0)
{
closegraph();
return 0;
}
if (i == 1)
{
jiemian2(5);
return 0;
}
if (i == 2)
{
jiemian2(1);
return 0;
}
if (i == 3)
{
jiemian2(3);
return 0;
}
if (i == 4)
{
sousuo();
return 0;
}
if (i == 5)
{
shanchu1();
return 0;
}
if (i == 6)
{
change();
return 0;
}
if (i == 7)
{
add();
return 0;
}
if (i == 8)
{
daoru1();
return 0;
}
if (i == 9)
{
daochu();
return 0;
}
}
return 1;
}
//录入成绩
void luru()
{
InitList(L[4]);
CreateList(L[4], "class1.txt");
L[4]->chi = 1;
yuchuli(L[4]);
InitList(L[5]);
CreateList(L[5], "class2.txt");
L[5]->chi = 2;
yuchuli(L[5]);
InitList(L[1]);
InitList(L[2]);
InitList(L[3]);
InitList(L[0]);
}
//预处理
void yu()
{
luru();
jinbu(L[4], L[5]);
int x = 0, y = 0;
for (int i = 0; i < L[4]->length; i++)
{
if (L[4]->data[i].clas == 0)
{
L[0]->data[x] = L[4]->data[i];
x++;
}
else
{
L[2]->data[y] = L[4]->data[i];
y++;
}
}
L[0]->length = x;
L[2]->length = y;
x = 0, y = 0;
for (int i = 0; i < L[5]->length; i++)
{
if (L[5]->data[i].clas == 0)
{
L[1]->data[x] = L[5]->data[i];
x++;
}
else
{
L[3]->data[y] = L[5]->data[i];
y++;
}
}
L[1]->length = x;
L[3]->length = y;
for (int i = 0; i < 6; i++)
{
if (i < 4)
Score(L[i]);
DispList(L[i], daochuming[i]);
}
}
cpp文件代码
#include"suan.h"
#include"jiemian.h"
#include<iostream>
using namespace std;
int main()
{
yu();
chushi();
return 0;
}
使用说明
1.使用的visual studio
2.easyx可以在代码巴士 - 分享有价值的 C/C++ 知识和源代码中一键下载
3.背景图像命名back1.png在chushihua函数中
4.成绩有六门,文件中文字按学号 名字 成绩的顺序
5.导入成绩没做完(真的不想改了)所以用yu的函数直接导入计算了(我用的是校成绩,文件命名class1.txt和class2.txt)
6.每个地方点击一次就可以了,如果点击两次你就会发现bug了
最后就是说缺点和遇到的问题了
作为一名c语言初学者,第一次写几百行的代码(最初只是想用好看的图片背景完成作业,结果写代码时遇到了许多问题,而且代码中还有许多问题未解决)。
1.用easyx图形库时发现看完文档后几乎不会写什么(后面直接用chatgpt查询,方便许多,但是还是出现许多报错如cpt给出函数库没有,给出的代码运行太慢点击了一分钟后才能反应)
2.开始写的函数,后面调用的时候发现调用困难了,难以运用(哭泣)
3.变量命名不规范和报错了