[SOLVED] 代写 Inheritance Lab :

30 $

File Name: 代写_Inheritance_Lab_:.zip
File Size: 226.08 KB

SKU: 4409383492 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Inheritance Lab :

派生类与继承

1.1 实验目的和要求
(1) 掌握派生类的声明方法和派生类构造函数的定义方法。
(2) 掌握不同继承方式下,基类成员在派生类中的访问属性。
(3) 掌握在继承方式下,构造函数与析构函数的执行顺序与构造规则。
1.2 实验内容与步骤·

1.输入下列程序。

//test4_1.cpp
#include using namespace std; class Base{
public:
void setx(int i)
{x=i;}
Int getx()
{return x;} public:
int x;
};
class Derived:public Base{ public:
void sety(int i)
{y=i;}
int gety()
{return y;} void show()
{cout<<”Base::x=”<
#include using namespace std; class MyArray
{
public: MyArray(int leng);
~MyArray{}; void Input();
void Display(string); protected:
int*alist; int length;
};
MyArray::MyArray(int leng)
{
if(leng<=0){cout<<”error length”; exit(1);}alist=new int [leng]; length=leng; if(alist==NULL){cout<<”assign failure”; exit(1);}cout<<”MyArray类对象已创建。”< >*p;
}
int main()
{
MyArray a(5); a.Input();
a.Display(“显示已输入的”);
return 0;
}
(2) 声明一个派生类 SortArray ,它继承类 MyArray。 在该类中定义一个函数,具有将输入的整数从
小到大进行排序的功能。
【提示】
在第 1 步的基础上可增加下面的参考框架:
class SortArray : public MyArray

{
public:
void Sort();
SortArray(int leng):MyArray(leng)
{
cout<<”SortArray类对象已创建。”<

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 Inheritance Lab :
30 $