📄 练习.txt
字号:
15.1
#include <iostream.h>
class Plant
{
public:
Plant(int a=10)
{
cout<<"in constructing"<<endl;
priV=a;
pubV++;
cout<<"pubV:"<<pubV<<endl;
}
void Display();
static void Dis_sta();
~Plant()
{
cout<<"destruct class "<<priV<<endl;
cout<<"befoer destruction,pubV:"<<pubV<<endl;
pubV--;
cout<<"after destruction,pubV:"<<pubV<<endl;
}
protected:
int priV;
static int pubV;
};
int Plant::pubV = 0;
void Plant::Dis_sta()
{
cout<<pubV<<endl;
}
void Plant::Display()
{
cout<<"priV:"<<priV<<endl;
}
void main()
{
Plant c1(5);
c1.Display();
cout<<"----------------------"<<endl;
Plant c2;
c2.Display();
cout<<"----------------------"<<endl;
Plant c3(15);
c3.Display();
cout<<"----------------------"<<endl;
}
15.2
#include <iostream.h>
class Animal
{
public:
void SetValue(int);
void SetValue(int,int);
protected:
int itsWeight;
int itsAge;
};
void Animal::SetValue(int tw)
{
itsWeight=tw;
cout<<"weight:"<<itsWeight<<endl;
}
void Animal::SetValue(int tw,int tn)
{
itsWeight=tw;
itsAge=tn;
cout<<"weight:"<<itsWeight<<","
<<"age:"<<itsAge<<endl;
}
void main()
{
Animal peppy;
peppy.SetValue(5);
peppy.SetValue(7,9);
}
15.3
#include <iostream.h>
#include <math.h>
class Boat;
class Car
{
public:
Car(int j) {size=j;}
float Leisure(int time)
{
return float(sqrt(time))*size;
}
int get()
{
return size;
}
protected:
int size;
};
class Boat
{
public:
Boat(int j) {size=j;};
float Leisure(int time)
{
return float(sqrt(time))*size;
}
int get()
{
return size;
}
protected:
int size;
};
void main()
{
Car c1(2);
Boat b1(3);
int time=22;
cout<<c1.Leisure(time)*b1.Leisure(time)<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -