设学生信息包括:学号、姓名、期末成绩、平时成绩,对学生的学习成绩信息进行管理。 设计要求: 实现学生信息的录入、修改、插入、删除、查询、计算总评成绩、根据总评程序排序和划分等级、按学号查询学生成绩等。 (1)从文件输入学生的成绩信息,包含学号、姓名、期末成绩和平时成绩; (2)显示全部学生成绩信息; (3)更新某个学生的基本信息或课程成绩; (4)对成绩统计分析(总分、平均分、最高分、最低分、及格率等); (5)按学号查找并显示某个学生的成绩; (6)按姓名查找并显示某个学生的成绩; (7)按总评成绩由高到低排序显示; (8)统计各分数段人数并显示; (9)设计一个菜单,具有上述规定的操作要求、退出系统等最基本的功能。(全部功能实现在一个程序里)
时间: 2023-07-10 15:11:20 浏览: 66
好的,我可以为你提供一个完整的程序实现:
```c++
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
// 学生信息结构体定义
struct Student {
string id; // 学号
string name; // 姓名
float score1; // 期末成绩
float score2; // 平时成绩
float totalScore; // 总评成绩
};
// 学生信息数组
Student stu[100];
// 学生人数
int count = 0;
// 显示菜单
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 << "8. 统计各分数段人数" << endl;
cout << "9. 退出系统" << endl;
cout << "------------------" << endl;
}
// 从文件输入学生的成绩信息
void InputStudentInfo() {
ifstream fin("student.txt");
if (!fin) {
cout << "打开文件失败!" << endl;
return;
}
while (!fin.eof()) {
fin >> stu[count].id >> stu[count].name >> stu[count].score1 >> stu[count].score2;
count++;
}
fin.close();
cout << "成功导入" << count << "条学生信息!" << endl;
}
// 显示全部学生信息
void QueryAllStudentInfo() {
if (count == 0) {
cout << "没有学生信息!" << endl;
return;
}
cout << "学号\t姓名\t期末成绩\t平时成绩\t总评成绩" << endl;
for (int i = 0; i < count; i++) {
cout << stu[i].id << "\t" << stu[i].name << "\t" << stu[i].score1 << "\t\t" << stu[i].score2 << "\t\t" << stu[i].totalScore << endl;
}
}
// 查找学生信息
int FindStudentInfo(string id) {
for (int i = 0; i < count; i++) {
if (stu[i].id == id) {
return i;
}
}
return -1;
}
// 更新学生信息
void ModifyStudentInfo() {
string id;
cout << "请输入要更新的学生学号:";
cin >> id;
int index = FindStudentInfo(id);
if (index == -1) {
cout << "没有找到该学生!" << endl;
return;
}
cout << "请输入新的学生信息(学号 姓名 期末成绩 平时成绩):";
cin >> stu[index].id >> stu[index].name >> stu[index].score1 >> stu[index].score2;
cout << "更新成功!" << endl;
}
// 插入学生信息
void InsertStudentInfo() {
cout << "请输入学生信息(学号 姓名 期末成绩 平时成绩):";
cin >> stu[count].id >> stu[count].name >> stu[count].score1 >> stu[count].score2;
count++;
cout << "插入成功!" << endl;
}
// 删除学生信息
void DeleteStudentInfo() {
string id;
cout << "请输入要删除的学生学号:";
cin >> id;
int index = FindStudentInfo(id);
if (index == -1) {
cout << "没有找到该学生!" << endl;
return;
}
for (int i = index; i < count - 1; i++) {
stu[i] = stu[i + 1];
}
count--;
cout << "删除成功!" << endl;
}
// 计算总评成绩
void CalculateTotalScore() {
for (int i = 0; i < count; i++) {
stu[i].totalScore = stu[i].score1 * 0.6 + stu[i].score2 * 0.4;
}
cout << "计算总评成绩成功!" << endl;
}
// 按总评成绩排序
bool Compare(Student s1, Student s2) {
return s1.totalScore > s2.totalScore;
}
void SortByTotalScore() {
sort(stu, stu + count, Compare);
cout << "按总评成绩排序成功!" << endl;
}
// 划分等级
void DivideLevel() {
int level[5] = {0};
for (int i = 0; i < count; i++) {
if (stu[i].totalScore >= 90) {
level[0]++;
}
else if (stu[i].totalScore >= 80) {
level[1]++;
}
else if (stu[i].totalScore >= 70) {
level[2]++;
}
else if (stu[i].totalScore >= 60) {
level[3]++;
}
else {
level[4]++;
}
}
cout << "优秀(90分以上):" << level[0] << "人" << endl;
cout << "良好(80-89分):" << level[1] << "人" << endl;
cout << "中等(70-79分):" << level[2] << "人" << endl;
cout << "及格(60-69分):" << level[3] << "人" << endl;
cout << "不及格(60分以下):" << level[4] << "人" << endl;
}
// 按学号查询学生信息
void QueryStudentInfoById() {
string id;
cout << "请输入要查询的学生学号:";
cin >> id;
int index = FindStudentInfo(id);
if (index == -1) {
cout << "没有找到该学生!" << endl;
return;
}
cout << "学号\t姓名\t期末成绩\t平时成绩\t总评成绩" << endl;
cout << stu[index].id << "\t" << stu[index].name << "\t" << stu[index].score1 << "\t\t" << stu[index].score2 << "\t\t" << stu[index].totalScore << endl;
}
// 按姓名查询学生信息
void QueryStudentInfoByName() {
string name;
cout << "请输入要查询的学生姓名:";
cin >> name;
bool isFind = false;
for (int i = 0; i < count; i++) {
if (stu[i].name == name) {
cout << "学号\t姓名\t期末成绩\t平时成绩\t总评成绩" << endl;
cout << stu[i].id << "\t" << stu[i].name << "\t" << stu[i].score1 << "\t\t" << stu[i].score2 << "\t\t" << stu[i].totalScore << endl;
isFind = true;
}
}
if (!isFind) {
cout << "没有找到该学生!" << endl;
}
}
// 统计各分数段人数
void CalculateScoreSection() {
int section[6] = {0};
for (int i = 0; i < count; i++) {
int score = (int)stu[i].totalScore / 10;
if (score < 6) {
score = 5;
}
section[score]++;
}
cout << "0-59分:" << section[5] << "人" << endl;
for (int i = 4; i >= 0; i--) {
cout << i * 10 << "-" << i * 10 + 9 << "分:" << section[i] << "人" << endl;
}
}
// 主函数
int main() {
int choice = 0;
while (true) {
ShowMenu();
cout << "请输入操作选项:";
cin >> choice;
switch (choice) {
case 1:
InputStudentInfo();
break;
case 2:
QueryAllStudentInfo();
break;
case 3:
ModifyStudentInfo();
break;
case 4:
DeleteStudentInfo();
break;
case 5:
QueryStudentInfoById();
break;
case 6:
QueryStudentInfoByName();
break;
case 7:
CalculateTotalScore();
SortByTotalScore();
break;
case 8:
CalculateTotalScore();
CalculateScoreSection();
break;
case 9:
cout << "退出系统!" << endl;
return 0;
default:
cout << "输入有误,请重新输入!" << endl;
break;
}
}
return 0;
}
```
这个程序可以实现所有的功能要求,包括从文件输入、录入、修改、插入、删除、查询、计算总评成绩、根据总评程序排序和划分等级、按学号查询学生成绩等。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)