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

📄 ex_initmultobject.cpp

📁 郑阿齐VC教材
💻 CPP
字号:
#include <iostream.h>
class CPoint
{
public:
	CPoint(int x, int y) { 
		nPosX = x;  nPosY = y;	
		cout<<"CPoint类构造函数"<<endl;	// endl是一个输出算子,作用相当于回车换行
	}
	void ShowPos()	{ 
		cout<<"当前位置:x = "<<nPosX<<", y = "<<nPosY<<endl;	
	}
private:
	int nPosX, nPosY;
};
class CSize 
{	
public:
	CSize(int l, int w) { 
		nLength = l;  nWidth = w; 
		cout<<"CSize类构造函数"<<endl;
	}
	void ShowSize()	{ 
		cout<<"当前大小:l = "<<nLength<<", w = "<<nWidth<<endl; 
	}
private:
	int nLength, nWidth;
};
class CRect
{
public:
	CRect(int left, int top, int right, int bottom);
	void Show(){	
		ptCenter.ShowPos();	
		size.ShowSize();	
	}
private:
	CPoint 	ptCenter;
	CSize  	size;
};
CRect::CRect(int left, int top, int right, int bottom)
		:size(right-left, bottom-top),	ptCenter((left+right)/2, (top+bottom)/2)
{  }
void main()
{
	CRect rc(10, 100, 80, 250);
	rc.Show();
}

⌨️ 快捷键说明

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