object01.cpp

来自「在c环境下的对数据结构进行讲解,包含有例题及答案」· C++ 代码 · 共 25 行

CPP
25
字号
 //object01.cpp
 #include <iostream.h>
 #include <conio.h>
 class  date						//类名称
 { private:						//局部
     unsigned int year,month,day;
   public:						//公共
     void set_date(int _year,int _month,int _day)	//自外界取得数据
     { year = _year;				//函数主体,将外部传入的数据设置给
       month = _month;			//数据成员
       day = _day;
     }
     void list_date()				//将数据输出
     { cout << "year="<<year<<endl		//函数主体,输出数据成员
           << "month="<<month<<endl
           << "day="<<day<<endl;
     }
 };
 void main()
 { date mybirth;					//对象声明
   mybirth.set_date(1970,12,5);		//调用成员函数并传数据
   mybirth.list_date();				//调用列出数据
   getch();
 }

⌨️ 快捷键说明

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