学生信息管理系统c++类
时间: 2023-12-07 08:04:24 浏览: 101
以下是一个简单的学生信息管理系统的C++类的示例:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Student {
public:
Student(string id, string name, string gender, int age, string cls) {
m_id = id;
m_name = name;
m_gender = gender;
m_age = age;
m_cls = cls;
}
string getId() {
return m_id;
}
string getName() {
return m_name;
}
string getGender() {
return m_gender;
}
int getAge() {
return m_age;
}
string getCls() {
return m_cls;
}
private:
string m_id;
string m_name;
string m_gender;
int m_age;
string m_cls;
};
class PrimaryStudent : public Student {
public:
PrimaryStudent(string id, string name, string gender, int age, string cls, int englishScore, int mathScore, int chineseScore)
: Student(id, name, gender, age, cls) {
m_englishScore = englishScore;
m_mathScore = mathScore;
m_chineseScore = chineseScore;
}
int getEnglishScore() {
return m_englishScore;
}
int getMathScore() {
return m_mathScore;
}
int getChineseScore() {
return m_chineseScore;
}
private:
int m_englishScore;
int m_mathScore;
int m_chineseScore;
};
class MiddleStudent : public PrimaryStudent {
public:
MiddleStudent(string id, string name, string gender, int age, string cls, int englishScore, int mathScore, int chineseScore, int geographyScore, int historyScore, string address)
: PrimaryStudent(id, name, gender, age, cls, englishScore, mathScore, chineseScore) {
m_geographyScore = geographyScore;
m_historyScore = historyScore;
m_address = address;
}
int getGeographyScore() {
return m_geographyScore;
}
int getHistoryScore() {
return m_historyScore;
}
string getAddress() {
return m_address;
}
private:
int m_geographyScore;
int m_historyScore;
string m_address;
};
int main() {
// 创建一个小学生对象
PrimaryStudent ps("001", "小明", "男", 10, "一年级", 80, 90, 85);
cout << "小学生信息:" << endl;
cout << "学号:" << ps.getId() << endl;
cout << "姓名:" << ps.getName() << endl;
cout << "性别:" << ps.getGender() << endl;
cout << "年龄:" << ps.getAge() << endl;
cout << "班级:" << ps.getCls() << endl;
cout << "英语成绩:" << ps.getEnglishScore() << endl;
cout << "数学成绩:" << ps.getMathScore() << endl;
cout << "语文成绩:" << ps.getChineseScore() << endl;
// 创建一个中学生对象
MiddleStudent ms("002", "小红", "女", 15, "高一", 90, 95, 92, 85, 88, "北京市朝阳区");
cout << "中学生信息:" << endl;
cout << "学号:" << ms.getId() << endl;
cout << "姓名:" << ms.getName() << endl;
cout << "性别:" << ms.getGender() << endl;
cout << "年龄:" << ms.getAge() << endl;
cout << "班级:" << ms.getCls() << endl;
cout << "英语成绩:" << ms.getEnglishScore() << endl;
cout << "数学成绩:" << ms.getMathScore() << endl;
cout << "语文成绩:" << ms.getChineseScore() << endl;
cout << "地理成绩:" << ms.getGeographyScore() << endl;
cout << "历史成绩:" << ms.getHistoryScore() << endl;
cout << "家庭住址:" << ms.getAddress() << endl;
return 0;
}
```
阅读全文