| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 879 人关注过本帖
标题:急!求助:帮忙写个程序 小弟我刚学C++~谢谢哥姐了!
取消只看楼主 加入收藏
bester214
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-10-21
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
急!求助:帮忙写个程序 小弟我刚学C++~谢谢哥姐了!
设计一个虚基类base,里面有姓名、年龄私有数据成员,派生出领导类leader,里面有职务,部门私有数据成员,由base类派生出工程师类engineer,里面有职称,专业私有数据成员,再由leader和engineer类共同派生出主任工程师类chairman。 最后主函数用个例子初始化就好了。 逻辑结构是个菱形的结构!

谢谢了!

小弟在等~~~~~~~~~~~~
搜索更多相关主题的帖子: 数据 engineer leader 
2009-11-12 20:28
bester214
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-10-21
收藏
得分:0 
#include <iostream>
#include<cstring>
using namespace std;
class base
{
    int age;
    char* name;
public:
    base(int a,char* na)
    {
        age=a;
        name=new char[strlen(na)+1];
        strcpy (name,na);
    }

~base(){}
delete char;
};

class leader:virtual public  base
{
    char* zhiwei;
    char* depart;
public:
    leader(na,a,char* zhi,char* dep)
    {
        zhi=new char[strlen(zhi)+1];
        strcpy (zhiwei,zhi);
        dep=new char[strlen(dep)+1];
        strcpy (depart,dep);
    }

~leader(){}
delete char;
};

class engineer:virtual public base
{
    char* zhicheng;
    char* career;
public:
    engineer(na,a,char*zhic,char* car);
    {
        zhic=new char[strlen(zhic)+1];
        strcpy (zhicheng,zhic);
        car=new char[strlen(car)+1];
        strcpy(career,car);
    }
~engineer(){}
delete char;
};

class chairman:public leader,public engineer
{
public:
    chairman(na,a,char*zhi,char*dep,char*zhic,char*car)
};

int main()
{

}
 
我自己只能写到这样的 期中关于zhic=new char[strlen(zhic)+1];
        strcpy (zhicheng,zhic);
        car=new char[strlen(car)+1];
        strcpy(career,car);  我自己搞不清楚 还有在chairman类写不来 还有int main主函数写不出

救命啊~ 帮我改好了 当然结分啦~ 小弟谢过了
2009-11-12 22:34
bester214
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-10-21
收藏
得分:0 
#include <iostream>
#include<cstring>
using namespace std;
class base
{
    int age;
    char* name;
public:
    base(int a,char* na)
    {
        age=a;
        name=new char[strlen(na)+1];
        strcpy (name,na);
    }

    virtual void display()=0;
~base(){}
//delete char;
};

class leader:virtual public  base
{
    char* zhiwei;
    char* depart;
public:
    leader(na,a,char* zhi,char* dep):base(a,na)
    {
        zhi=new char[strlen(zhi)+1];
        strcpy (zhiwei,zhi);
        dep=new char[strlen(dep)+1];
        strcpy (depart,dep);
    }
void display()
{
cout<<"姓名"<<name<<"年龄"<<age<<"职位"<<zhiwei<<"部门"<<depart<<endl;
}

~leader(){}
//delete char;
};

class engineer:virtual public base
{
    char* zhicheng;
    char* career;
public:
    engineer(na,a,char* zhic,char* car):base(a,na)
    {
        zhic=new char[strlen(zhic)+1];
        strcpy (zhicheng,zhic);
        car=new char[strlen(car)+1];
        strcpy(career,car);
    }
    void display()
    {
        cout<<"姓名"<<name<<"年龄"<<age<<"职称"<<zhicheng<<"职业"<<career<<endl;
    }
~engineer(){}
//delete char;
};

class chairman:public leader,public engineer
{
public:
    chairman(int a,char* na,char* zhi,char* dep,char* zhic,char* car):leader(a,na,zhi,dep),engineer(zhic,car){}
void display()
{
      cout<<"姓名"<<name<<"年龄"<<age<<"职称"<<zhicheng<<"职业"<<career<<"职位"<<zhiwei<<"部门"<<depart<<endl;
}
};

void main()
{
   
    leader L("三弟",28,"书记","团委");
    L.display();
    engineer e("二哥",29,"助教","电子工程");
    e.display();
    chairman c("一哥",40,"主任","电子工程","教授","办公室");
    c.display();

}

这样子了 调试通不过 还是很多 错的 怎么改呢?
2009-11-13 16:25
快速回复:急!求助:帮忙写个程序 小弟我刚学C++~谢谢哥姐了!
数据加载中...
 
   



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

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