标题:刚学C++帮忙分析一下
取消只看楼主
梁朝斌
Rank: 4
等 级:业余侠客
帖 子:192
专家分:288
注 册:2012-10-21
结帖率:100%
已结贴  问题点数:100 回复次数:0 
刚学C++帮忙分析一下
#include <iostream.h>
#include <string.h>
class person
{
protected:
    char name[20];
    int sex;
    int    age;
public:
    Person(char *na,int ag,int  se)
    {
        strcpy(name, na);
        sex= se;
        age = ag;
    }
    void initname(char *na)
    {
        strcpy(name, na);
    }

    void initsex(int se)
    {
        sex=se;
    }

    void initage(int ag)
    {
        age=ag;
    }

    char * getname()
    {
        return name;
    }

    int getage()
    {
        return age;
    }

    int getsex()
    {
        return sex;
    }

    void printf()
    {
        cout<<"姓名:"<<name<<endl;
        cout<<"性别:"<<sex<<endl;
        cout<<"年龄:"<<age<<endl;
    }
};
class teacher:public person
{
    int post;
    int  salary;
public:
    teacher(char *na,int ag,int se,int po,int sa):person(na,ag,se)
    {
        post=po;
        salary=sa;
    }
    void printf()
    {
        person::printf();
        cout<<"职位:"<<post<<endl;
        cout<<"工资:"<<salary<<endl;
    }
};
class student:public person
{
    char xuehao[20];
    char Class[20];
public:
    student(char *na,int ag,int se,char *xh,char *cl):person(na,ag,se)
    {
        strcoy(xuehao,xh);
        strcpy(Class,cl);
    }
    printf()
    {
        person::printf();
        cout<<"学号:"<<xuehao<<endl;
        cout<<"班级:"<<Class<<endl;
    }
};
void main()
{
    teacher te("liang",22,男,教授,5000);
    student st("liang",22,男,"20112111225","11B");
    te.printf();
    cout<<"__________________"<<endl;
    st.printf();
}
        

搜索更多相关主题的帖子: void include person public return 
2013-04-24 21:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-405419-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049912 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved