大家帮忙看一下,为什么参数没有传入

lllwwjj123 lllwwjj123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

//4、定义一个基类Person,从它派生出类Student和类Worker,再由类Student和Worker共同派生出WorStu。
//类Person的属性有姓名、年龄、性别,操作有设置姓名、年龄、性别和显示信息等。类Student的属性增加
//系别、专业和学号属性及相应的操作。类Worker新增部门和工作属性及相应操作。在主函数中声明一个
//WorStu最远派生类的对象,显示相关信息。

#include <iostream>
using namespace std;

class Person
{
public:
Person(){}
~Person(){}
void set_name(string);
void set_age(int);
void set_sex(string);
string show_name(){return name ;}
int show_age(){return age ;}
string show_sex(){return sex ;}
void display();
protected:
string name ;
int age ;
string sex ;
};
class Student:virtual public Person
{
public:
Student(){}
~Student(){}
void set_department(string);
void set_major(string) ;
void set_id(long) ;
string show_department(){return department ;}
string show_major(){return major ;}
long show_id(){return id ;}
protected:
string department ;
string major ;
long id ;
};
class Worker:virtual public Person
{
public:
Worker(){}
~Worker(){}
void set_section(string) ;
void set_job(string);
string show_section(){return section ;}
string show_job(){return job ;}
protected:
string section ;
string job ;
};

class WoeStu:public Student ,public Worker
{
public:
void show() ;
};
void Person::set_name(string a)
{
name = a ;
}
void Person::set_age(int a)
{
age = a ;

}
void Person::set_sex(string a)
{
sex = a ;
}
void Person::display()
{
cout<<"name:\n";
show_name();
cout<<"age:\n";
show_age();
cout<<"sex:\n";
show_sex();
}
void Student::set_department(string a )
{
department = a ;
}
void Student::set_major(string a)
{
major = a ;
}
void Student::set_id(long a)
{
id = a ;
}
void Worker::set_section(string a)
{
section = a ;
}
void Worker::set_job(string a )
{
job = a ;
}
void WoeStu::show()
{
display();
cout<<"department:\n";
show_department();
cout<<"major:\n";
show_major();
cout<<"id:\n";
show_id();
cout<<"section:\n";
show_section();
cout<<"job:\n";
show_job();
}

int main()
{
WoeStu WS ;
WS.set_name("Tom");
WS.set_age(25);
WS.set_sex("man");
WS.set_department("computer science ");
WS.set_major("Computer Science and Technology");
WS.set_id(11320088);
WS.set_section("export");
WS.set_job("sales");
WS.show();
return 0 ;
}

主函数参数没有起作用.
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
lllwwjj123
C++ 语言 65,214 成员 250,514 内容