实验四

/*#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<<"请输入"<for(int i=0;icin>>alist[i];
}

void MyArray::Display()
{
cout<<"显示"<cout<for(int i=0;i{
cout<if(i%6==5)
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;isum=sum+*(alist+1);

}

int main(void)
{
MyArray Dat1;
Dat1.Input();
cout<
Dat1.Display();
cout<cout<
SortArray Dat2(10);
Dat2.Input();
cout<
cout<<"排序前:";
Dat2.Display();
cout<Dat2.Sort();

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"<~building(){cout<<"destructing 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);
}

相关文档
最新文档