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

📄 308.cpp

📁 C++实训教程
💻 CPP
字号:
//308.CPP --
#include <iostream.h>
class R
{
   int x,y;   // x and y are private by default
  public:
   void Set(int InitX, int InitY)
   {x = InitX; y = InitY;}
   int GetX() {return x;}// public member functions
   int GetY() {return y;}
  private:
	int w,h;
  public:
   void Disp()
   { cout << "X="<<x<<" Y="<<y<<endl
		  << " Width= " << w << " Height endl" << h << endl;
   }
   void	Size(int InitW, int InitH);
	Area();
};
void R::Size(int InitW, int InitH)
{w = InitW; h = InitH;}
R::Area()
{ return w*h;}
int main()
{
   R r1,r2,*p;  //两个对象,一个指针
   r1.Set(1,11);
   r1.Size(10,10);
   cout << "对象p1的 x = " << r1.GetX()
		<< "  y = "		<< r1.GetY()
		<< " 面积= "	   << r1.Area()
		<< endl;
   //cout<<x; r1.x=2; 错误!
   r2.Set(200,-200);
   r2.Size(20,20);
   p = &r2;
   cout << "Display new point : "
		<< "x is "   << p->GetX()
		<< "  y is " << p->GetY()
		<< " 面积= " << p->Area()
		<< endl;
   return 0;
}
/*
对象p1的 x = 1  y = 11 面积= 100
Display new point : x is 200  y is -200 面积= 400

*/

⌨️ 快捷键说明

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