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

📄 303.cpp

📁 C++实训教程
💻 CPP
字号:
/*
	303.cpp
	Written By S.Y.Feng
	demo a simple Point class
*/
#include <iostream.h>

class Point // define Point class
{
	int x;   // x and y are private by default
	int y;
  public:
	void Set(int InitX, int InitY)	{	x = InitX; y = InitY;}
	int GetX() {return x;}// public member functions
	int GetY() {return y;}
};

int main()
{
	Point p1,p2;  //两个对象
	p1.Set(1,11);
	cout << "对象p1的 x ="<< p1.GetX()
		 << "  y = "      << p1.GetY()	<< endl;
	//cout<<x; p1.x=2; 错误!
	p2.Set(200,-200);
	cout << "Display new point : "
		<< "x is "   << p2.GetX()
		<< "  y is " << p2.GetY() 	<< endl;
	return 0;
}
/* ok
对象p1的 x =1  y = 11
Display new point : x is 200  y is -200

*/

⌨️ 快捷键说明

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