1701H2 10.25 王建瑜 连续第二天

来源:互联网 发布:淘宝cpc是什么意思 编辑:程序博客网 时间:2024/06/05 23:57

复习c++输入输出方式,又看了一遍类和对象,做了一次练习。学到“.”和"->"这两个符号,class定义类时   {  }  后要加";",明日继续学习视频,复习。

#include<stdlib.h>
#include<iostream>
using namespace std;

class Coordinate
{
 public:
  int x;
  int y;
  void printX()
  {
   cout<<x<<endl;
  }
  void printY()
  {
   cout<<y<<endl;
  }
};
int main(void)
{
    Coordinate coor;
 coor.x=50;
 coor.y=20;
 coor.printX();
 coor.printY();
 
 Coordinate *p=new Coordinate();
 if(NULL==p)
 {
 //failed
 return 0;
 }
  p->x=100;
 p->y=200;
 p->printX();
 p->printY();
 delete p;
 p=NULL;
 
 system("pause");
 return 0;
}

原创粉丝点击