●功能介绍
用 C++设计一个程序,能提供下列功能:
1. 录入学生成绩信息。按照学号,姓名,语文,数学,英语的格式录入学生的成绩。
2.展示目前录入学生的成绩信息。以学号,姓名,语文,数学,英语的格式按列表展示。
3.查询成绩。根据学生的学号或姓名查询学生的成绩。
4.修改。通过姓名查询找到相应的学生记录并对其进行修改。
5.统计。计算学生的总分并按顺序显示输出;统计班级学生的每门课程的平均分和全班人总分的平
均分并显示;统计个人总得分小于班级总分的学生并显示为不及格学生名单。
6.删除。删除指定学生成绩信息。
7.清空。清空学生表所有成绩信息。
●案例
1.录入5个学生的信息:
①1001 zhangsan 80 90 70
②1002 lisi 60 65 75
③1003 wangwu 75 85 100
④1004 zhaoliu 50 60 40
⑤1005 sunqi 70 85 95
2.展示已输入5个的学生成绩信息
3.用学号去查询zhaoliu的各科成绩
4.实现统计,查看学生成绩信息和不及格学生
5.对wangwu的语文成绩进行单科修改,修改为80(若要进行整体修改,按操作提示执行即可,这里只修改其语文成绩)
6.用姓名去查询wangwu的各科成绩
7.因为lisi的成绩录入错误,所以删除他的所有信息
8.展示目前剩余学生的成绩信息
9.操作完成清空学生成绩信息
●代码展示
#include <iostream> #include <string> #define max 100 //学生人数 using namespace std; struct person { string id; string name; int chinese; int math; int english; }; struct student_information { struct person data[max]; int size; }; void addinformation(student_information* si) { if (si->size == max) { cout << "学生信息表已满" << endl; } else { cout << "请输入学号:" << endl; string id; cin >> id; si->data[si->size].id = id; cout << "请输入姓名:" << endl; string name; cin >> name; si->data[si->size].name = name; cout << "请输入语文成绩:" << endl; int chinese; cin >> chinese; si->data[si->size].chinese = chinese; cout << "请输入数学成绩:" << endl; int math; cin >> math; si->data[si->size].math = math; cout << "请输入英语成绩:" << endl; int english; cin >> english; si->data[si->size].english = english; si->size++; cout << "<<添加成功>>" << endl; system("pause"); system("cls"); } } void showperson(student_information* si) { if (si->size == 0) { cout << "当前数据为空!" << endl; } else { for (int i = 0; i < si->size; i++) { cout << "学号:" << si->data[i].id<<" " << "姓名:" << si->data[i].name<<" " << "语文成绩:" << si->data[i].chinese<<" " << "数学成绩:" << si->data[i].math<<" " << "英语成绩:" << si->data[i].english << endl; } system("pause"); system("cls"); } } int isexist(student_information* si, string id) { for (int k = 0; k < si->size; k++) { if (si->data[k].id == id) return k; } return -1; } int isexist_1(student_information* si, string name) { for (int k = 0; k < si->size; k++) { if (si->data[k].name == name) return k; } return -1; } void searchperson(student_information* si) { cout << "请输入您要查找的学生:" << endl; cout << "如果按照学号查找输入1" << endl; cout << "如果按照姓名查找输入2" << endl; int n; cin >> n; string id, name; if (n == 1) { cin >> id; if (isexist(si, id) == -1) { cout << "此人不存在!" << endl; } else { cout << "此人存在!" << endl; int ret = isexist(si, id); { cout << "学号 " << si->data[ret].id << "\t"; cout << "姓名 " << si->data[ret].name << "\t"; cout << "语文成绩 " << si->data[ret].chinese << "\t"; cout << "数学成绩 " << si->data[ret].math << "\t"; cout << "英语成绩 " << si->data[ret].english << "\t"; } } } else { cin >> name; if (isexist_1(si, name) == -1) { cout << "此人不存在!" << endl; } else { cout << "此人存在!" << endl; int ret_1 = isexist_1(si, name); { cout << "学号 " << si->data[ret_1].id << "\t"; cout << "姓名 " << si->data[ret_1].name << "\t"; cout << "语文成绩 " << si->data[ret_1].chinese << "\t"; cout << "数学成绩 " << si->data[ret_1].math << "\t"; cout << "英语成绩 " << si->data[ret_1].english << "\t"; } } } system("pause"); system("cls"); } void alterperson(student_information* si) { cout << "请输入您要修改的联系人:" << endl; string name; cin >> name; if (isexist_1(si, name) == -1) { cout << "此人不存在!" << endl; } else { cout << "此人存在!" << endl; int ret_2 = isexist_1(si,name); cout << "单一修改-0" << "多数修改-1" << endl; int sign; cin >> sign; { if (sign == 0) { cout << "学号-1" << "姓名-2" << "语文成绩-3" << "数学成绩-4" << "英语成绩-5" << endl; int select_1; cin >> select_1; if (select_1 == 1) { string id; cin >> id; si->data[ret_2].id = id; } if (select_1 == 2) { string name; cin >> name; si->data[ret_2].name = name; } if (select_1 == 3) { int chinese; cin >> chinese; si->data[ret_2].chinese = chinese; } if (select_1 == 4) { int math; cin >> math; si->data[ret_2].math = math; } if (select_1 == 5) { int english; cin >> english; si->data[ret_2].english = english; } } } if (sign == 1) { cout << "请输入学号:" << endl; string id; cin >> id; si->data[ret_2].id = id; cout << "请输入姓名:" << endl; string name; cin >> name; si->data[ret_2].name = name; cout << "请输入语文成绩:" << endl; int chinese; cin >> chinese; si->data[ret_2].chinese = chinese; cout << "请输入数学成绩:" << endl; int math; cin >> math; si->data[ret_2].math = math; cout << "请输入英语成绩:" << endl; int english; cin >> english; si->data[ret_2].english = english; } } cout << "信息修改成功!" << endl; system("pause"); system("cls"); } void staticperson(student_information* si) { int allsum = 0; for (int i = 0; i < si->size; i++) { int sum = 0; sum = si->data[i].chinese + si->data[i].math + si->data[i].english; cout << "姓名:" << si->data[i].name << "语文:" << si->data[i].chinese << " " << "数学:" << si->data[i].math << " " << "英语:" << si->data[i].english << " " << "总分:" << sum << endl; allsum += sum; } int sum1 = 0, sum2 = 0, sum3 = 0; for (int i = 0; i < si->size; i++) { sum1 += si->data[i].chinese; sum2 += si->data[i].math; sum3 += si->data[i].english; } cout << "全班语文平均分:" << sum1 / si->size << endl; cout << "全班数学平均分:" << sum2 / si->size << endl; cout << "全班英语平均分:" << sum3 / si->size << endl; cout << "全班总分的平均分:" << allsum / si->size << endl; for (int i = 0; i < si->size; i++) { int sum = 0; sum = si->data[i].chinese + si->data[i].math + si->data[i].english; if (sum < allsum/si->size) { cout << "得分小于班级总分平均分的不及格学生:" << si->data[i].id << " " << si->data[i].name << endl; } } system("pause"); system("cls"); } void deleteperson(student_information* si) { cout << "请输入您要删除的学生:" << endl; string name; cin >> name; if (isexist_1(si, name) == -1) { cout << "查无此人!" << endl; } else { cout << "找到此人!" << endl; int ret = isexist_1(si, name); for (int l = ret; l < si->size; l++) { si->data[l].id = si->data[l + 1].id; si->data[l].name = si->data[l + 1].name; si->data[l].chinese = si->data[l + 1].chinese; si->data[l].math = si->data[l + 1].math; si->data[l].english = si->data[l + 1].english; }//abs->arrar[l]=abs->array[l+1]; si->size--; cout << "已删除此学生信息!" << endl; } system("pause"); system("cls"); } void emptyperson(student_information* si) { si->size = 0; cout << "成绩表已清空!" << endl; system("pause"); system("cls"); } void showmenu() { cout << "*************************" << endl; cout << "*****1:录入学生信息*****" << endl; cout << "*****2:展示学生信息******" << endl; cout << "*****3:查找学生信息******" << endl; cout << "*****4:修改学生信息******" << endl; cout << "*****5:统计学生信息******" << endl; cout << "*****6:删除学生信息******" << endl; cout << "*****7:清空学生信息******" << endl; cout << "*************************" << endl; } void text() { student_information SI; SI.size = 0; while (1) { showmenu(); int n; cin >> n; switch (n) { case 1: addinformation(&SI); break; case 2: showperson(&SI); break; case 3: searchperson(&SI); break; case 4: alterperson(&SI); break; case 5: staticperson(&SI); break; case 6: deleteperson(&SI); break; case 7: emptyperson(&SI); break; } } } int main() { text(); }
●结果展示
1.
2.
3.
4.
5.
6.
7.
8.
9.