高级函数.cpp

来自「C++编写的程序源码,里有21天学通C++的课后作业源码和章节源码.」· C++ 代码 · 共 43 行

CPP
43
字号
#include<iostream>
using namespace std;
class rectangle
{
public:
	rectangle(int width,int height);
	~rectangle(){}
	void drawshape()const;
    void drawshape(int awidth,int aheight)const;
private:
	int itswidth;
	int itsheight;
};
rectangle::rectangle(int width,int height)
{
	itswidth=width;
	itsheight=height;
}
void rectangle::drawshape()const
{
	drawshape(itswidth,itsheight);
}
void rectangle::drawshape (int width,int height)const
{
	for(int i=0;i<height;i++)
	{
		for(int j=0;j<width;j++)
			cout<<"*";
		cout<<endl;
	}
}
int main()
{
	rectangle therect(30,5);
	cout<<"drawshape():\n";
	therect.drawshape ();
	cout<<"\ndrawshape (40,2):\n";
	therect.drawshape (40,2);
	return 0;
}

 

⌨️ 快捷键说明

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