| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1791 人关注过本帖
标题:求大佬给萌新参考参考
只看楼主 加入收藏
wangmou
Rank: 2
等 级:新手上路
威 望:3
帖 子:6
专家分:0
注 册:2019-10-17
收藏
 问题点数:0 回复次数:3 
求大佬给萌新参考参考
定义人员信息Ddta_Rec类是Employee类和Student类的虚基类,包括数据成员姓名和ID号。在该类基础上派生Employee类(增加部门,工资)和Student类(增加专业,学号,总成绩),在Employee类基础上派生Teacher类(增加简历);在Employee和Student基础上派生E_Student类(增加薪酬)。成员函数输出每一类人员的基本信息。
有没有大佬看看这题,能让萌新参考参考。
搜索更多相关主题的帖子: Employee 基础 派生 增加 Student 
2019-10-17 22:17
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9024
专家分:54030
注 册:2011-1-18
收藏
得分:0 
程序代码:
class Ddta_Rec
{
    姓名类型 姓名;
    ID类型 ID;

    返回类型 输出基本信息() const = 0;
};

class Employee : virtual public Ddta_Rec
{
    部门类型 部门;
    工资类型 工资;

    返回类型 输出基本信息() const
    {
        噼里啪啦;
    };
};

class Student : virtual public Ddta_Rec
{
    专业类型 专业;
    学号类型 学号;
    成绩类型 成绩;

    返回类型 输出基本信息() const
    {
        噼里啪啦;
    };
};

class Teacher : public Employee
{
    简历类型 简历;

    返回类型 输出基本信息() const
    {
        噼里啪啦;
    };
};

class E_Student : public Employee, public Student
{
    薪酬类型 薪酬;

    返回类型 输出基本信息() const
    {
        噼里啪啦;
    };
};
2019-10-18 09:09
wangmou
Rank: 2
等 级:新手上路
威 望:3
帖 子:6
专家分:0
注 册:2019-10-17
收藏
得分:0 
#include<stdarg.h>
#include<iostream>
#include<string>
using namespace std;

class Data_Rec
{
protected:
    string n_name;
    int i_ID;
public:
    Data_Rec(string,int);   
   
};
Data_Rec::Data_Rec(string name,int ID):n_name(name),i_ID(ID){}


class Employee:virtual public Data_Rec
{
protected:
    char *d_department;
    int s_salary;
public:
    Employee(string name,int ID,char *dep,int salary);
    void output();
};
Employee::Employee(string name,int ID,char *dep,int salary):Data_Rec(name,ID),d_department(dep),s_salary(salary){}
        
void Employee::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n部门\t"<<d_department<<"\n工资\t"<<s_salary<<endl;
}


class Student:virtual public Data_Rec
{
protected:
     string m_major;
     int s_sno;
     int s_scare;
public:
    Student(string name,int ID,string major,int sno,int scare);
    void output();
};
Student::Student(string name,int ID,string major,int sno,int scare):Data_Rec(name,ID),m_major(major),s_sno(sno),s_scare(scare){}

void Student::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n专业\t"<<m_major<<"\n学号\t"<<s_sno<<"\n总成绩\t"<<s_scare<<endl;
}

class Teacher:public Employee
{
protected:
    string r_resume;
public:
    Teacher(string name,int ID,char *dep,int salary,string resume);
    void output();
};
Teacher::Teacher(string name,int ID,char *dep,int salary,string resume):Data_Rec(name,ID),Employee(name,ID,dep,salary),r_resume(resume){}

void Teacher::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n部门\t"<<d_department<<"\n工资\t"<<"简历"<<r_resume<<endl;
}


class E_Student:public Employee,public Student
{
protected:
    int Increase_salary;
public:
    E_Student(string name,int ID,char *dep,int salary,string major,int sno,int scare,int In);
    void output();
};
E_Student::E_Student(string name,int ID,char *dep,int salary,string major,int sno,int scare,int In):Data_Rec(name,ID),Employee(name,ID,dep,salary),Student(name,ID,major,sno,scare),Increase_salary(In){}

void E_Student::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n部门\t"<<d_department<<"\n工资\t"<<s_salary<<"\n专业\t"<<m_major<<"\n学号\t"<<s_sno<<"\n总成绩\t"<<s_scare<<"\n增加薪酬\t"<<Increase_salary<<endl;
}


void main()
{
        Teacher te1("math",001,"信工学院",30000,"我是数学老师,毕业于北京大学");
    Teacher te2("engliseh",002,"信工学院",30000,"我是英语老师,毕业于清华大学");
    Teacher te3("c++",003,"信工学院",30000,"我是c++老师,毕业于电子科技大学");
    Teacher te4("map",004,"信工学院",30000,"我是地图学老师,毕业于中国地质大学");
                    te1.output();
                    te2.output();
        te3.output();
        te4.output();
    E_Student e1("a",005,"信工学院",0,"地理空间信息工程",1,720,0);
    E_Student e2("b",006,"信工学院",10000,"地理空间信息工程",1,1000,3000);
            e1.output();
        e2.output();
}
这样写前面的cout好像没用,重复了,怎末一级一级的输出,而不是在最后输出。
2019-10-29 21:17
wangmou
Rank: 2
等 级:新手上路
威 望:3
帖 子:6
专家分:0
注 册:2019-10-17
收藏
得分:0 
回复 2楼 rjsp
#include<stdarg.h>
#include<iostream>
#include<string>
using namespace std;

class Data_Rec
{
protected:
    string n_name;
    int i_ID;
public:
    Data_Rec(string,int);   
   
};
Data_Rec::Data_Rec(string name,int ID):n_name(name),i_ID(ID){}


class Employee:virtual public Data_Rec
{
protected:
    char *d_department;
    int s_salary;
public:
    Employee(string name,int ID,char *dep,int salary);
    void output();
};
Employee::Employee(string name,int ID,char *dep,int salary):Data_Rec(name,ID),d_department(dep),s_salary(salary){}
        
void Employee::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n部门\t"<<d_department<<"\n工资\t"<<s_salary<<endl;
}


class Student:virtual public Data_Rec
{
protected:
     string m_major;
     int s_sno;
     int s_scare;
public:
    Student(string name,int ID,string major,int sno,int scare);
    void output();
};
Student::Student(string name,int ID,string major,int sno,int scare):Data_Rec(name,ID),m_major(major),s_sno(sno),s_scare(scare){}

void Student::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n专业\t"<<m_major<<"\n学号\t"<<s_sno<<"\n总成绩\t"<<s_scare<<endl;
}

class Teacher:public Employee
{
protected:
    string r_resume;
public:
    Teacher(string name,int ID,char *dep,int salary,string resume);
    void output();
};
Teacher::Teacher(string name,int ID,char *dep,int salary,string resume):Data_Rec(name,ID),Employee(name,ID,dep,salary),r_resume(resume){}

void Teacher::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n部门\t"<<d_department<<"\n工资\t"<<"简历"<<r_resume<<endl;
}


class E_Student:public Employee,public Student
{
protected:
    int Increase_salary;
public:
    E_Student(string name,int ID,char *dep,int salary,string major,int sno,int scare,int In);
    void output();
};
E_Student::E_Student(string name,int ID,char *dep,int salary,string major,int sno,int scare,int In):Data_Rec(name,ID),Employee(name,ID,dep,salary),Student(name,ID,major,sno,scare),Increase_salary(In){}

void E_Student::output()
{
    cout<<"姓名 \t"<<n_name<<"\nID\t"<<i_ID<<"\n部门\t"<<d_department<<"\n工资\t"<<s_salary<<"\n专业\t"<<m_major<<"\n学号\t"<<s_sno<<"\n总成绩\t"<<s_scare<<"\n增加薪酬\t"<<Increase_salary<<endl;
}


void main()
{
        Teacher te1("math",001,"信工学院",30000,"我是数学老师,毕业于北京大学");
    Teacher te2("engliseh",002,"信工学院",30000,"我是英语老师,毕业于清华大学");
    Teacher te3("c++",003,"信工学院",30000,"我是c++老师,毕业于电子科技大学");
    Teacher te4("map",004,"信工学院",30000,"我是地图学老师,毕业于中国地质大学");
                    te1.output();
                    te2.output();
        te3.output();
        te4.output();
    E_Student e1("a",005,"信工学院",0,"地理空间信息工程",1,720,0);
    E_Student e2("b",006,"信工学院",10000,"地理空间信息工程",1,1000,3000);
            e1.output();
        e2.output();
}
这样写前面的cout好像没用,重复了,怎末一级一级的输出,而不是在最后输出。
2019-10-29 21:46
快速回复:求大佬给萌新参考参考
数据加载中...
 
   



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

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