![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
不死鸟-PHOENIX
这个作者很懒,什么都没留下…
展开
-
qt串口调试助手
#-------------------------------------------------## Project created by QtCreator 2017-09-01T13:29:03##-------------------------------------------------QT += core gui serialportgreaterTh原创 2017-09-01 15:12:14 · 627 阅读 · 0 评论 -
多态 virtual
#include using namespace std; class Fract{ int n; int d;public: Fract():n(0),d(1) { } Fract(int an, int ad):n(an),d(ad) { reduce(); } void reduce() { if (d<0) { d = -d;原创 2017-08-12 13:26:33 · 219 阅读 · 0 评论 -
继承 带分数
#include using namespace std; class Fract{ int n; int d;public: Fract():n(0),d(1) { } Fract(int an, int ad):n(an),d(ad) { reduce(); } void reduce() { if (d<0) { d = -d;原创 2017-08-12 11:36:01 · 356 阅读 · 0 评论 -
构造函数 约分
#include using namespace std; class Fract{ int n; int d;public: Fract():n(0),d(1) { } Fract(int an, int ad):n(an),d(ad) { reduce(); } void reduce() { if (d<0) { d = -d;原创 2017-08-12 11:21:12 · 862 阅读 · 1 评论 -
递归汉诺塔问题
#include using namespace std;void hano(int n, char from, char temp, char to){ if (n==1) cout " << to <<endl; else { hano(n-1, from, temp, to); hano(1, from, to, temp); hano(n-1, temp,原创 2017-07-27 18:58:20 · 327 阅读 · 0 评论 -
结构体与指针
#include using namespace std;struct Date{ int year; int month; int day; }; void show(Date a){ Date* x = &a; int* y = &a.day; cout << (*x).year << (*x).month << (*x).day << endl; cou原创 2017-08-04 13:55:14 · 260 阅读 · 0 评论 -
继承 构造函数
#include using namespace std; class Parent{ int n;public: Parent():n(0) { cout << "Parent()" << endl; } Parent(int n):n(n) { cout << "Parnet(" << n << ")" << endl; } ~Parent() {原创 2017-08-11 16:52:40 · 176 阅读 · 0 评论 -
继承
#include using namespace std; class Animal{private: char name[20];protected: int age; public: void set_name(char* name) { strcpy(this->name, name); } void set_age(int age) { this-原创 2017-08-11 15:14:22 · 199 阅读 · 0 评论 -
multiset
#include using namespace std;#include templatevoid show(Iter ib, Iter ie){ while(ib!=ie) cout << *ib++ << ' '; cout << endl; }int main(){ int a[5]={5, 1, 7, 5, 1}; multiset pids(a, a+5原创 2017-08-18 15:01:46 · 543 阅读 · 0 评论 -
set
#include using namespace std;#include int main(){ set si; int userid[5]={3,4,7,7,8}; for (int i=0; i<5; i++) { si.insert(userid[i]); } set::iterator it; it = si.begin(); while(it!=si.e原创 2017-08-18 14:50:25 · 184 阅读 · 0 评论 -
multimap
#include using namespace std;#include #include typedef multimap M;int main(){ M mss; M::iterator ib ,ie; mss.insert(make_pair("aa", "bb")); mss.insert(make_pair("cc", "dd")); mss.insert(m原创 2017-08-18 14:35:32 · 357 阅读 · 0 评论 -
map
#include using namespace std;#include #include int main(){ map mis; mis.insert(make_pair(62, "小v")); mis.insert(make_pair(32, "魏军")); mis.insert(make_pair(36, "小明")); mis[20] = "小白"; mi原创 2017-08-18 14:12:14 · 178 阅读 · 0 评论 -
list
#include using namespace std;#include int main(){ int cpp[5]={3, 5, 7, 8, 9}; int java[8]={3, 4,6,7,8,9,11,12}; int Unix[4] = {2,3,6,8}; list li; li.insert(li.begin(), cpp, cpp+5); li.in原创 2017-08-18 13:33:53 · 179 阅读 · 0 评论 -
vector
#include using namespace std;#include void show(vector vi){ vector::iterator it; it=vi.begin(); while(it!=vi.end()) { cout << *it++ << ' '; } cout << endl;} int main(){ vector vi;原创 2017-08-18 13:23:06 · 182 阅读 · 0 评论 -
一个简单的时间和日期程序
#include using namespace std;struct Date{ int y; // year int m; //month int d; //day}; bool is_leap(int y){ return (y%4==0 &&y%109!=0 || y%400==0);}int days_of_month(int y, int m){原创 2017-08-04 11:40:24 · 544 阅读 · 0 评论 -
多态 虚函数
#include using namespace std;class Animal{string name;public: virtual void eat() //virtual 虚函数表一个占4个字节 { cout << "动物吃食物" << endl; } virtual void sleep() { cout << "动物休息" << endl; } v原创 2017-08-12 15:21:32 · 178 阅读 · 0 评论 -
友员
#include using namespace std;class A{ int data;public: A(int d):data(d) { } void show() { cout << "data=" << data << endl; } friend class B; //友员类 };class B{public: void twi原创 2017-08-12 19:09:42 · 254 阅读 · 0 评论 -
异常处理
#include using namespace std;#include int main(int argc, char* argv[]){try{ ifstream fin(argv[1]); if (!fin) throw 100; char buf[1000]; fin.read(buf, 1000); if (!fin) throw 100.0; co原创 2017-08-15 15:14:18 · 181 阅读 · 0 评论 -
格式化输出width,fill
#include using namespace std;class Wf{ int w; char f;public: Wf(int w, char f):w(w), f(f) { } friend ostream& operator<<(ostream& os, const Wf& o) { os.width(o.w); os.fill(o.f);原创 2017-08-15 10:30:05 · 349 阅读 · 0 评论 -
读写文件read/write
/** 写入文件 */#include using namespace std;#include int main(){ int n=123; double d=4.5; struct S{ char c; bool b; char addr[100]; }; S s={'S',true, "PingHu"}; class A{ int data;原创 2017-08-14 19:24:09 · 520 阅读 · 0 评论 -
putback()
#include using namespace std;int main(){ char ch; int n; cout << "input an integer:"; cin.get(ch); cin >> n; cout << "ch=" << ch << endl; cout << "n=" << n << endl; cin.ignore(1000, '\n');原创 2017-08-14 18:03:01 · 1623 阅读 · 0 评论 -
peek()
#include using namespace std;//#include int main(){ int no; char name[20]; cout << "input no or name" << endl; char ch=cin.peek(); if (ch>='0' && ch<='9') { cin >> no; cout << "no=" <<原创 2017-08-14 17:49:12 · 735 阅读 · 0 评论 -
getline c分格和c++风格
#include using namespace std;#include int main(){ string str; char buf[20]; cout << "input a line" << endl; getline(cin, str); cout << "str=" << str << endl; cout << "input a line <20" <<原创 2017-08-14 16:48:11 · 250 阅读 · 0 评论 -
I/O流 cat
#include using namespace std;#include #include int main(int argc, char* argv[]){ ifstream fin(argv[1]); char ch; while (fin.get(ch)) { time_t t=time(NULL); while (t==time(NULL)); cou原创 2017-08-14 16:28:30 · 277 阅读 · 0 评论 -
I/O流
#include using namespace std;#include #include int main(){ ofstream fout("a.txt"); fout << "hello world !" <<endl; fout.close(); string str = ""; int n=0; double d=0.0; char ch = 'a';原创 2017-08-14 12:06:29 · 186 阅读 · 0 评论 -
友员函数 operator
#include using namespace std;class F{ int a; //分子 int b; //分母 public: F(int a=0, int b=0):a(a),b(b) { } void show() { cout << a << '/' << b << endl; } F operator*(const F& o)const原创 2017-08-13 16:07:02 · 394 阅读 · 0 评论 -
两个分数相乘
#include using namespace std;class F{ int a; //分子 int b; //分母 public: F(int a=0, int b=0):a(a),b(b) { } void show() { cout << a << '/' << b << endl; } F operator*(const F& o)const原创 2017-08-13 15:54:09 · 638 阅读 · 0 评论 -
运算符函数 operator
#include using namespace std;class A{ int data;public: A(int n=0):data(n) { } void show() { cout << "data=" << data << endl; } A operator-(const A& o) { int dif = data - o.data;原创 2017-08-13 15:30:23 · 813 阅读 · 0 评论 -
深拷贝构造函数
#include using namespace std;class Array{ char *p; int len;public: Array(int n):len(n),p(new char[n]) { } int size() { return len; } ~Array() { delete[] p; } void fill(char st原创 2017-08-13 14:46:25 · 482 阅读 · 0 评论 -
构造动态数组
#include using namespace std;class Array{ char *p; int len;public: Array(int n):len(0),p(NULL) { resize(n); } void resize(int n) { char* q = new char[n]; int min = (n<len?n:len);原创 2017-08-13 14:27:25 · 394 阅读 · 0 评论 -
静态成员变量和静态成员函数 static
#include using namespace std;class SD207{public: string name; static string teacher; static int room; SD207(const string& n):name(n) { } void show() { cout << "我是" << name << "在" <<原创 2017-08-12 19:40:07 · 191 阅读 · 0 评论 -
构造函数的使用
#include using namespace std; class Person{private: char name[20]; bool gender; int age;public: Person(char* name, bool gender):gender(gender), age(0) { if (strlen(name) > 19) { co原创 2017-08-11 10:51:15 · 172 阅读 · 0 评论 -
序列式容器 vector
#include using namespace std;#include void show(vector vi){ vector::iterator it; it=vi.begin(); while(it!=vi.end()) { cout << *it++ << ' '; } cout << endl;} int main(){ vector vi(3原创 2017-08-18 11:02:00 · 224 阅读 · 0 评论 -
析构函数
#include using namespace std; class A{private: int n;public: A(int n=0):n(n) { cout << this << "A(" << n << ")"<< endl; } ~A() //析构函数 ,总是没有形参,不能重载 { cout << this << "~A(" << n << "原创 2017-08-10 21:00:33 · 163 阅读 · 0 评论 -
函数指针
#include //#include using namespace std;void reset(int a[], int n){ //menset(a, 0, sizeof(int)*n); for (int i=0; i<n; i++) { a[i] = 0; }}void output(int a[], int n){ for (int i=0; i<n;原创 2017-08-09 20:57:07 · 178 阅读 · 0 评论 -
引用 交换两个数的位置
#include using namespace std;void swap(int& a, int& b){ int t; t = a; a = b; b = t; }int main(){ int i = 10; int j = 20; swap(i, j); cout << i << ' ' << j << endl; return 0;}原创 2017-08-09 19:41:06 · 455 阅读 · 0 评论 -
直接选择法排序
#include using namespace std;#include typedef int T;void sort(T a[], int n) //T * p, int n{ for (int i=0; i<n-1; i++) { int pos = i; for (int j=i+1; j<n; j++) if (a[j] < a[pos]) po原创 2017-08-16 19:52:24 · 391 阅读 · 0 评论 -
字符串字符数统计
#include using namespace std;#include //#include int main(){ cout << "input some text:"; string str; getline(cin, str); int cnt[256]={}; for (int i=0; i<str.size(); i++) { cnt[(int)str原创 2017-08-09 15:52:03 · 537 阅读 · 0 评论 -
栈 数组
#include using namespace std;typedef int T;class Stack{ T a[10]; int num; //记录已经放入的元素个数 public: void push(const T& t) { if (full()) throw "stack overflow"; a[num++] = t; } void p原创 2017-08-16 15:28:19 · 269 阅读 · 0 评论 -
二维数组打印
#include using namespace std;void print(int array[], int n){ for (int i=0; i<n; i++) cout << array[i] << ' '; cout << endl;}int main(){ int b[3][4]={ {1, 3, 5, 6}, {2, 4, 6, 7}, {原创 2017-08-02 11:29:00 · 264 阅读 · 0 评论