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

📄 第一章8.txt

📁 本书在复习C++基础知识后
💻 TXT
字号:
#include <iostream.h>
class CPoint
{
public:
		CPoint( int x = 0, int y = 0)					// C
		{
			xPos = x;	yPos = y;
			cout<<"CPoint构造函数"<<endl;
		}
		void ShowPos(bool isEnd = false)
		{
			cout<<"pos("<<xPos<<", "<<yPos<<")";
			if (isEnd)	cout<<endl;
		}
private:
		int xPos, yPos;
};
class CRect
{
public:
		CRect( int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0)	// B
			: ptLT(x1, y1), ptRB(x2, y2)
		{
			cout<<"CRect构造函数"<<endl;
		}
		void ShowPos()
		{
			ptLT.ShowPos();	 cout<<", ";	 ptRB.ShowPos(true);
		}
private:
		CPoint ptLT, ptRB;
};
class CCuboid: public CRect
{
public:
		CCuboid( int x1, int y1, int x2, int y2, int height )	// A
			: CRect(x1, y1, x2, y2),
			ptCenter((x1+x2)/2, (y1+y2)/2),
			fHeight(height)
		{
			cout<<"CCuboid构造函数"<<endl;
		}
		void ShowAll()
		{
			cout<<"矩形的角点为:";			CRect::ShowPos();
			cout<<"底面矩形的中点为:";		ptCenter.ShowPos(true);
			cout<<"高为:"<<fHeight<<endl;
		}
private:
		CPoint	ptCenter;
		float		fHeight;
};
int main()
{
		CCuboid one( 5, 5, 30, 30, 50);
		one.ShowAll();
		return 0;
}

⌨️ 快捷键说明

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