fig5_9.cpp.bak

来自「用三个类来研究类的继承!类Point、Circle、Cylinder」· BAK 代码 · 共 37 行

BAK
37
字号
//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 + =
减小字号Ctrl + -
显示快捷键?