c++
文章平均质量分 62
weixin_45751113
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++基础--结构体案例
案例1 #include<iostream> using namespace std; #include<string> #include<Ctime> //定义学生结构体 struct student { string Sname; int score; }; //定义老师结构体 struct teacher { string Tname; student stu[5]; }; //定义赋值函数 void fuzhi(teacher tea[], int原创 2020-09-24 22:32:22 · 357 阅读 · 0 评论 -
C++基础--指针-数组-函数案例
#include<iostream> using namespace std; void paixu(int * arr,int len) { for(int i=0;i<=len-1;i++) { for(int j=0;j<len-1-i;j++) { if(arr[j]>arr[j+1]) { int temp = arr[j]; arr[j]= arr[j+1]; arr[j+1]=temp; } } } }原创 2020-09-24 22:24:25 · 180 阅读 · 0 评论 -
C++基础--数组案例
五只小猪称体重 #include <iostream> using namespace std; int main(){ //创建五只小猪的体重的数组 int arr[5]={200,250,100,500,260}; // 定义一个最大值max int max=0; //如果小猪的体重比最大值还大,更新最大值 for(int i=0;i<5;i++){ if(arr[i]>max){ max=arr[i]; } } cout &l原创 2020-09-24 22:18:48 · 299 阅读 · 0 评论 -
C++基础--循环结构案例
猜数字 #include<iostream> using namespace std; int main(){ //1.系统随机生成1-100的随机数 int num = rand()%100 + 1; cout << num << endl; //2.玩家进行猜测 int a; int sum=0; cout << "请玩家进行猜测:" << endl; //3. 判断猜测的对错,5次没猜对则游戏失败 for(int i=原创 2020-09-24 22:08:08 · 450 阅读 · 0 评论 -
C++基础--选择结构案例
三只小猪称体重 #include<iostream> using namespace std; int main(){ int a=0; int b=0; int c=0; cout <<"请输入a的体重:" << endl; cin>>a; cout <<"请输入b的体重:" << endl; cin>>b; cout <<"请输入c的体重:" << endl; cin>&原创 2020-09-24 21:40:56 · 218 阅读 · 0 评论 -
C++基础--结构体
结构体1. 概念2. 嵌套结构体3. 结构体数组4. 结构体做函数参数5. 结构体指针6. const使用场景 1. 概念 #include<iostream> using namespace std; #include<string> //结构体:自定义数据类型, //1.创建学生数据类型:学生包括(姓名,年龄,分数) struct student { string name; int age; int score; }s3; //2.通过学生类型创建具体学生 int原创 2020-09-23 11:45:34 · 598 阅读 · 0 评论 -
C++基础--指针
指针1. 定义2.内存空间3. 指针与数组4. 指针与函数5. const修饰指针 1. 定义 #include <iostream> using namespace std; int main(){ //1.定义一个指针:数据类型 *指针变量名 int a=10; int * p; p=&a; cout << "a的地址为:"<< p <<endl; cout << "指针P的地址为:"<< p <<e原创 2020-09-23 11:29:01 · 170 阅读 · 0 评论 -
C++基础--函数
函数1. 定义2.常见样式3. 声明4. 值传递5. 分文件编写 1. 定义 #include<iostream> using namespace std; /*返回值类型 函数名(参数列表) { 函数体语句 return表达式 } */ int Add(int num1,int num2){ int sum = num1+num2; return sum; } int main(){ int num1 =0; int num2 =0; cout << "请输入原创 2020-09-23 11:15:12 · 89 阅读 · 0 评论 -
C++基础--数组
数组1. 一维概念2. 一维数组3. 二维概念4. 二维数组5. 冒泡排序 1. 一维概念 #include<iostream> using namespace std; int main(){ //1.数据类型 数组名[数组长度] int score[3]; score[0]=100; score[1]=50; score[2]=50; cout << score[0] << endl; //2. 数据类型 数组名[数组长度]={值1,值2,值3,....原创 2020-09-23 10:57:39 · 107 阅读 · 0 评论 -
C++基础--程序流程结构
程序流程结构1. if语句2. switch语句3. while语句4. for语句5. break语句6. continue语句7. goto语句 1. if语句 多if 语句: #include<iostream> using namespace std; int main(){ int a=0; cout << "请用户输入分数:" <<endl; cin>>a; cout << "打印分数:"<< a <<end原创 2020-09-23 10:39:21 · 146 阅读 · 0 评论 -
C++基础--运算符
运算符1. 赋值运算符2. 加减乘除运算3. 比较运算符4. ++n与n++5. 与或非6. 键盘输入 1. 赋值运算符 #include<iostream> using namespace std; int main(){ int a= 10; //a=a+2 a+=2; cout << "a= "<< a <<endl; //a=a-2 a= 10 ; a-=2; cout << "a= "<< a <<endl; /原创 2020-09-23 09:51:26 · 107 阅读 · 0 评论 -
C++基础--定义
C++基础 概念C++基础1.标准样式2.变量与常量3.数据类型(1)浮点型(2)字符串型(3)转义字符(4)布尔类型4.sizeof 1.标准样式 #include<iostream> using namespace std; int main() { system("pause"); return 0; } 2.变量与常量 #include <iostream> using namespace std; int main(){ // 变量的定义方式 int a=10原创 2020-09-22 20:33:41 · 345 阅读 · 0 评论 -
STL--概念
STL初识 六大组件:容器、算法、迭代器、仿函数、适配器(配接器)、空间配置器 容器:存放数据,分为序列式容器和关联式容器 算法:解决问题,分为质变算法和非质变算法 迭代器:容器和算法之间的粘合剂 ...原创 2021-03-17 21:15:49 · 149 阅读 · 0 评论 -
STL--string容器
string1. string的构造函数2. string赋值3.string拼接4.string查找和替换5.string字符串比较6.string存取7.string插入和删除8.string字串 1. string的构造函数 string(); 创建一个空字符串,比如string str; string(const char * s);使用字符串s初始化 string(const string str);使用一个string对象初始化另一个string对象 string(int n, char c);原创 2021-03-17 21:15:32 · 313 阅读 · 0 评论 -
C++提高--模板案例
案例1 实现通用 对数组进行排序的函数 #include<iostream> using namespace std; //交换算法 template<typename T> void Myswap(T &a, T &b) { T temp = a; a = b; b = temp; } //排序算法 template<class T> void Mysort(T arr[], int len) { for (int i = 0; i <原创 2021-03-17 21:14:56 · 124 阅读 · 0 评论 -
C++提高--类模板
1. 语法 template后为class #include<iostream> using namespace std; #include<string> template<class nameType,class ageType> class person { public: person(nameType name,ageType age) { this->m_name = name; this->m_age = age; } voi原创 2021-03-17 21:14:36 · 104 阅读 · 0 评论 -
C++提高--函数模板
函数模板1. 语法2. 注意事项3. 普通函数与模板函数的区别3. 普通函数与模板函数的调用规则3. 函数模板的局限性 1. 语法 template–声明创建模板 typename–表明其后面的符号是一种数据类型,可以用class代替 T–通用的数据类型,名称可以替换,通常为大写字母 #include<iostream> using namespace std; void swapInt(int &a,int &b) { int temp = a; a = b; b =原创 2021-03-17 21:14:05 · 84 阅读 · 0 评论
分享