类:抽象类 学生类(研究生类 本科生类) 普通教师类 博导类
学生类包含:(string)姓名 (string)ID (int)年龄 (bool)性别 (double)综测
研究生类继承学生类,下设 成绩1 成绩2 成绩3
本科生类继承学生类,下设语文成绩, 数学成绩,英语成绩
普通教师类包含:姓名 ID 年龄 性别 教师评价分
博导类继承普通教师类和研究生类 ,下设成绩1 成绩2 成绩3 自我评分
目录
抽象类编写区:
学生类:继承抽象类
研究生类:继承学生类
本科生类:继承学生类
普通教师类:继承抽象类
博导类:继承普通教师类和研究生类
抽象类编写区:#include学生类:继承抽象类#include #include #define NUM 30 //在此可修改人数上限 using namespace std; void menu2_1(); void menu2_2(); void menu3_1(); void menu3_2(); //人 类 抽象类 class Person { public: //共有基本属性 string name; string id; int age; bool gender; //同名函数 纯虚函数 Person() {}; virtual void Set() = 0; virtual void Show()const = 0; virtual void Add() = 0; virtual void Delete() = 0; };
//学生类 class Student :protected Person { public: double survey;//综测分数 为研究生类本科生类共有成分 Student() {}; //设置学生类基本信息 姓名 ID 年龄 性别 综测 void Set(string n, string i, int a, bool g, double s) { name = n; id = i; age = a; gender = g; survey = s; } void Show() { cout << name << " " << id << " "<研究生类:继承学生类
//研究生类 class GraduateStudent :public Student { public: double score_1; double score_2; double score_3; GraduateStudent() {}; void Set(double s1, double s2, double s3) { score_1 = s1; score_2 = s2; score_3 = s3; } void Set() {};//没有用到 void Add() {}; void Delete(){}; void Show()const { cout << score_1 << " " << score_2 << " " << score_3 << endl; }; static void Add(int N, int N2); static void Delete(string ID,int N); const friend ostream& operator<<(ostream& os, GraduateStudent& G); }; static GraduateStudent GS[NUM]; void GraduateStudent::Add(int N, int N2) { cout << "分别输入:姓名 ID 年龄 性别 综测 成绩1 成绩2 成绩3" << endl; for (int i = N; i < N + N2; i++) { cin >> Gra[i].n >> Gra[i].i >> Gra[i].a >> Gra[i].g >> Gra[i].s >> Gra[i].s1 >> Gra[i].s2 >> Gra[i].s3; } for (int i = N; i < N + N2; i++) { GS[i].Student::Set(Gra[i].n, Gra[i].i, Gra[i].a, Gra[i].g, Gra[i].s); GS[i].Set(Gra[i].s1, Gra[i].s2, Gra[i].s3); } } void GraduateStudent::Delete(string ID, int N) { //遍历查找 int flag=-1; for (int i = 0; i < N; i++) { if (ID == GS[i].Student::id) { flag = i; break; } } //如果找到了 if (flag!=-1) { for (int i = flag; i < N ; i++) { GS[i].Student::name = GS[i + 1].Student::name; GS[i].Student::id=GS[i + 1].Student::id; GS[i].Student::age=GS[i + 1].Student::age; GS[i].Student::gender=GS[i + 1].Student::gender; GS[i].Student::survey=GS[i + 1].Student::survey; } for (int i = flag; i < N; i++) { GS[i].score_1 = GS[i + 1].score_1; GS[i].score_2 = GS[i + 1].score_2; GS[i].score_3 = GS[i + 1].score_3; } } else cout << "输入ID错误" << endl; } const ostream& operator<<(ostream& os, GraduateStudent& G) { os << G.Student::name <<" "<< G.Student::id << " " << G.Student::age << " " << G.Student::gender << " " << G.Student::survey << " " << G.score_1<< " " << G.score_2<< " " << G.score_3<< endl; return os; }本科生类:继承学生类
//本科生类 class Undergraduate : public Student { double Chinese; double Math; double English; public: Undergraduate() {}; void Set(double C, double M, double E) { Chinese = C; Math = M; English = E; } void Set() {};//没有用到 void Add() {}; void Delete() {}; void Show()const { cout << Chinese << " " << Math << " " << English << endl; }; static void Add(int N, int N2); static void Delete(string ID, int N); const friend ostream& operator<<(ostream& os, Undergraduate& G); }; static Undergraduate US[NUM]; void Undergraduate::Add(int N, int N2) { cout << "分别输入:姓名 ID 年龄 性别 综测 语文成绩 数学成绩 外语成绩" << endl; for (int i = N; i < N + N2; i++) { cin >> Un[i].n >> Un[i].i >> Un[i].a >> Un[i].g >> Un[i].s >> Un[i].s1 >> Un[i].s2 >> Un[i].s3; } for (int i = N; i < N + N2; i++) { GS[i].Student::Set(Un[i].n, Un[i].i, Un[i].a, Un[i].g, Un[i].s); GS[i].Set(Un[i].s1, Un[i].s2, Un[i].s3); } } void Undergraduate::Delete(string ID, int N) { //遍历查找 int flag = -1; for (int i = 0; i < N; i++) { if (ID == US[i].Student::id) { flag = i; break; } } //如果找到了 if (flag != -1) { for (int i = flag; i < N; i++) { US[i].Student::name = US[i + 1].Student::name; US[i].Student::id = US[i + 1].Student::id; US[i].Student::age = US[i + 1].Student::age; US[i].Student::gender = US[i + 1].Student::gender; US[i].Student::survey = US[i + 1].Student::survey; } for (int i = flag; i < N; i++) { US[i].Chinese = US[i + 1].Chinese; US[i].Math = US[i + 1].Math; US[i].English = US[i + 1].English; } } else cout << "输入ID错误" << endl; } const ostream& operator<<(ostream& os, Undergraduate& G) { os << G.Student::name << " " << G.Student::id << " " << G.Student::age << " " << G.Student::gender << " " << G.Student::survey << " " << G.Chinese << " " << G.Math << " " << G.English << endl; return os; }普通教师类:继承抽象类
//教师类 class Teacher :public Person { public: double Teacherevaluation;//教学评价分 为教师类独有部分 Teacher() {}; //教师类基本信息 void Set(string n, string i, int a, bool g, double T) { name = n; id = i; age = a; gender = g; Teacherevaluation = T; } void Set() {};//未用到 void Add() {}; void Delete() {}; void Show()const { cout << name << " " << id << " " << age << " " <博导类:继承普通教师类和研究生类> TC[i].n >> TC[i].i >> TC[i].a >> TC[i].g >> TC[i].s ; } for (int i = N; i < N + N2; i++) { T[i].Set(TC[i].n, TC[i].i, TC[i].a, TC[i].g, TC[i].s); } } void Teacher::Delete(string ID, int N) { //遍历查找 int flag = -1; for (int i = 0; i < N; i++) { if (ID == T[i].id) { flag = i; break; } } //如果找到了 if (flag != -1) { for (int i = flag; i < N; i++) { T[i].name = T[i + 1].name; T[i].id = T[i + 1].id; T[i].age = T[i + 1].age; T[i].gender = T[i + 1].gender; T[i].Teacherevaluation = T[i + 1].Teacherevaluation; } } else cout << "输入ID错误" << endl; } const ostream& operator<<(ostream& os, Teacher& G) { os << G.name << " " << G.id << " " << G.age << " " << G.gender << " " << G.Teacherevaluation << endl; return os; }
//博导类 class DoctoralTutor :virtual public Teacher, virtual public GraduateStudent { double Self_score; public: void Set(double S) { Self_score = S; } void Show()const { cout << Self_score << " "; } static void Add(int N,int N2); static void Delete(string ID, int N); const friend ostream& operator<<(ostream& os, DoctoralTutor& G); }; static DoctoralTutor DT[NUM]; void DoctoralTutor::Add(int N, int N2) { cout << "分别输入:姓名 ID 年龄 性别 教评 研究生毕业成绩1 成绩2 成绩3 博导分 " << endl; for (int i = N; i < N + N2; i++) { cin >> TC2[i].n >> TC2[i].i >> TC2[i].a >> TC2[i].g >> TC2[i].s>>TC2[i].s1>> TC2[i].s2>> TC2[i].s3>>TC2[i].s4; } for (int i = N; i < N + N2; i++) { DT[i].Teacher::Set(TC2[i].n , TC2[i].i ,TC2[i].a , TC2[i].g , TC2[i].s); DT[i].GraduateStudent::Set(TC2[i].s1 , TC2[i].s2 , TC2[i].s3); DT[i].Set(TC2[i].s4); } } void DoctoralTutor::Delete(string ID, int N) { //遍历查找 int flag = -1; for (int i = 0; i < N; i++) { if (ID == DT[i].Teacher::id) { flag = i; break; } } //如果找到了 if (flag != -1) { for (int i = flag; i < N; i++) { DT[i].Teacher::name = DT[i+1].Teacher::name; DT[i].Teacher::id = DT[i + 1].Teacher::id; DT[i].Teacher::age = DT[i + 1].Teacher::age; DT[i].Teacher::gender = DT[i + 1].Teacher::gender; DT[i].Teacher::Teacherevaluation= DT[i + 1].Teacher::Teacherevaluation; } for (int i = flag; i < N; i++) { DT[i].GraduateStudent::score_1 = DT[i+1].GraduateStudent::score_1; DT[i].GraduateStudent::score_2 = DT[i+1].GraduateStudent::score_2; DT[i].GraduateStudent::score_3 = DT[i+1].GraduateStudent::score_3; } for (int i = flag; i < N; i++) { DT[i].Self_score = DT[i + 1].Self_score; } } else cout << "输入ID错误" << endl; } const ostream& operator<<(ostream& os, DoctoralTutor& G) { os << G.Teacher::name << " " << G.Teacher::id << " " << G.Teacher::age << " " << G.Teacher::gender << " " << G.Teacher::Teacherevaluation << " "<学生类实现函数区:> n[temp] >> i[temp] >> a[temp] >> g[temp] >> s[temp]; GS[temp].Student::Set(n[temp], i[temp], a[temp], g[temp], s[temp]); } cout << "分别输入 成绩1 成绩2,成绩3" << endl; for (int temp = 0; temp < N; temp++) { cin >> s1[temp] >> s2[temp] >> s3[temp]; GS[temp].Set(s1[temp], s2[temp], s3[temp]); } }
//研究生对象创建实例化 void CreateGraStudent(int N) { string n[30]; string i[30]; int a[30]; bool g[30]; double s[30]; double s1[30]; double s2[30]; double s3[30]; cout << "分别输入 姓名 ID 年龄 性别 综测" << endl; for (int temp = 0; temp < N; temp++) { cin >> n[temp] >> i[temp] >> a[temp] >> g[temp] >> s[temp]; GS[temp].Student::Set(n[temp], i[temp], a[temp], g[temp], s[temp]); } cout << "分别输入 成绩1 成绩2,成绩3" << endl; for (int temp = 0; temp < N; temp++) { cin >> s1[temp] >> s2[temp] >> s3[temp]; GS[temp].Set(s1[temp], s2[temp], s3[temp]); } } //研究生对象显示 void ShowGraStudent(int N) { for (int i = 0; i < N; i++) { GS[i].Student::Show(); GS[i].Show(); } } //研究生对象添加 void AddGraStudent(int N, int N2) { GraduateStudent::Add(N, N2); } //研究生对象删除 void DeleteGraStudent(string ID, int N) { GraduateStudent::Delete(ID, N); } //本科生对象实例化 void CreateUngraStudent(int N) { string n[30]; string i[30]; int a[30]; bool g[30]; double s[30]; double s1[30]; double s2[30]; double s3[30]; cout << "分别输入 姓名 ID 年龄 性别 综测" << endl; for (int temp = 0; temp < N; temp++) { cin >> n[temp] >> i[temp] >> a[temp] >> g[temp] >> s[temp]; US[temp].Student::Set(n[temp], i[temp], a[temp], g[temp], s[temp]); } cout << "分别输入 成绩1 成绩2,成绩3" << endl; for (int temp = 0; temp < N; temp++) { cin >> s1[temp] >> s2[temp] >> s3[temp]; US[temp].Set(s1[temp], s2[temp], s3[temp]); } } //本科生对象显示 void ShowUnStudent(int N) { for (int i = 0; i < N; i++) { US[i].Student::Show(); US[i].Show(); } } //本科生对象添加 void AddUngraStudent(int N, int N2) { Undergraduate::Add(N, N2); } void DeleteUngraStudent(string ID, int N) { Undergraduate::Delete(ID, N); }教师类实现函数区:
//普通老师对象实例化 void CreateTeacher(int N) { string n[30]; string i[30]; int a[30]; bool g[30]; double t[30]; cout << "请分别输入姓名 ID 年龄 性别 教评" << endl; for(int temp=0;temp文件读写 *** 作:> n[temp] >> i[temp] >> a[temp] >> g[temp] >> t[temp]; T[temp].Set(n[temp], i[temp], a[temp], g[temp], t[temp]); } } //普通老师对象显示 void ShowTeacher(int N) { for (int i = 0; i < N; i++) { T[i].Show(); } } void AddTeacher(int N, int N2) { Teacher::Add(N, N2); } void DeleteTeacher(string ID, int N) { Teacher::Delete(ID, N); } //博导实例化 void CreateDocTeacher(int N) { string n[30]; string i[30]; int a[30]; bool g[30]; double t[30]; double st[30]; double s1[30]; double s2[30]; double s3[30]; cout << "请分别输入姓名 ID 年龄 性别 教评" << endl; for (int temp = 0; temp < N; temp++) { cin >> n[temp] >> i[temp] >> a[temp] >> g[temp] >> t[temp]; DT[temp].Teacher::Set(n[temp], i[temp], a[temp], g[temp], t[temp]); } cout << "输入研究生毕业成绩" << endl; for (int temp = 0; temp < N; temp++) { cin >> s1[temp]>>s2[temp]>>s3[temp]; DT[temp].GraduateStudent::Set(s1[temp], s2[temp], s3[temp]); } cout << "输入博导分" << endl; for (int temp = 0; temp < N; temp++) { cin >> st[temp]; DT[temp].Set(st[temp]); } } //博导对象显示 void ShowDocTeacher(int N) { for (int i = 0; i < N; i++) { DT[i].Teacher::Show(); cout << "博导分: "; DT[i].Show(); DT[i].GraduateStudent::Show(); } } //博导对象添加 void AddDocTeacher(int N, int N2) { DoctoralTutor::Add(N, N2); } //博导对象删除 void DeleteDocTeacher(string ID, int N) { DoctoralTutor::Delete(ID, N); }
//输出文件 void fire(int N) { //1.包含头文件 fstream //2.创建流对象 ofstream ofs1, ofs2, ofs3, ofs4; //3.指定打开方式 ofs1.open("GraduateStudent.txt", ios::out); ofs2.open("Undergraduate.txt", ios::out); ofs3.open("Teacher.txt", ios::out); ofs4.open("DoctoralTutor.txt", ios::out); //4.写内容 for (int i = 0; i < N; i++) { ofs1 <学生类菜单: //设计学生菜单 void menu2() { int j; cout << "#######################################################" << endl; cout << "# #" << endl; cout << "# 学 校 教 务 管 理 系 统 #" << endl; cout << "# 1.研究生 2.本科生 3.退出 #" << endl; cout << "# #" << endl; cout << "#######################################################" << endl; cin >> j; switch (j) { case 1: menu2_1(); system("cls"); break; case 2: menu2_2(); system("cls"); break; case 3: return; } } //研究生菜单 void menu2_1() { int N; int N2 = 0; string ID; bool flag = 1; cout << "输入人数" << endl; cin >> N; int i; while (flag) { cout << "#######################################################" << endl; cout << "# #" << endl; cout << "# 学 校 教 务 管 理 系 统 #" << endl; cout << "# 1.创建 2.显示 3.添加 4.删除 5.创建文件并退出 #" << endl; cout << "# #" << endl; cout << "#######################################################" << endl; cin >> i; switch (i) { case 1: CreateGraStudent(N); system("cls"); break; case 2:system("cls"); ShowGraStudent(N); break; case 3: system("cls"); cout << "请输入需要添加的人数" << endl; cin >> N2; AddGraStudent(N, N2); N += N2; system("cls"); break; case 4: system("cls"); cout << "请输入需要删除的ID:" << endl; cin >> ID; DeleteGraStudent(ID, N); N--; system("cls"); break; case 5: fire(N); return; } cout << "...是否继续操作(1/0)"; cin >> flag; if (flag == 0) break; } } //本科生菜单 void menu2_2() { int N; int N2; string ID; bool flag = 1; cout << "输入人数" << endl; cin >> N; int i; while (flag) { cout << "#######################################################" << endl; cout << "# 本 科 生 菜 单 #" << endl; cout << "# 学 校 教 务 管 理 系 统 #" << endl; cout << "# 1.创建 2.显示 3.添加 4.删除 5.创建文件并退出 #" << endl; cout << "# #" << endl; cout << "#######################################################" << endl; cin >> i; switch (i) { case 1: CreateUngraStudent(N); system("cls"); break; case 2: ShowUnStudent(N); break; case 3: system("cls"); cout << "请输入需要添加的人数" << endl; cin >> N2; AddUngraStudent(N, N2); N += N2; system("cls"); break; case 4: system("cls"); cout << "请输入需要删除的ID:" << endl; cin >> ID; DeleteUngraStudent(ID, N); N--; system("cls"); break; case 5: fire(N); return; } cout << "...是否继续操作(1/0)"; cin >> flag; if (flag == 0) break; } }教师菜单://设计普通教师菜单 void menu3_1() { int N; int N2; string ID; bool flag = 1; cout << "输入人数" << endl; cin >> N; int i; while (flag) { cout << "#######################################################" << endl; cout << "# #" << endl; cout << "# 学 校 教 务 管 理 系 统 #" << endl; cout << "# 1.创建 2.显示 3.添加 4.删除 5.创建文件并退出 #" << endl; cout << "# #" << endl; cout << "#######################################################" << endl; cin >> i; switch (i) { case 1: CreateTeacher(N); system("cls"); break; case 2: ShowTeacher(N); break; case 3: system("cls"); cout << "请输入需要添加的人数" << endl; cin >> N2; AddTeacher(N, N2); N += N2; system("cls"); break; case 4: system("cls"); cout << "请输入需要删除的ID:" << endl; cin >> ID; DeleteTeacher(ID, N); N--; system("cls"); break; case 5: fire(N); return; } cout << "...是否继续操作(1/0)"; cin >> flag; if (flag == 0) break; } } //设计博导菜单 void menu3_2() { int N; int N2; string ID; bool flag = 1; cout << "输入人数" << endl; cin >> N; int i; while (flag) { cout << "#######################################################" << endl; cout << "# 本 科 生 菜 单 #" << endl; cout << "# 学 校 教 务 管 理 系 统 #" << endl; cout << "# 1.创建 2.显示 3.添加 4.删除 5.创建文件并退出 #" << endl; cout << "# #" << endl; cout << "#######################################################" << endl; cin >> i; switch (i) { case 1: CreateDocTeacher(N); system("cls"); break; case 2: system("cls"); ShowDocTeacher(N); break; case 3: system("cls"); cout << "请输入需要添加的人数" << endl; cin >> N2; AddDocTeacher(N, N2); N += N2; system("cls"); break; case 4: system("cls"); cout << "请输入需要删除的ID:" << endl; cin >> ID; DeleteDocTeacher(ID, N); N--; system("cls"); break; case 5: fire(N); return; } cout << "...是否继续操作(1/0)"; cin >> flag; if (flag == 0) break; } }主菜单和主函数://设计主菜单 void menu() { int i; system("color 9F"); cout << "#######################################################" << endl; cout << "# 老 师 给 个 好 评 !!!求 求 了 #" << endl; cout << "# 学 校 教 务 管 理 系 统 #" << endl; cout << "# 1.学生信息 2.老师信息 3.退出 #" << endl; cout << "# 制 作 人 : 东 黎 学 号:2021 #" << endl; cout << "#######################################################" << endl; cin >> i; switch (i) { case 1: system("cls"); menu2(); break; case 2: system("cls"); menu3(); break; case 3: return; } } int main() { menu(); return 0; }注意:性别是bool类型
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)