成绩查询系统(未完成版)
//
// code by : yizimi 远欣
//
// 不知道该瞎打什么,就写一个无聊的成绩查询吧
//
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <windows.h>
#include <conio.h>
#include <algorithm>
#include <fstream>
using namespace std;
struct score {
int Math, Chinese, Endlish, C_PlusPlus, Python, Java;
int sum;
inline void get_sum() {
sum = Math + Chinese + Endlish + C_PlusPlus + Python + Java;
}
score(int _m = 0, int _c = 0, int _e = 0, int _c_ = 0, int _p = 0, int _j = 0, int _sum = 0)
: Math(_m), Chinese(_c), Endlish(_e), C_PlusPlus(_c_), Python(_p), Java(_j), sum(_sum) {}
};
struct student {
score sc;
char name[20];
int rank;
int num; // 编号
void put_info() {
printf(" %4d : ", num);
for(int i = 0; i <= 5; i++) {
if(name[i] == 0) putchar(' ');
else putchar(name[i]);
}
printf(" %3d %3d %3d %3d %3d %3d %3d %4d\n", rank, sc.Chinese,
sc.Math, sc.Endlish, sc.C_PlusPlus, sc.Python, sc.Java, sc.sum);
}
student(score _sc = score(), int _rank = 0, int _num = 0)
: sc(_sc), rank(_rank), num(_num) {
for(int i = 0; i <= 5; ++i)
name[i] = 0;
}
} stu[100010];
inline bool cmp1(student a, student b) {
if(a.num == 0) return false;
if(b.num == 0) return true;
return a.sc.sum > b.sc.sum;
}
inline bool cmp2(student a, student b) {
if(a.num == 0) return false;
if(b.num == 0) return true;
return a.num < b.num;
}
int stu_cnt;
inline void sputs(string a) {
int total = a.size();
for(int i = 0; i <= total - 1; ++i)
putchar(a[i]), Sleep(40);
putchar('\n');
}
#define clr system("cls")
#define pus system("pause")
#define nxl puts("")
inline void start_words(void);
inline void menu(void);
inline void end_words(void);
inline void use_menu(void);
inline int rejudge_out(void);
inline void add_student(void);
inline void about_words(void);
inline void quick_about(void);
inline void slow_about(void);
inline void debug(void);
inline void help_words(void);
inline void help_home(void);
inline void help_use(void);
inline void debug_plus(void);
inline void query_student(void);
inline void update_rank(void);
inline void save_document(void);
inline void read_document(void);
inline void start_words() {
clr;
puts("+--------------------------------------------------------------------+");
puts("| |");
puts("| |");
puts("| 欢迎使用yizimi成绩统计程序 |");
puts("| |");
puts("| |");
puts("| |");
puts("| 1. 开始使用 2. 关于 |");
puts("| 3. 帮助 4. 退出 |");
puts("| |");
puts("| |");
puts("+--------------------------------------------------------------------+");
}
inline void end_words() {
clr;
nxl; nxl; nxl; nxl; nxl;
sputs(" 欢迎您下次使用!!~QwQ~ ");
nxl; nxl; nxl; nxl; nxl;
}
inline void about_words() {
clr;
nxl; nxl; nxl; nxl; nxl;
puts(" 快速版?or 慢速版?");
puts(" 1. quick! 2.slow...");
printf(" ");
int chs = getch() - '0';
if(chs == 1) quick_about();
else slow_about();
nxl;
puts(" 按任意字符键返回QwQ");
getch();
}
inline void help_words() {
int chs = 0;
while(chs != 3) {
clr; nxl; nxl; nxl; nxl; nxl;
puts(" 帮助:");
puts(" 欢迎使用yizimiの软件");
puts(" 1. 主页命令");
puts(" 2. 使用界面命令");
puts(" 3. 退出");
chs = getch() - '0';
if(chs == 1) {
help_home();
continue;
} else if(chs == 2) {
help_use();
continue;
}
}
}
inline void quick_about() {
clr;
nxl; nxl; nxl; nxl; nxl;
puts(" 制作者:yizimi远欣");
puts(" 监制 :yizimi远樱");
puts(" 版本号:0.0.0.1 ");
puts(" latest update:2018:12:25");
}
inline void slow_about() {
#define puts sputs
clr;
nxl; nxl; nxl; nxl; nxl;
puts(" 制作者:yizimi远欣");
puts(" 监制 :yizimi远樱");
puts(" 版本号:0.0.0.1 ");
puts(" latest update:2018:12:25");
#undef puts
}
inline void help_home() {
clr;
nxl; nxl; nxl; nxl; nxl;
puts(" 主页命令:");
nxl;
puts(" '1' : 进入‘使用’界面");
puts(" '2' : 进入‘关于’界面");
puts(" '3' : 进入‘帮助’界面");
puts(" '4' : 进入退出界面");
nxl;
puts(" 按任意键回到上一级");
getch();
return ;
}
inline void help_use() {
clr;
nxl; nxl; nxl; nxl; nxl;
puts(" 使用界面命令");
nxl;
puts(" 'I':插入/修改学生的成绩信息");
puts(" 'Q':快速查询某编号学生的成绩");
puts(" 'U':根据总成绩排序");
puts(" 'N':根据原编号排序");
puts(" 'D':删除学生信息");
puts(" 'S':保存到存档中");
puts(" 'R':读取存档中的成绩");
puts(" 'H':查看指令");
nxl;
puts(" 按任意键回到上一级");
getch();
return ;
}
inline void update_rank() {
sort(stu + 1, stu + 100000 + 1, cmp1);
for(int i = 1; i <= stu_cnt; i++)
stu[i].rank = i;
sort(stu + 1, stu + 100000 + 1, cmp2);
}
inline void update_sort_sum() {
sort(stu + 1, stu + 100000 + 1, cmp1);
}
inline void update_sort_num() {
sort(stu + 1, stu + 100000 + 1, cmp2);
for(int i = 1; i <= 100000; ++i)
stu[i].num = i;
}
inline void add_student() {
clr;
nxl; nxl; nxl; nxl;
int num, _ma, _ch, _en, _cp, _ja, _py;
char _na[20];
printf(" 请输入学生编号(有重复则覆盖之前的成绩)");
scanf("%d", &num);
printf(" 学生姓名:");
scanf("%s", _na);
puts(" 请输入各科成绩:");
printf(" 语文: ");
scanf("%d", &_ch);
printf(" 数学: ");
scanf("%d", &_ma);
printf(" 英语: ");
scanf("%d", &_en);
printf(" C++ : ");
scanf("%d", &_cp);
printf(" Java: ");
scanf("%d", &_ja);
printf(" Python:");
scanf("%d", &_py);
nxl;
puts(" 确认加入?");
puts(" 1. 是 2. 否");
nxl;
int chs = getch() - '0';
if(chs == 1) {
if(stu[num].num == 0)
stu_cnt++;
stu[num].num = num;
for(int i = 0; i <= strlen(_na) - 1; ++i)
stu[num].name[i] = _na[i];
for(int i = strlen(_na); i <= 5; ++i)
stu[num].name[i] = 0;
stu[num].sc = score(_ma, _ch, _en, _cp, _py, _ja, 0);
stu[num].sc.get_sum();
// stu[num].put_info();
update_rank();
}
return ;
}
inline void query_student(int _num) {
system("cls");
nxl; nxl; nxl; nxl; nxl;
if(stu[_num].num != _num)
puts(" 查无此人QwQ……"),
puts(" 请按任意字符键继续");
else {
puts(" 编号 姓名 排名 语文 数学 英语 C++ Python Java 总分");
stu[_num].put_info();
puts(" 请按任意字符键继续");
}
getch();
return ;
}
inline void del_student(int _num) {
stu[_num] = student();
stu[_num].rank = 0;
stu[_num].num = 0;
for(int i = 0; i <= 5; ++i) {
stu[_num].name[i] = 0;
}
stu[_num].sc = score();
stu_cnt--;
update_rank();
}
inline void save_document() {
fstream f("data.txt", ios::out);
f << stu_cnt << "\n";
for(int i = 1; i <= 100000; ++i) {
if(stu[i].num == i) {
f << stu[i].num << " ";
for(int j = 0; j <= 5; j++) {
if(stu[i].name[j] == 0) f << ' ';
else f << stu[i].name[j];
}
f << " " << stu[i].rank << " " << stu[i].sc.Chinese << " " << stu[i].sc.Math;
f << " " << stu[i].sc.Endlish << " " << stu[i].sc.C_PlusPlus << " " << stu[i].sc.Python;
f << " " << stu[i].sc.Java << " " << stu[i].sc.sum << "\n";
// printf(" %3d %3d %3d %3d %3d %3d %3d %4d\n", rank, sc.Chinese,
// sc.Math, sc.Endlish, sc.C_PlusPlus, sc.Python, sc.Java, sc.sum);
}
}
f.close();
}
inline void read_document() {
freopen("data.txt", "r", stdin);
cin >> stu_cnt;
for(int i = 1; i <= stu_cnt; ++i) {
cin >> stu[i].num;
getchar();
for(int j = 0; j <= 5; ++j)
stu[i].name[j] = getchar();
cin >> stu[i].rank >> stu[i].sc.Chinese >> stu[i].sc.Math;
cin >> stu[i].sc.Endlish >> stu[i].sc.C_PlusPlus >> stu[i].sc.Python;
cin >> stu[i].sc.Java >> stu[i].sc.sum;
}
fclose(stdin);
freopen("CON", "r", stdin);
}
inline void use_menu() {
char choose = 0;
int change_page = 1;
bool num_sum = 0;
// debug_plus();
while(choose != 'T') {
if(num_sum == 0) update_sort_num();
else update_sort_sum();
clr;
nxl; nxl; nxl;
puts(" 成绩单");
printf(" 学生总数:%d, page : %d\n", stu_cnt, change_page);
if(num_sum == 0) puts(" 按编号排序:");
else puts(" 按成绩排序");
nxl;
puts(" 编号 姓名 排名 语文 数学 英语 C++ Python Java 总分");
if(stu_cnt == 0)
puts(" 还没有加入任何一个学生的成绩哦QAQ");
for(int i = 20 * (change_page - 1) + 1; i <= 20 * (change_page); ++i) {
if(stu[i].num != 0)
stu[i].put_info();
}
nxl;
printf(" page : %d\n", change_page);
nxl; nxl;
choose = getch();
if(choose == 'C') {
puts(" 跳转:跳到哪页呢?\n");
int _get_page;
scanf("%d", &_get_page);
change_page = _get_page;
continue;
} else if(choose == 'I') {
add_student();
continue;
} else if(choose == 'Q') {
int query_num = 0;
puts(" 查询:(请输入学生编号)");
printf(" ");
scanf("%d", &query_num);
query_student(query_num);
continue;
} else if(choose == 'U') {
update_sort_sum();
num_sum = 1;
continue;
} else if(choose == 'N') {
update_sort_num();
num_sum = 0;
continue;
} else if(choose == 'D') {
nxl;
puts(" 请问要删除哪位学生的信息?(输入学生编号)");
puts(" 注意!删除后其原编号以后的学生,编号都将会有改动!");
printf(" ");
int query_num = 0;
scanf("%d", &query_num);
if(stu[query_num].num == query_num)
del_student(query_num);
continue;
} else if(choose == 'S') {
nxl; nxl;
puts(" 是否保存?(将会覆盖历史版本)");
puts(" 1. 是的QwQ 2. 算了QAQ");
char chs = getch();
if(chs == '1') {
save_document();
}
continue;
} else if(choose == 'R') {
nxl; nxl;
puts(" 是否读档?");
puts(" 1. 是的QwQ 2. 算了QAQ");
char chs = getch();
if(chs == '1') {
read_document();
}
continue;
} else if(choose == 'H') {
help_use();
continue;
}
}
}
inline int rejudge_out() {
clr;
nxl; nxl; nxl; nxl; nxl;
puts(" 确定要抛弃我喵QAQ?");
puts(" 1. 狠心放弃");
puts(" 2. 我再想想");
nxl; nxl; nxl;
int chose = getch() - '0';
if(chose == 1)
return 4;
else return 0;
}
inline void menu() {
int choose = 0;
while(choose != 4) {
choose = 0;
start_words();
choose = getch() - '0';
switch (choose) {
case 1 :
use_menu();
break;
case 2 :
about_words();
break;
case 3 :
help_words();
break;
case 4 :
choose = rejudge_out();
break;
default :
break;
}
}
end_words();
}
inline void debug() {
// srand((unsigned)time(NULL));
// debug_plus();
// save_document();
read_document();
}
inline void debug_plus() {
for(int i = 1; i <= 1000; i++) {
stu_cnt++;
for(int j = 0; j <= 3; j++) {
stu[i].name[j] = rand() % 26 + 'a';
}
stu[i].num = i;
stu[i].sc = score(rand() % 100, rand() % 100, rand() % 100, rand() % 100, rand() % 100, rand() % 100, 0);
stu[i].sc.get_sum();
}
update_rank();
}
int main () {
debug();
menu();
int _ = 0;
return ~~(0^_^0);
}
NOIP2018并不是结束,而是开始