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

📄 fig5_9.cpp.bak

📁 用三个类来研究类的继承!类Point、Circle、Cylinder
💻 BAK
字号:
//fig5_9.cpp
//类Cylinder的测试程序
#include <iostream.h>
#include <assert.h>
#include <iomanip.h>
#include "cylinder2.h"

main()
{
	//建立类Cylinder对象的实例
	Cylinder cy1(5.7, 2.5, 1.2, 2.3);

	//用"get"函数显示圆柱体的信息
	cout<<"X coodinate is "<<cy1.getX()
		<<"\nY coodinate is "<<cy1.getY()
		<<"\nRadius is "<<cy1.getRadius()
		<<"\nHeight is "<<cy1.getHeight();

	//用"set"函数修改圆柱体的属性
	cy1.setHeight(10);
	cy1.setRadius(4.25);
	cy1.setPoint(2, 2);

	cout<<"\n\nThe new location, radius, and height of cy1 are: \n"
		<<cy1<<endl<<"Area: "<<cy1.area()<<"Volume: "<<cy1.volume();

	//把圆柱体当作点对象显示
	Point &pRef=cy1;	//pRef "以为" cy1是一个点
	cout<<"\n\nCylinder printed as a point is: "<<pRef;

	//把圆柱体当作圆对象显示
	Circle &cRef=cy1;	//cRef "以为" cy1是一个圆
	cout<<"\n\nCylinder printed as a circle is: "<<cRef
		<<"\nArea: "<<cRef.area()<<endl;

	return 0;
}

⌨️ 快捷键说明

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