2018年6月29日

摘要: 1 //设计一个double类型的数组Array 2 //1.可定义下界下标和上届上标 3 //2.可对下标越界进行检查 4 //3.可重置数组大小 5 //4.可知道数组的长度 6 //5.数组类的对象可以使用赋值运算符=和下标运算符[] 7 8 #include 9 #include 10 class Array{ 11 privat... 阅读全文
posted @ 2018-06-29 19:11 孙悟空son_ku_kong 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 1 //设计运算符重载的复数类 2 #include 3 4 class Complex{ 5 private: 6 double real;//实部 7 double image;//虚部 8 public: 9 Complex(){ 10 real=0; 11 ... 阅读全文
posted @ 2018-06-29 19:09 孙悟空son_ku_kong 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 1 //设计运算符重载的复数类 2 #include 3 4 class Complex{ 5 private: 6 double real;//实部 7 double image;//虚部 8 public: 9 Complex(){ 10 real=0; 11 ... 阅读全文
posted @ 2018-06-29 19:08 孙悟空son_ku_kong 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 1 //友元分为友元类和友元成员函数和友元函数 2 //设计A类是B类的友元类 3 //那么A类可以访问B类的所有成员(公有、私有、保护成员),同理,友元类和友元函数也是一样 4 #include 5 class B{ 6 friend class A; 7 private: 8 int topSecret; 9 public: 10 ... 阅读全文
posted @ 2018-06-29 19:05 孙悟空son_ku_kong 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 1 //static成员的学习 2 #include 3 #include 4 5 class Employee{ 6 private: 7 char name[30]; 8 float salary; 9 static float allSalary; 10 public: 11 Employe... 阅读全文
posted @ 2018-06-29 18:51 孙悟空son_ku_kong 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1 //内部类的学习 2 #include 3 class Line{ 4 class Point{ 5 public: 6 int x; 7 int y; 8 Point(int x=0,int y=0){ 9 this->x=x; 10 ... 阅读全文
posted @ 2018-06-29 18:50 孙悟空son_ku_kong 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1 //析构函数的学习 2 #include 3 class Point{ 4 private: 5 int x; 6 int y; 7 public: 8 Point(){} 9 Point(int x,int y){ 10 this->x=x; 11 ... 阅读全文
posted @ 2018-06-29 18:49 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 1 //设计一个线段类 2 #include 3 class Point{ 4 private: 5 int x; 6 int y; 7 public: 8 Point(){} 9 Point(int x,int y){ 10 this->x=x; 11 ... 阅读全文
posted @ 2018-06-29 18:36 孙悟空son_ku_kong 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1 //设计一个简单的动态数组类 2 #include 3 #include 4 class Array{ 5 private: 6 double *arr; 7 int size; 8 public: 9 Array(int sz=100); 10 ~Array(); 11 }; 12 13 A... 阅读全文
posted @ 2018-06-29 18:34 孙悟空son_ku_kong 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 1 //用类实现复数的加减功能 2 #include 3 class Complex{ 4 private: 5 float real;//虚部 6 float img;//实部 7 public: 8 Complex(float real,float img){ 9 this->real=... 阅读全文
posted @ 2018-06-29 18:29 孙悟空son_ku_kong 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 1 //利用动态数组保存字符串"Data Structure"程序 2 #include 3 int main(){ 4 char *str,s[]="Data Structure"; 5 int length=14;//字符串的长度 6 str=new char[sizeof(s)+1]; 7 int i; 8 for(i=0;i<len... 阅读全文
posted @ 2018-06-29 15:11 孙悟空son_ku_kong 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 1 //命名空间的使用 2 #include 3 namespace module{ 4 void f1(){ 5 cout<<"这是f1()函数"<<endl; 6 } 7 void f2(){ 8 cout<<"这是f2()函数"<<endl; 9 } 10 double s=1.0; 11 } 12 ... 阅读全文
posted @ 2018-06-29 15:06 孙悟空son_ku_kong 阅读(133) 评论(0) 推荐(0) 编辑

导航