l10_6.cpp

来自「《C++程序设计教程》电子教案及例题源码」· C++ 代码 · 共 50 行

CPP
50
字号
#include<iostream.h>
# include <fstream.h>
#include<string.h>
class CRect
{
private:
	char color[10];
	int left;
	int top;
	int length;
	int width;
public:
	void SetColor(char *c);
	void SetSize(int l, int w);
	void Move(int t,int l);
	void Draw();
};
void CRect::SetColor(char *c)
{
	strcpy(color, c);
}
void CRect::SetSize(int l, int w)
{
	length=l;
	width = w;
}
void CRect::Move(int t,int l)
{
	top = t;
	left = l;
}
void CRect::Draw()
{
	cout << "矩形左上角坐标为(" << left << "," << top << ")" << endl;
	cout << "矩形长和宽分别为" << length << "," << width << endl;
	cout << "矩形的颜色是" << color << endl;
}


void main()
{
	CRect r;                      
	r.SetColor("Red");
	r.Move(10,20);
	r.SetSize(100,200);
	ofstream  outfile("D:\\a.txt" , ios::out);
	outfile.write( (char *) &r , sizeof(r) );
	outfile.close();
}

⌨️ 快捷键说明

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