论坛网站需要多大的空间Wordpress pay plugin
论坛网站需要多大的空间,Wordpress pay plugin,图文制作app哪个好,漳诈网站建设C 实现学生成绩管理系统
思路#xff1a;
定义 Student 类#xff0c;包含学生的基本信息和成绩。实现添加学生、删除学生、修改成绩、显示所有学生成绩和查找学生的功能。使用向量#xff08;vector#xff09;存储学生信息。
#include iostream
#include …C 实现学生成绩管理系统
思路
定义 Student 类包含学生的基本信息和成绩。实现添加学生、删除学生、修改成绩、显示所有学生成绩和查找学生的功能。使用向量vector存储学生信息。
#include iostream
#include vector
#include stringusing namespace std;// Student 类定义
class Student {
public:string name;int id;vectorint scores;Student(string n, int i) : name(n), id(i) {}// 计算平均成绩float getAverageScore() {int total 0;for (int score : scores) {total score;}return scores.empty() ? 0 : (float)total / scores.size();}// 显示学生信息void display() {cout ID: id , Name: name , Average Score: getAverageScore() endl;}
};// 成绩管理系统类定义
class GradeManagementSystem {
private:vectorStudent students;public:// 添加学生void addStudent(string name, int id) {students.push_back(Student(name, id));}// 删除学生void removeStudent(int id) {for (auto it students.begin(); it ! students.end(); it) {if (it-id id) {students.erase(it);cout Student ID id removed. endl;return;}}cout Student ID id not found. endl;}// 添加成绩void addScore(int id, int score) {for (Student student : students) {if (student.id id) {student.scores.push_back(score);cout Score added to student ID id . endl;return;}}cout Student ID id not found. endl;}// 显示所有学生成绩void displayAllStudents() {for (Student student : students) {student.display();}}// 查找学生void findStudent(int id) {for (Student student : students) {if (student.id id) {student.display();return;}}cout Student ID id not found. endl;}
};int main() {GradeManagementSystem gms;int choice, id, score;string name;while (true) {cout \nStudent Grade Management System\n;cout 1. Add Student\n;cout 2. Remove Student\n;cout 3. Add Score\n;cout 4. Display All Students\n;cout 5. Find Student\n;cout 6. Exit\n;cout Enter your choice: ;cin choice;switch (choice) {case 1:cout Enter student name: ;cin name;cout Enter student ID: ;cin id;gms.addStudent(name, id);break;case 2:cout Enter student ID to remove: ;cin id;gms.removeStudent(id);break;case 3:cout Enter student ID to add score: ;cin id;cout Enter score: ;cin score;gms.addScore(id, score);break;case 4:gms.displayAllStudents();break;case 5:cout Enter student ID to find: ;cin id;gms.findStudent(id);break;case 6:return 0;default:cout Invalid choice. Please try again.\n;}}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88497.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!