摘要:#include<iostream>#include<string>#include<cstdlib>using namespace std;class Box{ public: Box(int h=10,int w=12,int len=15): height(h),width(w),length(len){} int volume(); private: int height; int wid...
阅读全文
摘要:#include<iostream>#include<string>#include<cstdlib>using namespace std;class student{ public: //定义构造函数,带参数的构造函数 //方法1 /* student(int n,string nam,char s) { num=n; name=nam; sex=s; cout<<"Constructor c...
阅读全文
摘要://构造函数的重载#include<iostream>using namespace std;class Box{ //两个构造函数 public: Box();//一个无参数 ,在函数体中对其私有数据成员赋值 Box(int h,int w,int len):height(h),width(w),length(len){}//第二个构造函数直接在类体的的定义中,参数初始化 int volume(...
阅读全文
摘要:#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
阅读全文
摘要:#include<iostream>#include<string>using namespace std;/*类并不是一个实体,而是一种投象数据类型,并不占存储空间,显然无处容纳。*//*对像的初始化,构造函数,与类名相同*/class Time{ public : //构造函数,功能由自己定义 Time( ) { hour=0; minute=0; sec=0; } void set(); ...
阅读全文
摘要:1.类声明和成员函数的分离 在一个工程里面,头文件包含类的声明。另一个文件定义类成员函数。 最后还有一个主函数的文件。 //student.cpp,类成员函数的定义 #include<iostream>#include"student.h"using namespace std;void student::display( ){ cout<<num<<endl; cout<<name<<end...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文