Up and Running with C++
2015-06-08 21:28
645 查看
1. 预备知识
基本概念:变量,数据类型,函数
流程图
UML统一建模语言
算法:解决一个问题的一系列步骤,如菜谱
2. C++背景
创始人Bjarne Stroustrup
内存管理:static, automatic, dynamic, garbage
3. 主函数基本部分剖析
注释/**/
变量
赋值=
输入输出
判断
循环
类,对象
文件读取写入
4. 数据类型
1byte char(字符), bool(布尔)
2bytes short(短型)
4bytes int(整数), long(长型), float(浮点数)
8bytes double(双浮点数)
5. 变换
隐式,int i = 5 + 11.12; // i = 17
显式,float f = 12.11; i = static_cast<int>(f);
6. Debug调试
设置断点
7. 表达式
数学 + - * / %
布尔 true false
判断 < > <= >= == != && ||
8. 循环
do{} while(true);
while(true){}
for(初始化; 判断; 递增){}
9. 随机数
#include<stdlib.h>
#include<time.h>
// a, b为界
(rand()%(b-a+1)) + a
// 更随机
srand(time(0));
rand();
10. 用户定义函数
ReturnType functionName( ParameterList )
{
// Code
return value;
}
拷贝值传递 ReturnType function( Type param )
引用值传递 ReturnType function( Type& param )
11. 预定义函数
<string> string getline(); int length(); string substr(int pos); string substr(int start, int length)
<cmath> sqrt(); pow(); sin(); cos(); fabs()
<iomanip> fixed; left/right; setfill(char fillchar); setprecision(int num); setw(int width)
<cstalib> int rand(); void srand(int num); int abs(int num); void exist(int num)
<cctype> bool isalpha(char c); bool isdigit(char c)
12. 默认参数
ReturnType functionName(Type param = defaultValue);
13. 函数重载 // 参数不同
ReturnType functionName(Type1 param1);
ReturnType functionName(Type2 param2);
14. 类
对象的蓝图(为什么需要类?重用,封装数据)
包括实例数据,构造器/析构器,函数(方法)(.h文件声明,.cpp文件定义)
实例化ClassName objectname(parameters);
封装Encapsulation
private(自己可访问)
protected(公共可访问)
public(继承可访问)
继承Inheritance
关系Is-a
多态Polymorphism
函数行为
15. 数组
Type arrayName[sizeNum];
固定大小
篱笆柱边界错误
16. 指针
Type* pointerName = &variable;
解引用 *pointerName
17. 向量vector
#include<vector>
vector<Type> vectorName;
vector<Type> vectorName(sizeNum);
vector<Type> vectorName(sizeNum, defaultValue);
18. 抽象数据类型(Abstract Data Type, ADT)
由程序员自己创造
包含不同的基本数据类型
用.(dot)操作符访问
比较时要每个数据单独比较
创建时可初始化
Struct StructName {
int foo;
float bar;
}
19. 排序
选择,插入,冒泡,快速,归并
20. 文件操作
#include<fstream>
// 读取
ifstream inputFile;
inputFile.open("fileName.txt", ios::in);
inputFile.eof();
inputFile.getline(storeVariable, sizeNum)
// 写入
ofstream outputFile;
outputFile.open("fineName.txt", ios::out);
outputFile << stringVariable << endl;
21. 异常处理
try {
// buggy code
throw errorCode; // 用户自定义
} catch(int error) {
// check here and handle it
}
基本概念:变量,数据类型,函数
流程图
UML统一建模语言
算法:解决一个问题的一系列步骤,如菜谱
2. C++背景
创始人Bjarne Stroustrup
内存管理:static, automatic, dynamic, garbage
3. 主函数基本部分剖析
注释/**/
变量
赋值=
输入输出
判断
循环
类,对象
文件读取写入
4. 数据类型
1byte char(字符), bool(布尔)
2bytes short(短型)
4bytes int(整数), long(长型), float(浮点数)
8bytes double(双浮点数)
5. 变换
隐式,int i = 5 + 11.12; // i = 17
显式,float f = 12.11; i = static_cast<int>(f);
6. Debug调试
设置断点
7. 表达式
数学 + - * / %
布尔 true false
判断 < > <= >= == != && ||
8. 循环
do{} while(true);
while(true){}
for(初始化; 判断; 递增){}
9. 随机数
#include<stdlib.h>
#include<time.h>
// a, b为界
(rand()%(b-a+1)) + a
// 更随机
srand(time(0));
rand();
10. 用户定义函数
ReturnType functionName( ParameterList )
{
// Code
return value;
}
拷贝值传递 ReturnType function( Type param )
引用值传递 ReturnType function( Type& param )
11. 预定义函数
<string> string getline(); int length(); string substr(int pos); string substr(int start, int length)
<cmath> sqrt(); pow(); sin(); cos(); fabs()
<iomanip> fixed; left/right; setfill(char fillchar); setprecision(int num); setw(int width)
<cstalib> int rand(); void srand(int num); int abs(int num); void exist(int num)
<cctype> bool isalpha(char c); bool isdigit(char c)
12. 默认参数
ReturnType functionName(Type param = defaultValue);
13. 函数重载 // 参数不同
ReturnType functionName(Type1 param1);
ReturnType functionName(Type2 param2);
14. 类
对象的蓝图(为什么需要类?重用,封装数据)
包括实例数据,构造器/析构器,函数(方法)(.h文件声明,.cpp文件定义)
实例化ClassName objectname(parameters);
封装Encapsulation
private(自己可访问)
protected(公共可访问)
public(继承可访问)
继承Inheritance
关系Is-a
多态Polymorphism
函数行为
15. 数组
Type arrayName[sizeNum];
固定大小
篱笆柱边界错误
16. 指针
Type* pointerName = &variable;
解引用 *pointerName
17. 向量vector
#include<vector>
vector<Type> vectorName;
vector<Type> vectorName(sizeNum);
vector<Type> vectorName(sizeNum, defaultValue);
18. 抽象数据类型(Abstract Data Type, ADT)
由程序员自己创造
包含不同的基本数据类型
用.(dot)操作符访问
比较时要每个数据单独比较
创建时可初始化
Struct StructName {
int foo;
float bar;
}
19. 排序
选择,插入,冒泡,快速,归并
20. 文件操作
#include<fstream>
// 读取
ifstream inputFile;
inputFile.open("fileName.txt", ios::in);
inputFile.eof();
inputFile.getline(storeVariable, sizeNum)
// 写入
ofstream outputFile;
outputFile.open("fineName.txt", ios::out);
outputFile << stringVariable << endl;
21. 异常处理
try {
// buggy code
throw errorCode; // 用户自定义
} catch(int error) {
// check here and handle it
}
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++中拷贝构造函数的应用详解
- C++中引用(&)的用法与应用实例分析
- C++使用CriticalSection实现线程同步实例
- C++智能指针实例详解
- 解析C++ 浮点数的格式化输出