- 博客(43)
- 收藏
- 关注
原创 静态成员变量
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//静态成员就是在成员变量和成员函数之前加上关键字static class Person{public: //所有对象都共享同一份数据 //编译阶段就分配内存 /
2021-05-11 19:17:07 113
原创 运算符重载3
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//关系运算符重载class Person{public: Person(string name, int age) { m_age = age; m_na
2021-05-11 19:02:39 89
原创 赋值运算符重载
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//赋值运算符重载class Person{public: Person(int age) { m_Age = new int(age); } ~Perso
2021-05-11 18:06:39 66
原创 浅拷贝和深拷贝
#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//浅拷贝 简单的赋值拷贝操作 // 如果利用编译器提供的拷贝构造操作,会做浅拷贝操作//会造成堆区内存重复释放// 自己实现拷贝构造函数 解决浅拷贝带来的问题//深拷贝:在堆区重新申请空间,进行拷贝操作//如果
2021-05-11 17:12:47 44
原创 运算符重载2
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//重载递增运算符class MyInteger{ friend ostream& operator<<(ostream& cout,
2021-05-11 16:16:17 45
原创 运算符重载1
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//加号运算符重载class Person{ public: //成员函数重载+ Person operator+(Person& p) { Per
2021-05-11 15:55:35 40
原创 常用集合算法
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>void myPrint(int val){ cout << val << " ";}//常用集合算法//set_intersectio
2021-05-11 13:46:07 72
原创 常用算数生成算法
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//accumulate 计算区间内 容器元素的总和#include<numeric>void test01(){ vector<int>
2021-05-11 13:18:09 88
原创 常用拷贝和替换算法
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//常用拷贝和替换算法void myPrint(int val){ cout << val << " ";}//copyvoid te
2021-05-11 01:04:30 58
原创 常用排序算法
#include<iostream>#include<string>#include<vector>using namespace std;#include<algorithm>#include<functional>#include<ctime>//sortvoid myPrint(int val){ cout << val << " ";}void test01(){ vec
2021-05-11 00:37:35 48
原创 常用查找算法2
#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;//count//统计内置数据类型void test01(){ vector<int>v; v.push_back(10); v.push_back(40); v.push_back(30); v.push_back(40); v.push_b
2021-05-10 17:28:13 39
原创 常用查找算法
#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;//查找 内置数据类型void test01(){ vector<int>v; for (int i = 0; i < 10; i++) { v.push_back(i); } //查找容器中是否有5这个元素 vector<in
2021-05-10 16:35:37 39
原创 常用遍历算法
#include<iostream>using namespace std;#include<vector>#include<algorithm>//常用遍历算法//普通函数void print01(int val){ cout << val << " ";}//仿函数class print02{public: void operator()(int val) { cout << val <
2021-05-09 17:39:12 123
原创 谓词和内建函数对象
#include<iostream>using namespace std;#include<vector>#include<algorithm>#include<functional>//内建函数对象头文件class greatFive{public: bool operator()(int val) { return val > 5; }};void test01(){ vector<int>v; f
2021-05-09 16:18:03 71
原创 map容器
#include<iostream>using namespace std;#include<map>;void printMap(map<int,int>&m){ for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) { cout << "key = " << (*it).first << "value = " <
2021-05-08 19:42:04 52
原创 set容器
#include<iostream>using namespace std;#include<set>void printSet(set<int>& s){ for (set<int>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl;}void test01()//赋值
2021-05-08 16:57:40 51
原创 list容器
#include<iostream>#include<list>using namespace std;void printList(const list<int>& L){ for (list<int>::const_iterator it = L.begin(); it != L.end();it++) { cout << *it << " "; } cout << endl;}v
2021-05-08 15:09:02 65
原创 vector容器
#include<iostream>#include<vector>using namespace std;void printVector(vector<int>& v){ for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout << *it << " "; } cout << endl;}void
2021-05-07 15:48:34 50
原创 string容器
#include<iostream>#include<string>using namespace std;//string的构造函数//string();//string(const char* s);//string(const string& str);//string(int n, char c);void test01(){ string s1;//默认构造 const char * str = "hello world"; stri
2021-05-07 10:06:23 43
原创 stl初 识
#include<iostream>#include<string>using namespace std;#include<vector>#include<algorithm>void myPrint(int val){ cout << val << endl;}void test01(){ vector<int>v; v.push_back(10); v.push_back(20);
2021-05-07 09:06:31 32
原创 类模板
#include <iostream>using namespace std;#include<string>;#include<fstream>#include<vector>#include<algorithm>//标准算法template<class NameType,class AgeType=int>class Person{public: Person(NameType name, AgeType ag
2021-05-05 16:38:36 45
原创 文件
#include <iostream>using namespace std;#include<string>;#include<fstream>void test01(){ // 包含头文件fstream //创建流对象 ofstream ofs; //指定打开方式 ofs.open("text.txt", ios::out); //写内容 ofs << "张三" << endl; //关闭 ofs.close();
2021-04-19 17:30:44 37
原创 类模板
#include using namespace std;#include;template<class NameType,class AgeType=int>//类模板在模板参数列表中可以有默认参数class Person{public:Person(NameType name,AgeType age){this->m_Name = name;this->m_Age = age;}string m_Name;int m_Age;void showPers
2021-04-11 15:34:52 33
原创 函数模板基本语法
#include <cmath>#include <vector>#include <iostream>#include<stdlib.h>using namespace std;template<typename T>void myswap(T& a, T& b) { T temp = a; a = b; b = temp;}void test() { int a = 10; int b = 20
2021-03-25 20:21:53 36
原创 2, 定义一个Object类,有数据成员weight及相应的构造函数和析构函数,由此派生出Box类,增加数据成员height和width及相应的构造函数和析构函数。声明一个Box对象,观察构造函数与析
#include<iostream>using namespace std;class object {public: int weight; object() { cout << "obj的构造函数" << endl; } ~object() { cout << "obj的析构函数" << endl; }};class box :public object{public: int height, width;
2021-03-21 15:05:52 1740 1
原创 1, 定义一个基类BaseClass,从它派生出类DerivedClass。BaseClass里有成员函数fn1(),fn2(),DerivedClass也有成员函数fn1(),fn2()。在主函数中
#include<iostream>using namespace std;class BaseClass {public: virtual void fn1() { cout << "bc的fn1调用" << endl; } virtual void fn2() { cout << "bc的fn2调用" << endl; }};class DerivedClass :public BaseClass{public
2021-03-21 14:33:35 1671
原创 this指针
#include<iostream>using namespace std;class Person {public: Person(int age) { this->age = age; } int age;};void test(){ Person p(18); cout << "p的年龄:" << p.age; }int main() { test();}
2021-03-20 22:04:39 32
原创 多态 计算器类案例
#include<iostream>using namespace std;class abstractcalculator {public: virtual int getResult() { return 0; } int m_num1; int m_num2;};//加法计算器类class AddCalculator :public abstractcalculator {public: int getResult() { return m_num1 +
2021-03-18 20:24:11 67
原创 多态
#include<iostream>using namespace std;class animal {public: virtual void speak() { cout << "动物在说话" << endl; }};class cat :public animal {public: void speak() { cout << "小猫在说话" << endl; }};class dog :public a
2021-03-18 17:02:18 31
原创 结构体案例1
#include<iostream>using namespace std;#include<string>#include<ctime>struct student { string sName; int score;};struct teacher { string tName; struct student sArray[5]; };void allowcatespace(teacher tArray[],int len) {
2021-01-30 01:14:35 347
原创 第三次上机作业
查找指定元素是否存在#include<iostream>using namespace std;int main() { int a[5] = { 19,67,24,11,17 }, b[5] = { 2,3,9,17,59 },t; cout << "请输入想查找的数字:" << endl; cin >> t; for (int i = 0; i < 5; i++) { if (a[i]==t) { cout <<
2020-12-25 16:15:40 55
原创 成员属性私有化
1、操控读写权限2、检测数据有效性#include<iostream>using namespace std;#include<string>class person {public: //设置姓名 void setname(string name) { m_name = name; } //获取姓名 string getname() { return m_name; } //设置年龄 void setage(int age) { if
2020-12-19 13:03:45 159 1
原创 类-封装-学生案例
#include<iostream>using namespace std;#include<string>class student {public: string m_name; int m_id; void showstudent() { cout << "姓名:" << m_name << " 学号:" << m_id << endl;}};int main() { student
2020-12-18 20:36:13 115 1
原创 打印乘法口诀表
打印乘法口诀表#include<iostream>using namespace std;int main() { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { cout << j<< "*"<< i <<"="<< i * j << " "; } cout << endl; }}
2020-12-12 16:36:40 82
原创 指针,数组,函数,冒泡排序升序案例
指针,数组,函数,冒泡排序升序案例#include<iostream>using namespace std;void bubblesort(int*arr,int len) { for (int i = 0; i < len - 1; i++) { for (int j = 0; j < len - i - 1; j++) { if (arr[j] >arr[j + 1]) { int temp = arr[j]; arr[j ] = ar
2020-12-12 15:55:00 113
原创 二维数组案例---统计学生总分
二维数组案例—统计学生总分int main() { int arr[3][3]{ {100,100,100}, {90,80,100}, {60,60,40} }; string names[3] = { "张三","李四","王五" }; for (int i = 0; i < 3; i++) { int sum = 0; for (int j = 0; j < 3; j++) { sum += arr[i][j]; } cout <
2020-12-12 15:22:27 844
原创 冒泡排序
冒泡排序#include<iostream>using namespace std;int main() { int arr[9] = { 4,8,1,7,5,6,9,3,2 }; cout << "before:" << endl; for (int i = 0; i < 9; i++) { cout << arr[i] << " "; } for (int i = 0; i < 9 - 1; i++) {
2020-12-12 15:06:25 39
原创 一维数组案例---元素逆置
一维数组案例—元素逆置#include<iostream>using namespace std;int main() { int arr[5] = { 2,3,4,5,6 }; int start = 0; int end = sizeof(arr) / sizeof(arr[0]) - 1; cout << "逆置前" << endl; for (int i = 0; i < 5; i++) { cout << arr[i] &
2020-12-12 14:43:57 304
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人