定义一个CPerson类及其派生类学生类和教师类

 时间:2024-10-12 13:46:16

1、定义一个cperson类,实现学工号,姓名,性别,生日等基本信息的录入。 2.采用公有继承方式定义cperson类的子类ctudent,添加班级,学号,课程,分数等学生特有的信息。 3.采用共有继承方式定义cperson类的子类cteacher,添加职称,工号,课程,学生成绩等教师特有信息。 4.对相关函数进行定义实现各种信息的键入和输出。 5.主函数定义实现上述功能的实现。(2)详细设计(要求详细写出每个模块的功能实现,关键技术,关键代码解释等。)

定义一个CPerson类及其派生类学生类和教师类

5、public: Cstudent(); ~Cstudent(); void input(); void inputCourse(); void displays();};class Teacher : public Cperson{private: string zhicheng; string gonghao; string bumen; string keming; string kechenghao; double chengji[300];public: Teacher(); ~Teacher(); void input();//录入教师相关信息 void setscore(int n);//录入学生相关信息 void dispscore(int m, int n);//用于指定或所有学生成绩信息 void sortcore(int n);//对学生成绩进行排序 void setstuscore(double &s1, int n);//用于修改指定学生 void display(int n);//用于显示教师信息};Cperson::Cperson(){ id = new char[10];

定义一个CPerson类及其派生类学生类和教师类

7、Cstudent::~Cstudent(){ delete[] classname; delete[] xuehao;}void Cstudent::input(){ classname = new char[20], xuehao = new char[20]; cin >> classname >> xuehao;}void Cstudent::inputCourse(){ for (int i = 0; i < 8; i++) { cin >> keming[i] >> score[i]; }}void Cstudent::displays(){ cout << " " << classname << " " << xuehao << "\n";//输出到屏幕 Cperson::displayP(); ofstream fout; fout.open("学生信息库.txt"); if (!fout) { fout << " " << classname << " " << xuehao << endl; return; }

定义一个CPerson类及其派生类学生类和教师类

9、else {罕铞泱殳 int i; for (i = 0; i < n; i++) cout << chengji[i] << " "; cout << endl; }}void Teacher::sortcore(int n){ cout << "10位学生成绩为:\n"; sort(chengji, chengji + n);}void Teacher::setstuscore(double &s1, int n){ chengji[n] = s1;}void Teacher::display(int n){ Cperson::displayP(); int i; cout << "每个老师" << n << "名学生成绩\n"; for (i = 0; i < n; i++) { cout << chengji[i] << " "; cout << endl; }}Teacher::~Teacher(){}int _tmain(int argc, _TCHAR* argv[]){ Cstudent *ti1 = new Cstudent[10]; int i; for (i = 0; i < 10; i++) { cout << "\n班级名" << " 和 " << "学号\n"; ti1[i].input(); cout << "分别输入每位学生对应的8个课名和课程成绩 例如a90" <<endl; ti1[i].inputCourse(); } for (i = 0; i < 8; i++) ti1[i].displays(); Teacher * ti2 = new Teacher[4]; for (i = 0; i < 4; i++) { ti2[i].input(); ti2[i].setscore(10); } for (i = 0; i <4; i++) ti2[i].display(10); return 0;}

  • 怎么判断用x型区域还是y型区域
  • 学习通视频怎么自动播放
  • 二重积分dxdy怎么算?
  • ∫lnxdx的不定积分解题步骤
  • lnx/x的不定积分怎么求
  • 热门搜索
    调漂方法图解 对联大全 肾阴虚的治疗方法 耳鸣的治疗方法 入党自传怎么写 家常炒菜的做法大全 怎么查看笔记本配置 鸡蛋羹怎么做好吃 核算方式怎么填 最大公约数怎么求