电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

c 实验8 继承与派生上机练习题

c  实验8 继承与派生上机练习题_第1页
1/6
c  实验8 继承与派生上机练习题_第2页
2/6
c  实验8 继承与派生上机练习题_第3页
3/6
1. 定义一个哺乳动物类 Mammal,并从中派生出一个狗类 Dog,下面给出 Mammal 类得定义,要求:(1)添加 Dog 类得颜色数据成员,访问属性为私有,通过 SetColor 与 GetColor 成员函数来对颜色进行设置与猎取。(2)分别为基类与派生类添加相应得构造函数(有参、无参)与析构函数,并进行测试。class Mammal{protected:int itsAge;int itsWeight;public:int GetAge{return itsAge;}void SetAge(int age) {itsAge=age;}int GetWeight { return itsWeight;}void SetWeight(int weight) {itsWeight= weight;} };class Dog : public Mammal{//定义 Dog 类得数据成员与成员函数};改:#include #include using namespace std;class Mammal{protected:int itsAge;int itsWeight;public:Mammal;~Mammal;int GetAge{return itsAge;}void SetAge(int age) {itsAge=age;}int GetWeight { return itsWeight;}void SetWeight(int weight) {itsWeight= weight;} };class Dog : public Mammal{protected:char itscolor[20];public:Dog;void Setcolor(char *color) {strcpy(itscolor,color);} void getcolor{cout<<"狗得颜色"<>age1;SetAge(age1);cout<<"请输入动物得体重:"<>weight1;SetWeight(weight1);}Mammal::~Mammal{cout<<"Destructor called、"<>color;Setcolor(color);cout<<"狗得颜色"<

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

c 实验8 继承与派生上机练习题

确认删除?
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群