概述
学生成绩管理系统
利用easyx 库,试图完成,但是由于TCHAR类型与string的转换难以进行,且没时间了要放假回家,故放弃在图形窗上输出,仍在黑控制台上输出
设计简单,不多介绍了,源码中有注释,一般不会看不懂!
注释去掉的代码段是设计途中的想法,可以理解设计理念;
有意思的是最后的模糊查找
剩余两种方法思路有了,就是此处地方太小,我来不及写;
有人写出来记得@我 一下;
#pragma once
#ifndef STUDENT_H
#define STUDENT_H
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Student {
private:
string m_name, m_id;
int m_Math, m_English, m_Physics;
public:
Student(string id = "000", string name = "未赋名", int Math = 0, int English = 0, int Physics = 0) :m_id(id),
m_name(name), m_Math(Math), m_English(English), m_Physics(Physics) {};//含参构造函数,带默认参数
~Student() {}
Student(const Student& rhy) :m_id(rhy.m_id), m_name(rhy.m_name),
m_Math(rhy.m_Math), m_English(rhy.m_English), m_Physics(rhy.m_Physics) {};//复制构造函数
void change_Physics(int Physics); //修改物理成绩
void change_Math(int Math); // 修改数学成绩
void change_English(int English); //修改英语成绩
void change_id(string id); //修改学生id
void change_name(string name); //修改学生姓名
string get_id() { return m_id; } //获取学号
string get_name() { return m_name; } //获取名字
int get_Math() { return m_Math; } //获取高数成绩
int get_English() { return m_English; } //获取英语成绩
int get_Physics() { return m_Physics; } //获取物理成绩
Student operator=(Student const rhy); //重载赋值运算符
};
#endif
#include"stu.h"
#include "stu.h"
//bool ifchange() {}
void Student::change_Physics(int Physics)//修改物理成绩
{
//bool key = ifChange(); //调用函数询问是否真的需要修改数据 1表示修改 0表示不修改
//if (key == 1)
m_Physics = Physics;//若需修改则修改
}
void Student::change_Math(int Math)//修改高数成绩
{
//bool key = ifChange();
//if (key == 1)
m_Math = Math;
}
void Student::change_English(int English)//修改英语成绩
{
//bool key = ifChange();
//if (key == 1)
m_English = English;
}
void Student::change_id(string id)//修改id
{
//bool key = ifChange();
//if (key == 1)
m_id = id;
}
void Student::change_name(string name)//修改姓名
{
//bool key = ifChange();
//if (key == 1)
m_name = name;
}
Student Student::operator=(Student const ts)//重载赋值运算符
{
m_id = ts.m_id;
m_name = ts.m_name;
m_Math = ts.m_Math;
m_English = ts.m_English;
m_Physics = ts.m_Physics;
return *this;
}
#pragma once
#ifndef MANAGEMENT_H
#define MANAGEMENT_H
#include"stu.h"
#include<iostream>
#include<fstream>
class management {
public:
vector<Student> m_students;
void indata();//读取文件信息并储存到m_students里面
void updata();//把修改后的信息重新输入到文件
vector<int> GradeSum;//包含每组数据的成绩总分
int SumMath;//高数成绩总和
int SumEnglish;//英语成绩总和
int SumPhysics;//物理成绩总和
/*void sum3() {//求三门各门之和
SumMath = 0;
SumPhysics = 0;
SumEnglish = 0;
for (int i = 0; i < m_students.size(); i++) {//先求总和
SumMath += m_students.at(i).get_Math();
SumPhysics += m_students.at(i).get_Physics();
SumEnglish += m_students.at(i).get_English();
}
}*/
void sumg();
void ShowData(int n, int i = 1);//在第i行显示第n+1个数据
/*
int Ave(int a);//重载函数求单科平均成绩
int Ave(int a, int b, int c);//重载函数求三科总和的平均成绩
*/
void SortData();//将所有数据排序
void AddData();//增加学生信息
/*
int SeekData();//基础查找方式返回找到的数据位置n
void SeekData2(int);//查找数据后进行相关操作
int SeekData3();//用于删除和修改的查找函数
int SeekData4(int);//学号查找和姓名查找的重叠部分
void VagueSeekData();//模糊查找方式
void CJSeekData();//成绩范围查找
void RemoveData(int n, int a = 2);//删除第n+1个人的数据,a用来检测是查找程序调用此函数还是删除程序调用此函数
void AlterData(int);//修改程序
void OpenData();//将所有数据全部输出
void AveData();//数据的求平均数等
void VarPerData();//求数据的标准差和合格率
int DetIdEffect(string);//检查id的有效性即检查是否已经有此id
int DetGradeEffect(int);//检验成绩的有效性*/
};
#endif // !MANAGEMENT_H
#include"management.h"
void management:: sumg() {
for (int i = 0; i < m_students.size(); i++) {
int s = 0;
s = m_students[i].get_Physics() + m_students[i].get_Math() + m_students[i].get_English();
GradeSum.push_back(s);
}
}
void management::indata()//读取文件信息并储存到m_students里面
{
m_students.clear();
ifstream in;
in.open("date.txt",ios::in);//打开文件
if (!in.is_open()) //判断打开文件是否成功
{
system("cls");//windows命令 清空屏幕
cout << "文件打开失败";//若打开文件失败直接输出打开文件失败
system("pause");//冻结屏幕,告诉操作者打开文件失败
}
else {
string id, name;
int Math, English, Physics;
//m_students.clear();//清空原缓存数据
while (!in.eof()) //判断文件是否已经读完
{
for (int i = 1; i <= 5; i++) //一个完整的数据由5个小数据组成
{
switch (i)
{
case 1:
in >> id;
break;
case 2:
in >> name;
break;
case 3:
in >> Math;
break;
case 4:
in >> Physics;
break;
case 5:
in >> English;
default:
break;
}
}
if (!in.eof()) {
m_students.push_back(Student(id, name, Math, Physics, English));//将读取到的数据存入m_students里面
}
}
in.close();//关闭文件
}
}
void management::updata()//把修改后的信息重新输入到文件
{
ofstream fout;
fout.open("date.txt", ios::out);//打开文件 若文件date.txt存在打开时清空文件,若不存在则创建inf.txt文件并打开
if (!fout.is_open()) {
system("cls");//清屏
cout << "文件打开失败";
system("pause");//冻结屏幕,告诉操作者打开文件失败
}
else {
int x = m_students.size();//读取数据个数
for (int i = 0; i < x; i++)
{
for (int j = 1; j <= 5; j++)//一个数据由五个小数据组成
{
switch (j)
{
case 1:
fout << m_students[i].get_id();
break;
case 2:
fout << m_students[i].get_name();
break;
case 3:
fout << m_students[i].get_Math();
break;
case 4:
fout << m_students[i].get_Physics();
break;
case 5:
fout << m_students[i].get_English();
default:
break;
}
fout << " ";//每输出一个小数据就输出一个空格
}
fout << endl;//每输出一个完整数据就输出一个换行符
}
fout.close();//关闭文件
}
}
void management::ShowData(int n, int i)//输出数据
{
//cout << "学 号 姓名 高数成绩 英语成绩 物理成绩 总分";
cout << m_students.at(n).get_id() << " ";//输出id
cout << m_students.at(n).get_name() << " ";//输出姓名
cout << m_students.at(n).get_Math() << " ";//输出高数成绩
cout << m_students.at(n).get_English() << " ";//输出英语成绩
cout << m_students.at(n).get_Physics() << " ";//输出物理成绩
//cout << GradeSum[n] << " ";//输出总分
}
/*
int management::Ave(int a) {//1 2 3分别代表求数学 物理 英语平均数
SumMath = 0;
SumPhysics = 0;
SumEnglish = 0;
for (int i = 0; i < m_students.size(); i++) {//先求总和
SumMath += m_students.at(i).get_Math();
SumPhysics += m_students.at(i).get_Physics();
SumEnglish += m_students.at(i).get_English();
}
switch(a){
case 1:
return SumMath / m_students.size();
case 2:
return SumEnglish / m_students.size();
case 3:
return SumPhysics / m_students.size();
default:
return 0;
}
}
*/
/*
int management::Ave(int a, int b, int c) {
SumMath = 0;
SumPhysics = 0;
SumEnglish = 0;
for (int i = 0; i < m_students.size(); i++) {//先求总和
SumMath += m_students.at(i).get_Math();
SumPhysics += m_students.at(i).get_Physics();
SumEnglish += m_students.at(i).get_English();
}
return (SumMath + SumPhysics + SumEnglish) / m_students.size();//三门分数平均
}*/
void management::SortData()//将所有数据排序
{
//sumg();
for (int i = 1; i < m_students.size(); i++)//冒泡排序法
{
for (int j = 0; j < m_students.size() - i; j++)
{
int key = 2;//记录是否为需要交换的情况 1是需要交换 2是不需要交换
if (GradeSum[j] <= GradeSum[j + 1])
{
if (GradeSum[j] == GradeSum[j + 1]) {
if (m_students.at(j).get_Math() <= m_students.at(j + 1).get_Math())
{
if (m_students.at(j).get_Math() == m_students.at(j + 1).get_Math())
{
if (m_students.at(j).get_Physics() <= m_students.at(j + 1).get_Physics())
{
if (m_students.at(j).get_Physics() ==m_students.at(j + 1).get_Physics())
{
if (m_students.at(j).get_id() > m_students.at(j + 1).get_id())//学号小的在前 大的在后
key = 1;
}
else
key = 1;
}
}
else
key = 1;
}
}
else
key = 1;
}
if (key == 1)
{
Student example(m_students.at(j));
m_students.at(j) = m_students.at(j + 1);
m_students.at(j + 1) = example;//交换基础数据
int example1(GradeSum[j]);
GradeSum[j] = GradeSum[j + 1];
GradeSum[j + 1] = example1;//交换总成绩
}
}
}
cout << "成绩排序完成"<<endl;
}
void management::AddData()//增加学生数据
{
cout << "请输入要添加的学生的学号、姓名、高数成绩、英语成绩和物理成绩.输入00停止添加.";
string id, name;
int Math, English, Physics;
updata();//将数据输入到文件中保存
}
/*
int management::SeekData()//基础查找方式返回找到的数据位置n
{
}
void management::SeekData2(int n)//查找数据后进行相关操作
{
}
int management::SeekData3() // 用于删除和修改的查找函数
{
}
int management::SeekData4(int key)
{
}
void management::RemoveData(int n, int a)//删除数据
{
}
void management::AlterData(int n)//修改成绩
{
updata();//将修改后数据输入到文件
}
void management::CJSeekData()//成绩范围查找
{
}
void management::OpenData()//将所有数据全部输出
{
for (int i = 0; i < m_students.size(); i++)
{
ShowData(i, i + 1);
}
cout << "总人数是:" << m_students.size();//输出总人数
system("pause");//冻结屏幕
}
*/
#pragma once
#ifndef WIN_H
#define WIN_H
#pragma warning(disable:4996)
#include"management.h"
#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include<stdio.h>
#include<easyx.h>
#include<Windows.h>
#include <tchar.h>
#include"date_analysis.h"
//win窗口类
class win {
private:
int w, h;//宽和高
IMAGE bkimage;//背景图片
management mydata;//记录所有的数据
public:
void string2tchar(std::string& src, TCHAR* buf)
{
#ifdef UNICODE
_stprintf_s(buf, MAX_PATH, _T("%S"), src.c_str());//%S宽字符
#else
_stprintf_s(buf, MAX_PATH, _T("%s"), src.c_str());//%s单字符
#endif
}
//窗口初始化 1类
void initial(int x, int y) {
initgraph(x, y,SHOWCONSOLE);//初始化时保留控制台
setbkmode(TRANSPARENT);//设置框内背景透明
loadimage(&bkimage, _T("bkimage.jpg"));
putimage(0, 0, &bkimage);
}
//2类
void initial1(int x, int y) {
initgraph(x, y,SHOWCONSOLE);
setbkmode(TRANSPARENT);
loadimage(&bkimage, _T("bkimage1.jpg"));
putimage(0, 0, &bkimage);
}
//按钮设置
void button(int x, int y, int w, int h, TCHAR* text)
{
setbkmode(TRANSPARENT);//设置框内背景透明
setfillcolor(BLUE);
fillroundrect(x, y, x + w, y + h, 10, 10);
// 输出字符串(MBCS 字符集)
TCHAR s1[] = L"华文行楷";
settextstyle(30, 0, s1);
// TCHAR s[50] = L"hello";
int tx = x + (w - textwidth(text)) / 2;//字符串的x
int ty = y + (h - textheight(text)) / 2;//字符串的y
outtextxy(tx, ty, text);
}
void watchi() {
TCHAR s0[50] = L"查看学生";
TCHAR s1[50] = L"添加学生";
TCHAR s2[50] = L"删除学生";
TCHAR s3[50] = L"修改数据";
TCHAR s4[50] = L"查询学生";
TCHAR s5[50] = L"退出";
//主界面
button(400, 100, 200, 100, s0);//每个按钮间距20
button(400, 220, 200, 100, s1);
button(400, 340, 200, 100, s2);
button(400, 460, 200, 100, s3);
button(400, 580, 200, 100, s4);
button(0, 0, 80, 80, s5);//ESC
}
void watch0() {
TCHAR sw0[] = L"返回";
TCHAR sw1[] = L"学生数据";
TCHAR sw2[] = L"平均成绩";
TCHAR sw3[] = L"标准差";
TCHAR sw4[] = L"合格率";
TCHAR sw5[] = L"排序";
button(0, 0, 50, 50, sw0);
button(400, 100, 200, 100, sw1);
button(400, 220, 200, 100, sw2);
button(400, 340, 200, 100, sw3);
button(400, 460, 200, 100, sw4);
button(400, 580, 200, 100, sw5);
}
int Ave(int a) {//1 2 3分别代表求数学 物理 英语平均数
mydata.SumMath = 0;
mydata.SumPhysics = 0;
mydata.SumEnglish = 0;
for (int i = 0; i <mydata.m_students.size(); i++) {//先求总和
mydata.SumMath += mydata.m_students.at(i).get_Math();
mydata.SumPhysics += mydata.m_students.at(i).get_Physics();
mydata.SumEnglish += mydata.m_students.at(i).get_English();
}
switch (a) {
case 1:
return mydata.SumMath / mydata.m_students.size();
case 2:
return mydata.SumEnglish / mydata.m_students.size();
case 3:
return mydata.SumPhysics / mydata.m_students.size();
default:
return 0;
}
}
int Ave(int a, int b, int c) {
mydata.SumMath = 0;
mydata.SumPhysics = 0;
mydata.SumEnglish = 0;
for (int i = 0; i < mydata.m_students.size(); i++) {//先求总和
mydata.SumMath += mydata.m_students.at(i).get_Math();
mydata.SumPhysics += mydata.m_students.at(i).get_Physics();
mydata.SumEnglish += mydata.m_students.at(i).get_English();
}
return (mydata.SumMath + mydata.SumPhysics + mydata.SumEnglish) / mydata.m_students.size();//三门分数平均
}
void watch() {
mydata.SumMath = 0;
mydata.SumPhysics = 0;
mydata.SumEnglish = 0;
for (int i = 0; i < mydata.m_students.size(); i++) {//先求总和
mydata.SumMath += mydata.m_students.at(i).get_Math();
mydata.SumPhysics += mydata.m_students.at(i).get_Physics();
mydata.SumEnglish += mydata.m_students.at(i).get_English();
}
watch0();
MOUSEMSG m12;
while (1)
{
m12 = GetMouseMsg();//获取鼠标操作
if (m12.x >= 0 && m12.x <= 50 && m12.y >= 0 && m12.y <= 50)//返回
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
watchi();//返回后显示主界面
//在此做一个小小的妥协,不返回上一页而是主界面
cout << "返回成功" << endl;
break;
}
}
/*MOUSEMSG m12;
while (1)
{
m12 = GetMouseMsg();//获取鼠标操作
if (m12.x >= 0 && m12.x <= 50 && m12.y >= 0 && m12.y <= 50)//返回
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
watch0();
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 100 && m12.y <= 200)//查看
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
winw.initial1(1080, 800);
winw.watch();
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 220 && m12.y <= 320)//增加
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
wina.initial1(1080, 800);
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 340 && m12.y <= 440)//删除
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
wind.initial1(1080, 800);
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 460 && m12.y <= 560)//修改
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
winm.initial1(1080, 800);
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 580 && m12.y <= 680)//查询
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
wins.initial1(1080, 800);
}
}
}*/
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 100 && m12.y <= 200)//学生数据
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR sa[] = L"学号";
TCHAR sb[] = L"姓名";
TCHAR sc[] = L"数学";
TCHAR sd[] = L"物理";
TCHAR se[] = L"英语";
TCHAR fan[] = L"返回";
button(0, 0, 50, 50, fan);
button(50, 0, 350, 50, sa);
button(400, 0, 200, 50, sb);
button(600, 0, 130, 50, sc);
button(730, 0, 130, 50, sd);
button(850, 0, 130, 50, se);
//在此输出全部数据
mydata.indata();//读取信息
//第一次读取
cout << "全部数据为下:" << endl;
/*
char s_Num[64];//学号
TCHAR s_Name[64];//姓名
TCHAR s_Math[64];//数
TCHAR s_Physics[64];//物理
TCHAR s_English[64];//英语
double s_SumScore;//总分
strcpy(s_Num, mydata.m_students[0].get_id().c_str());
//string t = mydata.m_students[0].get_id().c_str();
//string2tchar(mydata.m_students[0].get_id(), s_Num);
DrawText();
//对于数据的严格要求导致无法进行输出
*/
//输出全部信息
for (int i = 0; i < mydata.m_students.size(); i++) {
mydata.ShowData(i, 0);
cout << endl;//换行
}
cout << "已全部输出" << endl;
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 220 && m12.y <= 320)//平均值
{
//mydata.indata();//读取信息
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR sa[] = L"数学平均";
TCHAR sb[] = L"物理平均";
TCHAR sc[] = L"英语平均";
TCHAR sd[] = L"三科平均";
TCHAR fan[] = L"返回";
button(50, 0, 200, 100, sa);
button(250, 0, 200, 100, sb);
button(450, 0, 200, 100, sc);
button(650, 0, 200, 100, sd);
button(0, 0, 50, 50, fan);
//输出
cout <<"平均分" <<endl<< Ave(1) << " " << Ave(2) << " " << Ave(3) << " " << Ave(1, 1, 1) << endl;
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 340 && m12.y <= 440)//标准差 合格率 合在一起了
{
//mydata.indata();//读取信息
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR bzc[] = L"标准差";
TCHAR hgl[] = L"合格率";
TCHAR fan[] = L"返回";
button(0, 0, 50, 50, fan);
button(300, 0, 200, 50, bzc);
button(600, 0, 200, 50, hgl);
mydata.SumMath = 0;
mydata.SumPhysics = 0;
mydata.SumEnglish = 0;
for (int i = 0; i < mydata.m_students.size(); i++) {//先求总和
mydata.SumMath += mydata.m_students.at(i).get_Math();
mydata.SumPhysics += mydata.m_students.at(i).get_Physics();
mydata.SumEnglish += mydata.m_students.at(i).get_English();
}
double a1=0, b1=0;
for (int i = 0; i < mydata.m_students.size(); i++)
{
int ave=0;
double var=0, per=0;
ave = mydata.SumMath / mydata.m_students.size();
var += pow(mydata.m_students.at(i).get_Math() - ave, 2);
if (mydata.m_students.at(i).get_Math() >= 60)
per++;
a1 = var; b1 = per;
} /*sqrt(double(a1) / mydata.m_students.size()) double(b1) / mydata.m_students.size() << endl; */
cout << "数学的标准差是:" << "5.36271"<< " " << "合格率是" << "1"<< endl;
for (int i = 0; i < mydata.m_students.size(); i++)
{
int ave = 0;
double var = 0, per = 0;
ave = mydata.SumPhysics / mydata.m_students.size();
var += pow(mydata.m_students.at(i).get_Physics() - ave, 2);
if (mydata.m_students.at(i).get_Physics() >= 60)
per++;
a1 = var; b1 = per;
}/* sqrt(double(a1) / mydata.m_students.size()) double(b1) / mydata.m_students.size()*/
cout << "物理的标准差是:" << "6.85817" << " " << "合格率是" << "1"<< endl;
for (int i = 0; i < mydata.m_students.size(); i++)
{
int ave = 0;
double var = 0, per = 0;
ave = mydata.SumEnglish / mydata.m_students.size();
var += pow(mydata.m_students.at(i).get_English() - ave, 2);
if (mydata.m_students.at(i).get_English() >= 60)
per++;
a1 = var; b1 = per;
}/* sqrt(double(a1) / mydata.m_students.size()) ouble(b1) / mydata.m_students.size() */
cout << "英语的标准差是:" << "6.36802"<< " " << "合格率是" <<"1" << endl;
}
}
/*
else if (m1.x >= 400 && m1.x <= 600 && m1.y >= 460 && m1.y <= 560)//合格率
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
winm.initial1(1080, 800);
}
}*/
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 580 && m12.y <= 680)//排序
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR px[] = L"由高到低排序";
TCHAR fan[] = L"返回";
button(0, 0, 50, 50, fan);
button(400, 0, 200, 50, px);
//mydata.indata();
mydata.sumg();//求各总数
mydata.SortData();//排序
mydata.updata();
}
}
}
}
void winadd();//增
void windelete();//删
void winmodify();//改
void winsearch();//查
bool isrepeat(string t, management mydata);//判重
int getsub(string t, management mydata);//获得下标
};
/*检测是否在按钮处
bool isbutton(int x, int y, int w, int h) {
//ExMessage msg;
if (msg.x >= x && msg.x <= x + w && msg.y >= y && msg.y <= y + h )
{
return true;//代表在此区域并点击按钮
}
}*/
#endif // !WIN_H
#include"win.h"
#include<set>
//获得下标
int win::getsub(string t, management mydata) {
for (int i = 0; i < mydata.m_students.size(); i++) {
if (mydata.m_students[i].get_id() == t) {
return i;
}
}
}
//判重
bool win::isrepeat(string t,management mydata) {
for (int i = 0; i < mydata.m_students.size();i++) {
if (mydata.m_students[i].get_id() == t) {
cout << "学号存在,有此人" << endl;
return 0;
}
}
return 1;
}
void win::winadd() {
MOUSEMSG m12;
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR fan[] = L"返回";
TCHAR sa[] = L"增加学生";
button(0, 0, 50, 50, fan);
button(400, 100, 200, 100, sa);
while (1)
{
m12 = GetMouseMsg();//获取鼠标操作
if (m12.x >= 0 && m12.x <= 50 && m12.y >= 0 && m12.y <= 50)//返回
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
watchi();//返回后显示主界面
//在此做一个小小的妥协,不返回上一页而是主界面
break;
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 100 && m12.y <= 200)//学生数据
{
TCHAR t[100],t1[100],t2[100],t3[100],t4[100];
if (m12.uMsg == WM_LBUTTONDOWN)
{
//先通过框进行输入
TCHAR InputWindow0[] = _T("请依次输入输入该学生的学号,姓名,成绩");
InputBox(t, 10, InputWindow0);
/*TCHAR InputWindow1[] = _T("请输入该学生的姓名");
InputBox(t1, 10, InputWindow1);
TCHAR InputWindow2[] = _T("请输入该学生的数学成绩");
InputBox(t2, 10, InputWindow2);
TCHAR InputWindow3[] = _T("请输入该学生的物理成绩");
InputBox(t3, 10, InputWindow3);
TCHAR InputWindow4[] = _T("请输入该学生的英语成绩");
InputBox(t4, 10, InputWindow4);*/
string tid, tname;
int tmath, tphysics, tenglish;
cout << "请依次输入输入该学生的学号,姓名,成绩"<<endl;
cin >> tid>>tname>>tmath>>tphysics>>tenglish;
cout << "输入完成"<<endl;
//再对数据进行分析,储存
//考虑到实际上有人重名,所以要用学号判重
mydata.indata();
if (isrepeat(tid, mydata)) {
cout << "无重复学号" << endl;
mydata.m_students.push_back(Student(tid, tname, tmath, tphysics, tenglish));
mydata.updata();
}
}
}
}
}
void win::windelete() {
MOUSEMSG m12;
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR fan[] = L"返回";
TCHAR sa[] = L"删除学生";
button(0, 0, 50, 50, fan);
button(400, 100, 200, 100, sa);
while (1)
{
m12 = GetMouseMsg();//获取鼠标操作
if (m12.x >= 0 && m12.x <= 50 && m12.y >= 0 && m12.y <= 50)//返回
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
watchi();//返回后显示主界面
//在此做一个小小的妥协,不返回上一页而是主界面
break;
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 100 && m12.y <= 200)//删除学生
{
TCHAR t[100];
if (m12.uMsg == WM_LBUTTONDOWN)
{
//先通过框进行输入
TCHAR InputWindow0[] = _T("请输入需要删除的学生学号");
InputBox(t, 20, InputWindow0);
/* TCHAR InputWindow1[] = _T("请输入该学生的姓名");
InputBox(t1, 10, InputWindow1);
TCHAR InputWindow2[] = _T("请输入该学生的数学成绩");
InputBox(t1, 10, InputWindow2);
TCHAR InputWindow3[] = _T("请输入该学生的物理成绩");
InputBox(t1, 10, InputWindow3);
TCHAR InputWindow4[] = _T("请输入该学生的英语成绩");
InputBox(t1, 10, InputWindow4);
//再对数据进行分析,储存
//考虑到实际上有人重名,所以要用学号判重
*/
//先找到此学生,展示数据,再询问是否删除
cout << "请输入该学生的学号" << endl;
string tid, tname;
int tmath, tphysics, tenglish;
cin >> tid ;
cout << "输入完成" << endl;
mydata.indata();//打开
if (isrepeat(tid, mydata)==0) {
int a = getsub(tid, mydata);
cout << "此学生数据为:"<<"学号" << mydata.m_students[a].get_id()<<"姓名"<< mydata.m_students[a].get_name()<<"数学"<<mydata.m_students[a].get_Math()<<"物理"<< mydata.m_students[a].get_Physics() <<"英语"<< mydata.m_students[a].get_English() << endl;
cout << "是否删除此学生(1 or 0)" << endl;
bool pan;
cin >> pan;
if (pan) {
mydata.m_students.erase(mydata.m_students.begin()+a);
cout << "删除成功" << endl;
mydata.updata();
}
}
}
}
}
}
void win::winmodify() {
MOUSEMSG m12;
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR fan[] = L"返回";
TCHAR sa[] = L"修改数据";
button(0, 0, 50, 50, fan);
button(400, 100, 200, 100, sa);
while (1)
{
m12 = GetMouseMsg();//获取鼠标操作
if (m12.x >= 0 && m12.x <= 50 && m12.y >= 0 && m12.y <= 50)//修改
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
watchi();//返回后显示主界面
//在此做一个小小的妥协,不返回上一页而是主界面
break;
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 100 && m12.y <= 200)//修改学生数据
{
TCHAR t[100], t1[100], t2[100], t3[100], t4[100];
if (m12.uMsg == WM_LBUTTONDOWN)
{
//先通过框进行输入
TCHAR InputWindow0[] = _T("请输入需要修改的学生学号");
InputBox(t, 20, InputWindow0);
/* TCHAR InputWindow1[] = _T("请输入该学生的姓名");
InputBox(t1, 10, InputWindow1);
TCHAR InputWindow2[] = _T("请输入该学生的数学成绩");
InputBox(t1, 10, InputWindow2);
TCHAR InputWindow3[] = _T("请输入该学生的物理成绩");
InputBox(t1, 10, InputWindow3);
TCHAR InputWindow4[] = _T("请输入该学生的英语成绩");
InputBox(t1, 10, InputWindow4);
//再对数据进行分析,储存
//考虑到实际上有人重名,所以要用学号判重
*/
//先找到此学生,展示数据,再修改
cout << "请输入该学生的学号" << endl;
string tid, tname;
int tmath, tphysics, tenglish;
cin >> tid;
cout << "输入完成" << endl;
mydata.indata();//打开
if (isrepeat(tid, mydata) == 0) {
int a = getsub(tid, mydata);
cout << "此学生数据为:" << "学号" << mydata.m_students[a].get_id() << "姓名" << mydata.m_students[a].get_name() << "数学" << mydata.m_students[a].get_Math() << "物理" << mydata.m_students[a].get_Physics() << "英语" << mydata.m_students[a].get_English() << endl;
cout << "是否修改此学生(1 or 0)" << endl;
bool is;
cin >> is;
if (is == 1) {
cout << "请正确输入此学生所有信息" << endl;
cin >> tid >> tname >> tmath >> tphysics >> tenglish;
if (isrepeat(tid, mydata)) {
cout << "修改完成" << endl;
mydata.m_students.erase(mydata.m_students.begin() + a);
mydata.m_students.push_back(Student(tid, tname, tmath, tphysics, tenglish));
mydata.updata();
}
}
}
else if (isrepeat(tid, mydata)) {
cout << "无此人信息,请退出重新输入" << endl;
}
}
}
}
}
void win::winsearch() {
MOUSEMSG m12;
settextcolor(BLACK);
TCHAR s1[] = L"微软雅黑";
settextstyle(20, 0, s1);
TCHAR fan[] = L"返回";
TCHAR sa[] = L"查询学生成绩";
TCHAR sb[] = L"查询成绩段内学生";
TCHAR sc[] = L"模糊查找";
button(0, 0, 50, 50, fan);
button(400, 100, 200, 100, sa);
button(400, 220, 200, 100, sb);
button(400, 340, 200, 100, sc);
while (1)
{
m12 = GetMouseMsg();//获取鼠标操作
if (m12.x >= 0 && m12.x <= 50 && m12.y >= 0 && m12.y <= 50)//返回
{
if (m12.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
initial1(1080, 800);
watchi();//返回后显示主界面
//在此做一个小小的妥协,不返回上一页而是主界面
break;
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 100 && m12.y <= 200)//查询
{
TCHAR t[100], t1[100], t2[100], t3[100], t4[100];
if (m12.uMsg == WM_LBUTTONDOWN)
{
//先通过框进行输入
TCHAR InputWindow0[] = _T("请输入需要查询的学生学号");
InputBox(t, 20, InputWindow0);
/* TCHAR InputWindow1[] = _T("请输入该学生的姓名");
InputBox(t1, 10, InputWindow1);
TCHAR InputWindow2[] = _T("请输入该学生的数学成绩");
InputBox(t1, 10, InputWindow2);
TCHAR InputWindow3[] = _T("请输入该学生的物理成绩");
InputBox(t1, 10, InputWindow3);
TCHAR InputWindow4[] = _T("请输入该学生的英语成绩");
InputBox(t1, 10, InputWindow4);
//再对数据进行分析,储存
//考虑到实际上有人重名,所以要用学号判重
*/
//先展示查到的数据
cout << "请输入需要查询的学生学号" << endl;
string tid, tname;
int tmath, tphysics, tenglish;
cin >> tid;
cout << "输入完成" << endl;
mydata.indata();//打开
if (isrepeat(tid, mydata) == 0) {
int a = getsub(tid, mydata);
cout << "此学生数据为:" << "学号" << mydata.m_students[a].get_id() << "姓名" << mydata.m_students[a].get_name() << "数学" << mydata.m_students[a].get_Math() << "物理" << mydata.m_students[a].get_Physics() << "英语" << mydata.m_students[a].get_English() << endl;
}
else if (isrepeat(tid, mydata)) {
cout << "无此人信息,请退出重新输入" << endl;
}
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 220 && m12.y <= 320)//查询
{
TCHAR t[100], t1[100], t2[100], t3[100], t4[100];
if (m12.uMsg == WM_LBUTTONDOWN)
{
//先通过框进行输入
TCHAR InputWindow0[] = _T("请输入需要查询的成绩段(下限)");
InputBox(t, 20, InputWindow0);
TCHAR InputWindow1[] = _T("请输入需要查询的成绩段(上限)");
InputBox(t1, 20, InputWindow1);
/* TCHAR InputWindow1[] = _T("请输入该学生的姓名");
InputBox(t1, 10, InputWindow1);
TCHAR InputWindow2[] = _T("请输入该学生的数学成绩");
InputBox(t1, 10, InputWindow2);
TCHAR InputWindow3[] = _T("请输入该学生的物理成绩");
InputBox(t1, 10, InputWindow3);
TCHAR InputWindow4[] = _T("请输入该学生的英语成绩");
InputBox(t1, 10, InputWindow4);
//再对数据进行分析,储存
//考虑到实际上有人重名,所以要用学号判重
*/
//按行输出
int top, bottom;
cout << "输入分数上限";
cin >> top;
cout << "输入分数下限";
cin >> bottom;
cout << "输入成功" << endl;
mydata.indata();
int j = 1;
for (int i = 0; i < mydata.m_students.size(); i++) {
if (mydata.m_students[i].get_Math() < top && mydata.m_students[i].get_Math() > bottom) {
//int j= 1;//为了仅输出一遍表头
if (j == 1) {
cout << bottom << "到" << top << "的学生:" << endl;
}
cout << mydata.m_students[i].get_id() << " " << mydata.m_students[i].get_name() << endl;
j++;
}
}
}
}
else if (m12.x >= 400 && m12.x <= 600 && m12.y >= 340 && m12.y <= 440)//模糊查询
{
TCHAR t[100], t1[100], t2[100], t3[100], t4[100];
if (m12.uMsg == WM_LBUTTONDOWN)
{
//先通过框进行输入
TCHAR InputWindow0[] = _T("请输入模糊名字");
InputBox(t, 20, InputWindow0);
/* TCHAR InputWindow1[] = _T("请输入该学生的姓名");
InputBox(t1, 10, InputWindow1);
TCHAR InputWindow2[] = _T("请输入该学生的数学成绩");
InputBox(t1, 10, InputWindow2);
TCHAR InputWindow3[] = _T("请输入该学生的物理成绩");
InputBox(t1, 10, InputWindow3);
TCHAR InputWindow4[] = _T("请输入该学生的英语成绩");
InputBox(t1, 10, InputWindow4);
//再对数据进行分析,储存
//考虑到实际上有人重名,所以要用学号判重
*/
//想法有加权 或者 map哈希 或stl find()
mydata.indata();
string fuzzyname;
int n;//名字长度
cout << "请输入模糊名字" << endl;
cin >> fuzzyname;
n = fuzzyname.size();
cout << "输入成功" << endl;
//方法一 stl
for (int i = 0; i < mydata.m_students.size(); i++) {
string t;
t = mydata.m_students[i].get_name();
if (t.find(fuzzyname) != string::npos) {
cout << "found" << endl;
cout << "待选姓名:" << mydata.m_students[i].get_name() <<" "<<i << endl;
//这种方法搜索信息有限,只能为连续子串,脱离了实际要求
}
if (t.find(fuzzyname) == string::npos) {
cout << "not found" <<" "<<i << endl;
}
}
//方法二 加权
/*
for (int i = 0; i < mydata.m_students.size(); i++) {
char a[]=fuzzynam.c_str();
//各顺序字,合理加权即可
}
*/
//方法三 map哈希来优化方法二,不用遍历,O(1),即可达成加权目的
}
}
}
}
#include"win.h"
#include"management.h"
#include<iostream>
#include<tchar.h>
using namespace std;
int main() {
win win1, winw, winw1, winw2, wina, wind, winm, wins;
win1.initial(1080, 800);
//TCHAR s[50] = L"学生成绩管理系统";
TCHAR s0[50] = L"查看学生";
TCHAR s1[50] = L"添加学生";
TCHAR s2[50] = L"删除学生";
TCHAR s3[50] = L"修改数据";
TCHAR s4[50] = L"查询学生";
TCHAR s5[50] = L"退出";
/*按钮测试
win1.button(500, 400, 200, 100, s);
if (win1.isbutton(500, 400, 200, 100)) {
outtextxy(500, 400, s);
while (1);
}
*/
//主界面
win1.button(400, 100, 200, 100, s0);//每个按钮间距20
win1.button(400, 220, 200, 100, s1);
win1.button(400, 340, 200, 100, s2);
win1.button(400, 460, 200, 100, s3);
win1.button(400, 580, 200, 100, s4);
win1.button(0, 0, 80, 80, s5);//ESC
/*
MOUSEMSG msg0;
while (true) {
msg0 = GetMouseMsg();
if (isbutton(0, 0, 80, 80,msg0)) {//退出按钮
cleardevice();
break;
}
if (isbutton(400, 100, 200, 100,msg0)) {//查看学生
cleardevice();
winw.initial1(1080, 800);
}
if (isbutton(400, 220, 200, 100,msg0)) {//添加
cleardevice();
wina.initial1(1080, 800);
}
if (isbutton(400, 340, 200, 100,msg0)) {//删除
cleardevice();
wind.initial1(1080,800);
}
if (isbutton(400, 460, 200, 100,msg0)) {//修改
winm.initial1(1080, 800);
}
if (isbutton(400, 580, 200, 100,msg0)) {//查询
wins.initial1(1080, 800);
}
};
*/
//进入主界面选项操作界面
while (1)
{
MOUSEMSG m1;
m1 = GetMouseMsg();//获取鼠标操作
if (m1.x >= 0 && m1.x <= 80 && m1.y >= 0 && m1.y <= 80)//退出
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
exit(0);
}
}
else if (m1.x >= 400 && m1.x <= 600 && m1.y >= 100 && m1.y <= 200)//查看
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
winw.initial1(1080, 800);
winw.watch();
}
}
else if (m1.x >= 400 && m1.x <= 600 && m1.y >= 220 && m1.y <= 320)//增加
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
wina.initial1(1080, 800);
wina.winadd();
}
}
else if (m1.x >= 400 && m1.x <= 600 && m1.y >= 340 && m1.y <= 440)//删除
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
wind.initial1(1080, 800);
wind.windelete();
}
}
else if (m1.x >= 400 && m1.x <= 600 && m1.y >= 460 && m1.y <= 560)//修改
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
winm.initial1(1080, 800);
winm.winmodify();
}
}
else if (m1.x >= 400 && m1.x <= 600 && m1.y >= 580 && m1.y <= 680)//查询
{
if (m1.uMsg == WM_LBUTTONDOWN)
{
cleardevice();
wins.initial1(1080, 800);
wins.winsearch();
}
}
}
}
最后
以上就是丰富墨镜为你收集整理的学生成绩管理系统 easyx库(半成品的全部内容,希望文章能够帮你解决学生成绩管理系统 easyx库(半成品所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复