实验四
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/*#include"iostream"
#include"conio.h"
using namespace std;
class A{
protected:
private:
int m,n;
public:
void set(int a,int b){
m=a;n=b;
}
void show(){
cout<
};
class B:public A{
int s;
public:
void sets(){
s=m*n;
}
void shows(){
cout<}
};
void main(){
B obj;
obj.set(2,3);
obj.show();
obj.sets();
obj.shows();
getch();
}*/
/*#include
#include
#include
using namespace std;
class MyArray
{
public:
MyArray();
MyArray(int leng);
~MyArray();
void Input();
void Display();
protected:
int* alist;//指向动态申请的一组空间
int length;//整数的个数
};
class SortArray: public MyArray
{
public:
SortArray() : MyArray() {} //必须要增加的
SortArray(int leng) : MyArray(leng) {}//必须要增加的
void Sort();
};
class AverArray: public MyArray{
public:
AverArray(int l): MyArray(l){}
void Aver();
};
MyArray::MyArray()
{
length=4;//默认给4个数据
alist=new int[4];
}
MyArray::MyArray(int leng)
{
if(leng<=0)leng=4;//如果初值不是正整数,给默认给4个数据
length=leng;
alist=new int[leng];
}
MyArray::~MyArray()
{
delete alist;
}
void MyArray::Input()
{
cout<<"请输入"<
}
void MyArray::Display()
{
cout<<"显示"<
cout<
cout<
}
void SortArray::Sort()
{
int temp,i,j;
for(i=length-1;i>0;i--)//经典冒泡排序
{
for(j=0;j{
if( alist[j] < alist[j+1] )
{
temp=alist[j];
alist[j]=alist[j+1];
alist[j+1]=temp;
}
}
}
}
void AverArray:: Aver(){
int i,sum=0;
for(i=0;i
}
int main(void)
{
MyArray Dat1;
Dat1.Input();
cout<
Dat1.Display();
cout<
SortArray Dat2(10);
Dat2.Input();
cout<
cout<<"排序前:";
Dat2.Display();
cout<
cout<<"排序后:";
Dat2.Display();
cout<
return 0;
getch();
}*/
# include
using namespace std;
class building
{
protected:
char name;
int floors;
float areas;
public:
building(){cout<<"constructing building"<
class house:public building{
private:
int rooms;
int balcony;
public:
house(){
cout<<"constructing house"<
void print(int ,int ){
int rooms=50;
int balcony=40;
cout<<
"房间数:"<
};
class office{
private:
int offices;
int meetingrooms;
public:
office(){
cout<<"constructing office"<
void print(int ,int ){
int offices=30;
int meetingrooms=20;
cout<<"办公室数:"<
};
void main(){
house h1;
h1.house::print(50,40);
office o1;
o1.office::print(30,20);
}