你可以帮我用c++语言写分别一段关于学生信息管理系统内的查看学生基本个人信息和学生登录还有修改密码功能的代码吗
时间: 2024-04-04 18:29:18 浏览: 26
当然可以,以下是基于C++的学生信息管理系统的查看学生信息、学生登录和修改密码的代码。
```
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 学生类
class Student {
public:
string name; // 姓名
int age; // 年龄
string gender; // 性别
string id; // 学号
string password; // 密码
Student(string n, int a, string g, string i, string p) {
name = n;
age = a;
gender = g;
id = i;
password = p;
}
// 输出学生信息
void displayInfo() {
cout << "姓名:" << name << endl;
cout << "年龄:" << age << endl;
cout << "性别:" << gender << endl;
cout << "学号:" << id << endl;
}
// 修改密码
void changePassword(string new_password) {
password = new_password;
cout << "密码修改成功!" << endl;
}
// 验证密码
bool checkPassword(string input_password) {
return input_password == password;
}
};
int main() {
// 创建学生对象
Student stu1("张三", 18, "男", "001", "123456");
Student stu2("李四", 19, "女", "002", "654321");
// 学生信息存储容器
vector<Student> students;
students.push_back(stu1);
students.push_back(stu2);
// 查看学生信息
string input_id;
cout << "请输入学生的学号:" << endl;
cin >> input_id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == input_id) {
students[i].displayInfo();
break;
}
}
// 学生登录
string input_stu_id, input_stu_password;
cout << "请输入学号:" << endl;
cin >> input_stu_id;
cout << "请输入密码:" << endl;
cin >> input_stu_password;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == input_stu_id && students[i].checkPassword(input_stu_password)) {
cout << "登录成功!" << endl;
break;
}
}
// 修改密码
string input_password;
cout << "请输入原密码:" << endl;
cin >> input_password;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == input_stu_id && students[i].checkPassword(input_password)) {
string new_password;
cout << "请输入新密码:" << endl;
cin >> new_password;
students[i].changePassword(new_password);
break;
}
}
return 0;
}
```
以上就是基于C++的学生信息管理系统的查看学生信息、学生登录和修改密码的代码。
相关推荐
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)