
C++
恒云客
这个作者很懒,什么都没留下…
展开
-
字符进行数值运算
/** * program: * Authors: hao.l * Date: 2016/10/24 * Modify by: * * Desc: * 字符进行数值运算 */#include #include using namespace std;int main(){ int i,j; i='A'; //65 j='B'原创 2016-10-24 21:42:12 · 418 阅读 · 0 评论 -
10101 输出流
#include <iostream> using namespace std; // 空白字符(空格、制表符、回车) int main() { int a,b,c; cin>>a>>b>>c; // 1 2 3 >> 123 cout<<a<<b&原创 2018-04-09 22:55:47 · 201 阅读 · 0 评论 -
10102 循环输入字符串
#include <iostream>#include <string>using namespace std;// 循环输入字符串int main(){ string str; while(cin>>str){ if(str=="exit"){ break; } ...原创 2018-04-09 22:59:57 · 993 阅读 · 0 评论 -
10003 字符串
#include <iostream>#include <string>using namespace std;// char[128]="This is a test";// char* s = "This is a test";// strcat()// strcmp()int main(){ string s1 ="This is ...原创 2018-04-09 23:37:26 · 221 阅读 · 0 评论 -
10003 标准库string类型
#include <iostream>#include <string>using namespace std;// 标准库string类型int main(){ string key(10,'a'); string name = key + "bbb"; string password = string("123456"); ...原创 2018-04-09 23:40:27 · 171 阅读 · 0 评论 -
10003 字符统计
#include <iostream>#include <string>using namespace std;// 字符串统计int main(){ string text; string line; int rows=0; while(getline(cin,line)){ if(line=="q"){ ...原创 2018-04-09 23:45:43 · 187 阅读 · 0 评论 -
10200 容器vector操作
#include <iostream>#include <vector>#include <string>using namespace std;// 标准类库vector类型int main(){ vector<string> v(100); v.push_back("Hello"); v.push_bac...原创 2018-04-10 13:40:02 · 126 阅读 · 0 评论 -
10003 字符统计vector
#include <iostream>#include <vector>#include <string>#include <iomanip>using namespace std;// 字符统计vectorint main(){ vector<string> text; string rows;...原创 2018-04-10 14:10:34 · 146 阅读 · 0 评论 -
10007 函数参数引用
#include <iostream>using namespace std;// 引用的主要用于在函数参数传递中,解决大块数据或对象的传递效率和空间的问题void swap(int&,int&);int main(){ int a=23; int& b=a; cout<<a<<','<...原创 2018-04-10 22:06:44 · 157 阅读 · 0 评论 -
10004 函数默认参数
#include <iostream>#include <string>using namespace std;// 函数默认参数void move(int step= 1,int delta= 100);int main(){ move(); return 0;}void move(int step,int delta){ ...原创 2018-04-10 22:43:15 · 160 阅读 · 0 评论 -
10004 函数重载
#include <iostream>using namespace std;// 函数重载// 参数列表数据类型相同,返回类型不同,不属于函数重载int add(int a,int b){ return a+b;}double add(double a,double b){ return a+b;}int main(){ c...原创 2018-04-10 23:06:54 · 206 阅读 · 0 评论 -
10004 函数模板
#include <iostream>using namespace std;// 函数模板template <typename T>T add(T a,T b){ return a+b;}int main(){ cout<<add(22,24)<<","<<add(23.5,0.5)<<原创 2018-04-10 23:19:14 · 159 阅读 · 0 评论 -
10007 函数返回引用类型
#include <iostream>using namespace std;// 函数返回引用类型const int& add(int a,int b,int& c){ c=a+b; return c;}int main(){ int a=23,b=44,c; int d = add(a,b,c); co...原创 2018-04-10 23:29:01 · 159 阅读 · 0 评论 -
10200 类定义
#ifndef STUDENT_H#define STUDENT_Hclass Student{ public: Student(); void print(); protected: private: char name[128]; int age; char addr[128];...原创 2018-04-11 23:10:45 · 281 阅读 · 0 评论 -
10100 输出流格式化
/*dec 10进制hex 16进制oct 8进制setw(int) 输出长度setprecision(int) 有效数字位数setfill(char) 设置填充字符endl 换行/刷新流缓存区flush 刷新缓存区*/#include <iostream>#include <iomanip>using namespace std;int ...原创 2018-04-09 22:33:10 · 138 阅读 · 0 评论 -
10007 引用(变量别名)
#include <iostream>using namespace std;// 引用(变量别名)void add(int,int,int&);int main(){ int c= 0; add(23,44,c); cout<<c<<endl; return 0;}void add(int a,int b...原创 2018-04-08 23:58:30 · 188 阅读 · 0 评论 -
10006 内存分配
#include <iostream>#include <malloc.h>using namespace std;// 内存分配// 单个变量 // int* p = new int; // delete p;int main(){ int* p = (int*)malloc(sizeof(int)*100); if(!p){ ...原创 2018-04-08 23:51:48 · 139 阅读 · 0 评论 -
Hello World
/** * Hello World */#include using namespace std;int main(){ cout return 0;}原创 2016-10-14 00:56:29 · 210 阅读 · 0 评论 -
求A和B两个数之和
/* 求A和B两个数之和 */#include using namespace std;int main(){ int a,b; cout cin>>a>>b; cout return 0;}原创 2016-10-14 08:08:13 · 732 阅读 · 0 评论 -
英尺到米的转换
/* 英尺到米的转换 转换公式:1米约等于3.28英尺 */#include using namespace std;int main(){ double feet,meter; cout cin>>feet; meter=feet/3.28; cout return原创 2016-10-14 08:19:31 · 1724 阅读 · 0 评论 -
摄氏度(C)与华氏(F)转换
/* 摄氏度(C)与华氏(F)转换 转换公式:F=C*9/5+32 */#include using namespace std;int main(){ double c,f; cout cin>>c; f=c*9/5+32; cout return 0;}原创 2016-10-14 08:27:18 · 6395 阅读 · 0 评论 -
求2个数中的大者
/* * file: getMax.cpp * author: * date: 2016.10.14 * ver: 1.0 * desc: 求2个数中的大者 */#include using namespace std;int getMax(int,int);int main(){ cout原创 2016-10-14 21:43:04 · 307 阅读 · 0 评论 -
分支判断 90分以上为优秀 60以上为合格 60以下为不合格
/** * Desc: 90分以上为优秀 60以上为合格 60以下为不合格 * Authors: hao.l * Date: 2016/10/17 * Modify by: * */#include #include using namespace std;string getScope(int);int main原创 2016-10-17 19:46:29 · 7319 阅读 · 0 评论 -
闰年判断
/** * Desc: 输入年月求月份天数 * Authors: hao.l * Date: 2016/10/17 * Modify by: * */#include #include using namespace std;int getDays(int,int);int main(){ cout原创 2016-10-17 22:34:00 · 319 阅读 · 0 评论 -
成人体重计算
/* 计算体重:成人的身高减去100*/#include using namespace std;int getWeight(int);int main(){ cout return 0;}int getWeight(int a){ return a-100;}原创 2016-10-15 23:08:33 · 413 阅读 · 0 评论 -
计算连板价
/** * program: * Authors: hao.l * Date: 2016/10/17 * Modify by: * * Desc: 杭州银行2-5个板后的价格(发行价14.39) 当日涨停为10% * 2:17.41 3021 * 3:19.15 4763 * 4:21.07 6678 * 5:23.18 8785 */#include #includ原创 2016-10-17 23:13:27 · 324 阅读 · 0 评论 -
全局变量和局部变量作用域
/** * program: * Authors: hao.l * Date: 2016/10/20 * Modify by: * * Desc: * 全局变量和局部变量作用域 * 全局变量作用在所有函数 * 局部变量作用在函数体内部 */#include #include using namespace std;void swap原创 2016-10-20 09:08:45 · 628 阅读 · 0 评论 -
10001 你好世界
#include <iostream>using namespace std;int main(){ cout << "Hello world!" << endl; return 0;}原创 2018-04-08 23:08:05 · 165 阅读 · 0 评论 -
10002 数组
#include <iostream>#include <vector>using namespace std;int main(){ vector<int> c; c.push_back(10); c.push_back(20); for(int i =0;i<c.size();i++){ co...原创 2018-04-08 23:08:58 · 149 阅读 · 0 评论 -
10005 内联函数
#include <iostream>using namespace std;// 内联函数 代码插入到调用的位置(由编译器决定是否插入)inline int add(int,int);int main(){ int c = add(20,21); cout<<c<<endl; return 0;}int add(in...原创 2018-04-08 23:45:54 · 151 阅读 · 0 评论 -
10020 复制构造函数
以其他对象作为参数创建对象时# Student.hStudent(Student&);# Student.cpp// 复制构造函数Student::Student(Student& student){ strcpy(m_name,student.m_name); m_age=student.m_age; strcpy(m_addr,student...原创 2018-04-13 13:25:25 · 165 阅读 · 0 评论