📄 statistics.cpp
字号:
/************************************
统计信息
*************************************/
#include "ManagerInterface.h"
void ManagerInterface::Statistics()
{
while (1)
{
system("cls");
cout<<"\n"
<<"\t1. 学生分数统计\n"
<<"\t2. 学生年龄统计\n"
<<"\t3. 学生性别比例\n"
<<"\t4. 返回上层菜单\n"
<<"\n左边数字对应功能选择,请选择1~4: ";
int choice;
while (1)
{
cin.sync();
cin>>choice;
if (choice<1||choice>4) cout<<"\n输入错误,重选1~9\n";
else break;
}
switch (choice)
{
case 1:
InfoManager::mark();
break;
case 2:
InfoManager::old();
break;
case 3:
InfoManager::sex_proportion();
break;
case 4:
return;
}
}
}
void InfoManager::mark()
{
while (1)
{
Unit *p=head_stu;
system("cls");
cout<<"\n"
<<"\t1. 分数段统计\n"
<<"\t 不及格统计:\n"
<<"\t 2. 三门课程全不及格统计\n"
<<"\t 3. 有且仅有两门课程不及格统计\n"
<<"\t 有且仅有单科不及格统计:\n"
<<"\t 4. 数学\n"
<<"\t 5. 语文\n"
<<"\t 6. 英语\n"
<<"\t7. 返回上层菜单\n"
<<"\n左边数字对应功能选择,请选择1~7: ";
int choice;
while (1)
{
cin.sync();
cin>>choice;
if (choice<1||choice>7) cout<<"\n输入错误,重选1~7\n";
else break;
}
switch (choice)
{
case 1:
system("cls");
InfoManager::mark_distributions();
break;
case 2:
system("cls");
InfoManager::mark_fail_all();
break;
case 3:
system("cls");
InfoManager::mark_fail_both();
break;
case 4:
system("cls");
InfoManager::mark_fail_single(1);
break;
case 5:
system("cls");
InfoManager::mark_fail_single(2);
break;
case 6:
system("cls");
InfoManager::mark_fail_single(3);
break;
case 7:
return;
}
}
}
void InfoManager::mark_distributions()
{
Unit *p=head_stu;
int total=InfoManager::Get_Length();
int math_count_90_100=0, chs_count_90_100=0, eng_count_90_100=0, ave_count_90_100=0,
math_count_80_90=0, chs_count_80_90=0, eng_count_80_90=0, ave_count_80_90=0,
math_count_70_80=0, chs_count_70_80=0, eng_count_70_80=0, ave_count_70_80=0,
math_count_60_70=0, chs_count_60_70=0, eng_count_60_70=0, ave_count_60_70=0,
math_count_fail=0, chs_count_fail=0, eng_count_fail=0, ave_count_fail=0;
while (p)
{
if (p->Math>=90&&p->Math<=100) math_count_90_100++;
else if (p->Math>=80&&p->Math<=89) math_count_80_90++;
else if (p->Math>=70&&p->Math<=79) math_count_70_80++;
else if (p->Math>=60&&p->Math<=69) math_count_60_70++;
else math_count_fail++;
if (p->Chinese>=90&&p->Chinese<=100) chs_count_90_100++;
else if (p->Chinese>=80&&p->Chinese<=89) chs_count_80_90++;
else if (p->Chinese>=70&&p->Chinese<=79) chs_count_70_80++;
else if (p->Chinese>=60&&p->Chinese<=69) chs_count_60_70++;
else chs_count_fail++;
if (p->English>=90&&p->English<=100) eng_count_90_100++;
else if (p->English>=80&&p->English<=89) eng_count_80_90++;
else if (p->English>=70&&p->English<=79) eng_count_70_80++;
else if (p->English>=60&&p->English<=69) eng_count_60_70++;
else eng_count_fail++;
if (p->Average>=90&&p->Average<=100) ave_count_90_100++;
else if (p->Average>=80&&p->Average<=89) ave_count_80_90++;
else if (p->Average>=70&&p->Average<=79) ave_count_70_80++;
else if (p->Average>=60&&p->Average<=69) ave_count_60_70++;
else ave_count_fail++;
p=p->next;
}
cout.precision(4);
cout<<"┌────────┬────┬────┬────┬────┐"<<endl;
cout<<"│"<<setw(6)<<"共"<<setw(3)<<total<<"人"<<" │ 数 学 │ 语 文 │ 英 语 │ 平均分 │"<<endl;
cout<<"├────┬───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │ 人数 │"<<setw(5)<<math_count_90_100<<" │"<<setw(5)<<chs_count_90_100<<" │"<<setw(5)<<eng_count_90_100<<" │"<<setw(5)<<ave_count_90_100<<" │"<<endl;
cout<<"│ 90~100├───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │百分比│"<<setw(6)<<(double)math_count_90_100/total*100<<"% │"<<setw(6)<<(double)chs_count_90_100/total*100<<"% │"<<setw(6)<<(double)eng_count_90_100/total*100<<"% │"<<setw(6)<<(double)ave_count_90_100/total*100<<"% │"<<endl;
cout<<"├────┼───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │ 人数 │"<<setw(5)<<math_count_80_90<<" │"<<setw(5)<<chs_count_80_90<<" │"<<setw(5)<<eng_count_80_90<<" │"<<setw(5)<<ave_count_80_90<<" │"<<endl;
cout<<"│ 80~90 ├───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │百分比│"<<setw(6)<<(double)math_count_80_90/total*100<<"% │"<<setw(6)<<(double)chs_count_80_90/total*100<<"% │"<<setw(6)<<(double)eng_count_80_90/total*100<<"% │"<<setw(6)<<(double)ave_count_80_90/total*100<<"% │"<<endl;
cout<<"├────┼───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │ 人数 │"<<setw(5)<<math_count_70_80<<" │"<<setw(5)<<chs_count_70_80<<" │"<<setw(5)<<eng_count_70_80<<" │"<<setw(5)<<ave_count_70_80<<" │"<<endl;
cout<<"│ 70~80 ├───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │百分比│"<<setw(6)<<(double)math_count_70_80/total*100<<"% │"<<setw(6)<<(double)chs_count_70_80/total*100<<"% │"<<setw(6)<<(double)eng_count_70_80/total*100<<"% │"<<setw(6)<<(double)ave_count_70_80/total*100<<"% │"<<endl;
cout<<"├────┼───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │ 人数 │"<<setw(5)<<math_count_60_70<<" │"<<setw(5)<<chs_count_60_70<<" │"<<setw(5)<<eng_count_60_70<<" │"<<setw(5)<<ave_count_60_70<<" │"<<endl;
cout<<"│ 60~70 ├───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │百分比│"<<setw(6)<<(double)math_count_60_70/total*100<<"% │"<<setw(6)<<(double)chs_count_60_70/total*100<<"% │"<<setw(6)<<(double)eng_count_60_70/total*100<<"% │"<<setw(6)<<(double)ave_count_60_70/total*100<<"% │"<<endl;
cout<<"├────┼───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │ 人数 │"<<setw(5)<<math_count_fail<<" │"<<setw(5)<<chs_count_fail<<" │"<<setw(5)<<eng_count_fail<<" │"<<setw(5)<<ave_count_fail<<" │"<<endl;
cout<<"│ 不及格 ├───┼────┼────┼────┼────┤"<<endl;
cout<<"│ │百分比│"<<setw(6)<<(double)math_count_fail/total*100<<"% │"<<setw(6)<<(double)chs_count_fail/total*100<<"% │"<<setw(6)<<(double)eng_count_fail/total*100<<"% │"<<setw(6)<<(double)ave_count_fail/total*100<<"% │"<<endl;
cout<<"└────┴───┴────┴────┴────┴────┘"<<endl;
system("pause");
}
void InfoManager::mark_fail_all()
{
Unit *p=head_stu;
int count=0;
Unit *i=NULL;
Unit *j=NULL;
while (p)
{
if (p->Math<60&&p->Chinese<60&&p->English<60)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
cout<<"共有"<<count<<"名学生三门课程都不及格\n\n";
j=InfoManager::SortByClass(i);
InfoManager::Show_All_Stu(j);
cout<<"是否保存为文件?[Y/N]";
char choice;
cin>>choice;
if (choice=='N'||choice=='n') return;
InfoManager::saveRecords(j);
}
void InfoManager::mark_fail_both()
{
Unit *p=head_stu;
int count=0;
Unit *i=NULL;
Unit *j=NULL;
while (p)
{
if ((p->Math<60&&p->Chinese<60&&p->English>=60)||(p->Math<60&&p->Chinese>=60&&p->English<60)||(p->Math>=60&&p->Chinese<60&&p->English<60))
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
cout<<"共有"<<count<<"名学生两门课程都不及格\n\n";
j=InfoManager::SortByClass(i);
InfoManager::Show_All_Stu(j);
cout<<"是否保存为文件?[Y/N]";
char choice;
cin>>choice;
if (choice=='N'||choice=='n') return;
InfoManager::saveRecords(j);
}
void InfoManager::mark_fail_single(int choice)
{
Unit *p=head_stu;
int count=0;
Unit *i=NULL;
Unit *j=NULL;
switch (choice)
{
case 1:
{
while (p)
{
if (p->Math<60&&p->Chinese>=60&&p->English>=60)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
cout<<"共有"<<count<<"名学生有且仅有数学不及格\n\n";
break;
}
case 2:
{
while (p)
{
if (p->Math>=60&&p->Chinese<60&&p->English>=60)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
cout<<"共有"<<count<<"名学生有且仅有语文不及格\n\n";
break;
}
case 3:
{
while (p)
{
if (p->Math>=60&&p->Chinese>=60&&p->English<60)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
cout<<"共有"<<count<<"名学生有且仅有英语不及格\n\n";
break;
}
}
j=InfoManager::SortByClass(i);
InfoManager::Show_All_Stu(j);
cout<<"是否保存为文件?[Y/N]";
char judge;
cin>>judge;
if (judge=='N'||judge=='n') return;
InfoManager::saveRecords(j);
}
void InfoManager::sex_proportion()
{
Unit *p=head_stu;
int count_male=0;
int count_female=0;
int total=InfoManager::Get_Length();
while (p)
{
if (p->Sex==0) ++count_male;
else ++count_female;
p=p->next;
}
cout.precision(4);
cout<<"┌────────┬────┬────┐"<<endl;
cout<<"│"<<setw(6)<<"共"<<setw(3)<<total<<"人"<<" │ 男 生 │ 女 生 │"<<endl;
cout<<"├────┬───┼────┼────┤"<<endl;
cout<<"│ 性 别 │ 人数 │"<<setw(5)<<count_male<<" │"<<setw(5)<<count_female<<" │"<<endl;
cout<<"│ ├───┼────┼────┤"<<endl;
cout<<"│ 比 例 │百分比│"<<setw(6)<<(double)count_male/total*100<<"% │"<<setw(6)<<(double)count_female/total*100<<"% │"<<endl;
cout<<"└────┴───┴────┴────┘"<<endl;
system("pause");
}
void InfoManager::old()
{
Unit *p=head_stu;
int count_male=0;
int count_female=0;
int total=InfoManager::Get_Length();
int total_old=0;
int total_old_male=0;
int total_old_female=0;
int max_male=0;
int min_male=200;
int max_female=0;
int min_female=200;
while (p)
{
total_old+=p->Old;
if (p->Sex==0)
{
if (p->Old>max_male) max_male=p->Old;
if (p->Old<min_male) min_male=p->Old;
++count_male;
total_old_male+=p->Old;
}
else
{
if (p->Old>max_female) max_female=p->Old;
if (p->Old<min_female) min_female=p->Old;
++count_female;
total_old_female+=p->Old;
}
p=p->next;
}
cout<<"┌────────┬─────────┬─────────┐"<<endl;
cout<<"│"<<setw(6)<<"共"<<setw(3)<<total<<"人"<<" │ 男 生 │ 女 生 │"<<endl;
cout<<"├────────┼────┬────┼────┬────┤"<<endl;
cout<<"│ 极 值 │ 最大 │ 最小 │ 最大 │ 最小 │"<<endl;
cout<<"│ ├────┼────┼────┼────┤"<<endl;
cout<<"│ │"<<setw(5)<<max_male<<" │"<<setw(5)<<min_male<<" │"<<setw(5)<<max_female<<" │"<<setw(5)<<min_female<<" │"<<endl;
cout<<"├────────┼────┴────┼────┴────┤"<<endl;
cout<<"│ 平 均 │"<<setw(10)<<total_old_male/count_male<<" │"<<setw(10)<<total_old_female/count_female<<" │"<<endl;
cout<<"└────────┴─────────┴─────────┘"<<endl;
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -