以下是一个基于C++的学生成绩管理系统的简单实现,包含了用户管理模块和成绩管理模块的基本功能:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class User {
public:
string username;
string password;
string role;
User(string uname, string pwd, string r) : username(uname), password(pwd), role(r) {}
};
class Student {
public:
string name;
int score;
Student(string n, int s) : name(n), score(s) {}
};
class GradeManagementSystem {
private:
vector<User> users;
vector<Student> students;
public:
void registerUser(string username, string password, string role) {
User newUser(username, password, role);
users.push_back(newUser);
cout << "Successfully registered user: " << username << endl;
}
bool login(string username, string password) {
for (const auto& user : users) {
if (user.username == username && user.password == password) {
cout << "Successfully logged in as " << username << endl;
return true;
}
}
cout << "Invalid username or password" << endl;
return false;
}
void addStudent(string name, int score) {
Student newStudent(name, score);
students.push_back(newStudent);
cout << "Successfully added student: " << name << endl;
}
void findStudent(string name) {
bool found = false;
for (const auto& student : students) {
if (student.name == name) {
cout << "Found student: " << student.name << ", Score: " << student.score << endl;
found = true;
break;
}
}
if (!found) {
cout << "Student not found" << endl;
}
}
void modifyScore(string name, int newScore) {
bool found = false;
for (auto& student : students) {
if (student.name == name) {
student.score = newScore;
cout << "Modified score for student " << name << ": " << newScore << endl;
found = true;
break;
}
}
if (!found) {
cout << "Student not found" << endl;
}
}
};
int main() {
GradeManagementSystem system;
// 注册用户
system.registerUser("admin", "admin123", "admin");
system.registerUser("teacher", "teacher123", "teacher");
// 登录系统
system.login("admin", "admin123");
system.login("student", "wrongpassword");
// 添加学生
system.addStudent("Alice", 90);
system.addStudent("Bob", 85);
// 查找学生
system.findStudent("Alice");
system.findStudent("Charlie");
// 修改成绩
system.modifyScore("Bob", 88);
system.modifyScore("Eve", 100);
return 0;
}
这个代码中,我们建立了`User`类和`Student`类来分别表示用户和学生的信息。`GradeManagementSystem`类包含了注册用户、登录、添加学生、查找学生和修改成绩等操作。
运行这段代码,你可以通过调用相关函数来测试不同的功能模块。可以根据实际需求进一步扩展代码,例如添加更多功能,设计更复杂的数据结构等。
请注意,这只是一个简单示例,并没有涉及数据库存储和界面设计等方面。实际的系统可能需要更多的功能和细节处理。希望这个示例可以帮助你更好地理解学生成绩管理系统的设计与实现。如有任何疑问,请随时向我询问。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |