#include #include using namespace std;

class Person { protected: string name; string gender; public: Person(string n, string g) : name(n), gender(g) {} virtual void ShowMe() { cout << 'Name: ' << name << endl; cout << 'Gender: ' << gender << endl; } };

class Staff : public Person { private: string workID; public: Staff(string n, string g, string id) : Person(n, g), workID(id) {} void ShowMe() { cout << 'Name: ' << name << endl; cout << 'Gender: ' << gender << endl; cout << 'Work ID: ' << workID << endl; } friend istream& operator>>(istream& in, Staff& s) { cout << 'Input name: '; in >> s.name; cout << 'Input gender: '; in >> s.gender; cout << 'Input work ID: '; in >> s.workID; return in; } };

class Student : public Person { private: string studentID; public: Student(string n, string g, string id) : Person(n, g), studentID(id) {} void ShowMe() { cout << 'Name: ' << name << endl; cout << 'Gender: ' << gender << endl; cout << 'Student ID: ' << studentID << endl; } friend istream& operator>>(istream& in, Student& s) { cout << 'Input name: '; in >> s.name; cout << 'Input gender: '; in >> s.gender; cout << 'Input student ID: '; in >> s.studentID; return in; } };

class Staff_Student : public Staff, public Student { public: Staff_Student(string n, string g, string id1, string id2) : Staff(n, g, id1), Student(n, g, id2) {} void ShowMe() { cout << 'Name: ' << name << endl; cout << 'Gender: ' << gender << endl; cout << 'Work ID: ' << Staff::workID << endl; cout << 'Student ID: ' << Student::studentID << endl; } friend istream& operator>>(istream& in, Staff_Student& ss) { cout << 'Input name: '; in >> ss.name; cout << 'Input gender: '; in >> ss.gender; cout << 'Input work ID: '; in >> ss.workID; cout << 'Input student ID: '; in >> ss.studentID; return in; } };

class School { private: int num; Person* p[100]; public: School() : num(0) {} void Append(Person* per) { p[num++] = per; } void Show() { for (int i = 0; i < num; i++) { p[i]->ShowMe(); cout << endl; } } };

int main() { School s; int choice; do { cout << '1. Add staff member' << endl; cout << '2. Add student member' << endl; cout << '3. Add staff-student member' << endl; cout << '4. Show all members' << endl; cout << '5. Exit' << endl; cout << 'Your choice: '; cin >> choice; switch (choice) { case 1: Staff* stf; stf = new Staff("", "", ""); cin >> stf; s.Append(stf); break; case 2: Student stu; stu = new Student("", "", ""); cin >> stu; s.Append(stu); break; case 3: Staff_Student ss; ss = new Staff_Student("", "", "", ""); cin >> *ss; s.Append(ss); break; case 4: s.Show(); break; case 5: break; default: cout << 'Error choice!' << endl; break; } } while (choice != 5); return 0;

C++ 简单学校人员管理系统:学生、员工和在职学生

原文地址: https://www.cveoy.top/t/topic/mMYw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录