⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog6.cpp

📁 C++语言程序设计题典
💻 CPP
字号:
#include <iostream.h>
class Cat
{
public:
	Cat();
	Cat(const Cat&);
	~Cat();
	int getage() const { return *itsage; }
	void setage(int age) { *itsage=age; }
protected:
	int *itsage;
};
Cat::Cat()
{
	itsage=new int;
	*itsage=5;
}
Cat::Cat(const Cat& c)
{
	itsage=new int;
	*itsage=*c.itsage;
}
Cat::~Cat()
{
	delete itsage;
	itsage=0;
}
void main()
{
	Cat frisky;
	cout << "frisky's age:" << frisky.getage() << endl;
    cout << "setting frisky to 6...\n";
	frisky.setage(6);
	cout << "creating boots from frisky\n";
	Cat boots(frisky);
	cout << "frisky's age:" << frisky.getage() << endl;
	cout << "boots'age:" << boots.getage() << endl;
	cout << "setting frisky to 7...\n";
	frisky.setage(7);
	cout << "frisky's age:" << frisky.getage() << endl;
	cout << "boots'age:" << boots.getage() << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -