00022.cpp

来自「通过一些基础的程序」· C++ 代码 · 共 38 行

CPP
38
字号
/*
名称编号:00022
实现功能:矩形类完全模块化
运行结果:通过
*/
/***************************************************************************/
#include <iostream.h>
//声明矩形类
class Square
{
 public:
    void setdata(int NewL,int NewW);
    void showdata();
 private:
    int Length,Wide;
};
//获取长宽函数的实现
void Square::setdata(int NewL,int NewW)
{Length=NewL;
 Wide=NewW;
}
//内联函数实现显示功能
inline void Square::showdata()
{
	cout<<"The area of the Square S="
		<<Length<<'*'<<Wide<<"="
		<<Length*Wide<<endl;
}
void main()
{
	Square Area;
	int NewL,NewW;
	cout<<"Please enter the L&W:"<<endl;
	cin>>NewL>>NewW;
	Area.setdata(NewL,NewW);
	Area.showdata();
}
/***************************************************************************/

⌨️ 快捷键说明

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