2011年6月8日

构造函数的重载

摘要: //构造函数的重载#include<iostream>using namespace std;class Box{ //两个构造函数 public: Box();//一个无参数 ,在函数体中对其私有数据成员赋值 Box(int h,int w,int len):height(h),width(w),length(len){}//第二个构造函数直接在类体的的定义中,参数初始化 int volume(... 阅读全文

posted @ 2011-06-08 23:11 more think, more gains 阅读(264) 评论(0) 推荐(0) 编辑

带参数的构造函数

摘要: #include<iostream>#include<string>#include<cstdlib>using namespace std;class Box{ public: Box(int,int,int); int volume(); private: int height; int width; int length;};Box::Box(int x,int y,int z){ height=x; width=y; length=z;}int Box::volume( ){ return (height*width*length);}int mai 阅读全文

posted @ 2011-06-08 22:32 more think, more gains 阅读(263) 评论(0) 推荐(0) 编辑

不带参的构造函数

摘要: #include<iostream>#include<string>using namespace std;/*类并不是一个实体,而是一种投象数据类型,并不占存储空间,显然无处容纳。*//*对像的初始化,构造函数,与类名相同*/class Time{ public : //构造函数,功能由自己定义 Time( ) { hour=0; minute=0; sec=0; } void set(); ... 阅读全文

posted @ 2011-06-08 22:25 more think, more gains 阅读(391) 评论(0) 推荐(0) 编辑

类的封装性与隐敝性

摘要: 1.类声明和成员函数的分离 在一个工程里面,头文件包含类的声明。另一个文件定义类成员函数。 最后还有一个主函数的文件。 //student.cpp,类成员函数的定义 #include<iostream>#include"student.h"using namespace std;void student::display( ){ cout<<num<<endl; cout<<name<<end... 阅读全文

posted @ 2011-06-08 22:03 more think, more gains 阅读(348) 评论(0) 推荐(0) 编辑

c++ 类的学习2

摘要: #include<iostream>#include<stdlib.h>#include<string>using namespace std;class Time{ public: void set_time(); //公有成员函数,声明函数 void show_time();//公有成员函数,声明函数 private: int hour; int minute; int sec;};int m... 阅读全文

posted @ 2011-06-08 21:40 more think, more gains 阅读(160) 评论(0) 推荐(0) 编辑

c++类的学习

摘要: #include<iostream>#include<stdlib.h>#include<string>#include<time.h>using namespace std;class Array{ public: void set(); void show(); void find(); void allshow(); private: int max; int array[1000];};v... 阅读全文

posted @ 2011-06-08 21:39 more think, more gains 阅读(188) 评论(0) 推荐(0) 编辑

导航