2015年C++第三周,任务一:打印个人信息,学生,老师,在职教师

本文展示了一个使用C++实现的学生与教师信息打印程序,包括基本的个人信息打印、学生特定属性打印以及教师的职称和教授课程信息打印。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

任务一:打印个人信息,学生,老师,在职教师

2-11

#include "stdafx.h"

#include<iostream>

#include<string>

using namespacestd;

class person

{

public:

    person(char*n,char*s,inty,intm)

    {

        name =newchar[strlen(n)+ 1];

        strcpy(name,n);

        sex = newchar[strlen(s)+ 1];

        strcpy(sex,s);

        year =y;

        month= m;

    }

    voidprint()

    {

 

        cout<< "姓名:" << name << endl;

        cout<< "性别:" << sex << endl;

        cout<< "出生日期:" << year <<""<< month <<""<< endl;

    }

protected:

    char*name;

    char*sex;

    intyear;

    intmonth;

};

class student:virtualpublicperson

{

public:

    student(char*n,char*s,inty,intm,intN,char*g):person(n,s,y,m)

    {

        NO = N;

        grade= new char[strlen(g)+ 1];

        strcpy(grade,g);

         }

     void print()

     {

         cout << "年级:"<< grade << endl;

        cout<< "学号:" << NO << endl;

        person::print();

     }

protected:

    int  NO;

    char*grade;

};

class studentTeacher:virtualpublicstudent

{

public:

    studentTeacher(char*n,char*s,inty,intm,intN,char*g,char*c):student(n,s,y,m,N,g),person(n,s,y,m)

    {

        course= new char[strlen(c)+ 1];

        strcpy(course,c);

    }

     void print()

     {

        student::print();

        cout<< "教授课程:" << course << endl;

    }

protected:

    char*course;

};

class teacher:virtualpublicperson

{

public:

    teacher(char*n,char*s,inty,intm,char*tchar *c):person(n,s,y,m)

    {

        tile =newchar[strlen(t)+ 1];

        strcpy(tile,t);

        course= new char[strlen(c)+ 1];

        strcpy(course,c);

    }

     void print()

     {

         person::print();

         cout << "职称:"<< tile << endl;

        cout<< "教授课程:" << course << endl;

    }

protected:

    char*tile;

    char*course;

};

void main()

{

    person p("周民","",1993,2);

    student st("张帆","",1993, 12, 14721614,"硕士一年级");

    studentTeacher sT("林勤勤","", 1990, 12, 12721614,"博士一年级","c++程序设计");

    teacher  teac("李宁","",1963,2,"教授","数字化制造");

    cout<< "************************"<< endl;

    p.print();

    cout<<"************************"<<endl;

    st.print();

    cout<< "************************"<< endl;

    sT.print();

    cout<< "************************"<< endl;

    teac.print();

    cout<< "************************"<< endl;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值