![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 68
叽了咣啷biang
这个作者很懒,什么都没留下…
展开
-
图书链表
#include #include using namespace std;class book{public: int num; float price; book*next;};bool check(string str){ int i,j=0; if (str[0]=='.') //假如字符串第一个元素为小数点返回假 re转载 2012-07-12 13:10:05 · 340 阅读 · 0 评论 -
数组
二分二分法查找数据前提是数组中的值是从小到大依次排列的: #include using namespace std;int find(int,int[],int);int main(){ int a[]={1,32,55,66,77,88,99,110,115,120,125,130}; cout<<"32在数组a中的位置是:"<<find(32,a,12)<<转载 2012-07-10 21:04:22 · 278 阅读 · 0 评论 -
继承笔记
派生类的对象可以赋给基类对象,反过来则不行。基类的对象可以指向派生类对象,反过来不行。基类的对象可以引用子类的对象,反过来则不行。 多重继承 #include using namespace std;class father{private: int tall;public: void seta(int a){tall=a;} void pri转载 2012-07-09 21:59:29 · 169 阅读 · 0 评论 -
不可以重载的运算符
转载 2012-07-09 19:15:55 · 221 阅读 · 0 评论 -
把对象赋给int型变量
#include using namespace std;class A{public: A(){i=0;} A(int x){i=x;} A(A const& r){i=r.i;} ~A(){} int get(){return i;} void set(int x){i=x;} operator int(){return i;} //int类型转换转载 2012-07-09 19:00:18 · 421 阅读 · 0 评论 -
operator =
#include using namespace std;class num{public: num(){n=new int;} num(int i){n=new int;*n=i;} ~num(){delete n;n=0;} int get()const{return *n;} int set(int x){*n=x;} const num &opera转载 2012-07-09 17:58:50 · 171 阅读 · 0 评论 -
运算符重载笔记
创建临时对象将自加后的对象赋给另一个对象,我们需要创建一个临时对象,然后返回该对象 #include using namespace std;class num{public: num(){n=1;} ~num(){} int get()const{return n;} void set(int x){n=x;} num operator++()转载 2012-07-07 22:12:42 · 187 阅读 · 0 评论 -
友元类简介
//电视机将遥控器声明为友元类,遥控器可以控制电视机反过来则不行。就好像你愿意把秘密告诉你的朋友,这不不意味着你的朋友愿意把他的秘密告诉你#include using namespace std;class TV //电视机类{public: friend class Tele; //声明遥控器类为电视机类的友元转载 2012-07-17 23:01:08 · 1942 阅读 · 0 评论 -
公有继承、私有继承和保护继承之间的对比
继承方式 公有继承 保护继承 私有继承 被继承的对象 基类的公有成员 派生类的公有成员 派生类的保护成员 派生类的私有成员基类的保护成员 派生类的保护成员转载 2012-07-17 22:14:30 · 238 阅读 · 0 评论 -
链表
静态链表const int NULL=0;#include using namespace std;class book{public: int num; float price; book*next;};void main(){ book x,y,z,*head,*p; x.num=5; x.price=22.5f; y.num=6转载 2012-07-11 19:19:34 · 180 阅读 · 0 评论 -
多态性
多重继承虽然多重继承与单一继承相比有很多优点,但是由于虚基类的定义很复杂,因此很多程序员都不愿意使用它。他们认为很多编译器不支持多重继承,代码容易产生多义性,调试起来很困难,而且很多时候不实用多重继承同样可以做到。我们要注意在用单一继承就可以实现的情况下,不要使用多重继承。 #include using namespace std;class father{p转载 2012-07-12 16:16:11 · 751 阅读 · 0 评论 -
简写string类
#include using namespace std;class String{public: String(); ~String(); String(const String&rs); String(const char*const ch); char&operator[](unsigned short int length); char operat转载 2012-07-15 21:10:41 · 352 阅读 · 0 评论 -
c++指针小计
假如没有删除第一个指针就对其重新赋值就会造成内存泄漏。 使用空值的指针会令程序出错。 指针也可以与指针相加相减比较,可以自加自减,都是相对于指针保存的地址操作,比如自加,int型的指针会自加四个字节,两个指针比较也是比较两个指针的内存地址。 常量指针 我们可以将指针声明为常量指针,该指针不可改变如: int *co转载 2012-07-01 18:20:47 · 196 阅读 · 0 评论 -
控制结构
python 关键字 and continue else for import not raiseassert def except翻译 2012-06-24 18:59:20 · 200 阅读 · 0 评论 -
类的特殊成员
静态变量在C++中(以及其他一些语言,如 C#,Java 等面向对象的语言中)类的成员变量被声明为static(称为静态成员变量),意味着它为该类的所有实例所共享,也就是说当某个类的实例修改了该静态成员变量,其修改值为该类的其它所有实例所见。 比如在某个类A中声明一个static int number;初始化为0。这个number就能被所有A的实例共用。在A的构造函数里加上numbe转载 2012-07-13 21:45:05 · 358 阅读 · 0 评论 -
字符数组的几个应用函数
1.strcat函数它的作用是把第二个数组中的字符串连接到第一个数组中的字符串后面,而把连接后的字符串放在字一个字符数组中。格式为 strcat(字符数组1,字符数组2)。2.strcpy函数该函数用来将第二个字符数组中的字符串复制到第一个字符数组中去3.strcmp函数把两个字符串做比较假如返回0代表相同,返回其他则不同。4.strupr函数将字符串中小写的字母转换为转载 2012-07-11 12:43:42 · 466 阅读 · 0 评论 -
虚函数
拳击游戏演示#include using namespace std;class poser{public: virtual void beat()const{cout<<"一般选手一拳的力量为260磅\n";}protected: int age;};class Ali:public poser{public: void beat()const转载 2012-07-10 18:05:38 · 184 阅读 · 0 评论 -
深层复制构造函数
#include using namespace std;class A{public: A(){x=new int;*x=5;} //创建一个对象的同时将成员指针指向的变量保存到新空间中 ~A(){delete x;x=0} //析构对象的同时删除成员指针指向的内存空间,为了 //稳妥起见将指针赋为空转载 2012-07-07 18:24:24 · 307 阅读 · 0 评论 -
调用构造函数进行类型转换
#include using namespace std;class A{public: A(int x){i=x;} //把这条语句改成 explicit A(int x){i=x;}关闭这个构造函数的隐式转换。 ~A(){}private: int i;};int main(){ A a(15); a=58; //a=58等原创 2012-07-07 13:21:05 · 187 阅读 · 0 评论 -
c++引用
引用就是别名定义引用时一定要同时对该引用进行初始化,如:int a;int &ra=a;而不能写成:int a;int &ra;ra=a; 按址传递 void swap(int *pa,int *pb); //swap函数声明int a=3,b=4; //变量a和bswap(&a,&b);转载 2012-07-04 20:25:02 · 219 阅读 · 0 评论 -
c++函数简述
c++函数定义 返回类型 函数名(参数) { 功能 如果函数是返回void则不用写返回类型,如果是其他则返回一个函数类型的参数,例如: return 0; }例如实现输出文字功能 void show(){ std::cout}翻译 2012-06-24 19:11:53 · 306 阅读 · 0 评论 -
流
缓冲从磁盘中每读取一个字符都需要大量的硬件活动,这样,向磁盘读写数据时就会花费很多时间,为了避免频繁的读写数据,流提供了缓冲技术。数据经过流的操作被读入缓冲区中,此时,该数据不会立即写到磁盘中,而是不断地将其他数据读入缓冲区中,知道缓冲区充满时,才一次性写入磁盘中。缓冲区是内存中的一块区域,他对数据的处理速度比硬盘快,因此,当大量信息存储在缓冲区时,会无形中提高了程序对数据的访问速度。同时转载 2012-07-19 11:56:36 · 418 阅读 · 0 评论