- 博客(10)
- 收藏
- 关注
原创 个人笔记
#include#includeusing namespace std;void f(int n){ int i,j=0,sum=n; int a[10]={0}; while(n>0) { a[j]=n%10;j++;n=n/10; } if(a[0]==a[1]||a[0]==a[2]||a[
2016-09-12 20:59:05 217
转载 虚函数
#includeusing namespace std;class Student{public:Student(int ag,char se){age=ag;sex=se;}virtual void display(){ cout}protected:int age;char sex;};class Gradua
2016-09-07 17:04:59 208
转载 虚基态程序
#include #includeusing namespace std;class Person{public:Person(string nam,char s,int a){name=nam; sex=s;age=a;}protected: string name;char sex;int age;};//声明Person的
2016-08-30 22:15:01 310
原创 继承类的访问属性的小程序
#include #includeusing namespace std;class student{public:student(string n,int a){name=n; age=a;}void display();protected: string name;int age;};void student::disp
2016-08-30 15:50:09 294
原创 运算符重载
c++ 中 * 重载1,运算符重载函数作为类成员函数:#include using namespace std;class complex1{public:complex1(){real=0;imag=0;}complex1(int r,int i);void display();complex1 operator*(complex1 &c);priva
2016-08-29 11:03:30 325
转载 以++运算符为例,介绍单目运算符的重载
#includeusing namespace std;class Time{public: Time(){minute=0;sec=0;}Time(int m,int s):minute(m),sec(s){} Time operator++();void display(){coutprivate:int minute;int sec
2016-08-27 16:43:33 458
转载 关于运算符重载(总结)
关于运算符重载(总结)1、运算符重载是为了对用户自定义数据类型的数据的操作与内定义的数据类型的数据的操作形式一致。不能重载的5个运算符:*成员指针访问运算符;::域运算符;sizeof长度运算符;?:条件运算符;.成员访问符。运算重载的三种方式:普通函数,友元函数,类成员函数。当重载为成员函数时,双目运算符仅有一个参数。对单目运算符,重载为成员函数时,不能再显式说明参数
2016-08-27 11:54:35 457
原创 复数相加小程序
#include using namespace std;class complex{public:void display();complex(int,int);~complex(){} int real;int imag;};complex::complex(int r,int ima){ real=r; imag=ima;}
2016-08-26 10:54:18 400
原创 几个小程序 O(∩_∩)O~
1,#includeusing namespace std;int main(){char*s="AAA";printf("%s",s);s[0]='B';printf("%s",s);return 0;}输出为AAA 第二个不能输出 因为s是指向字符串的指针,不能被赋值。若是想赋值可以改成如下:#includeusing namespace s
2016-08-24 11:49:44 297
原创 指向常对象的指针变量和指向对象的常指针
指向常对象的指针变量和指向对象的常指针1,指向常对象的指针变量指向常对象的指针变量可以指向一个已经申明为常对象的变量,此时只能用指向常对象的指针变量指向它;也可以指向一个非常对象的变量,而此时可通过指针访问该对象,但是不能通过指针改变该对象的值。下面给出一个简单程序:#include using namespace std;class Student{ publi
2016-08-23 21:22:56 3227
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人