第一节 C++语言的发展历史
略
第二节 C++语言的特点
1、C++是一种面向对象的程序设计语言,其中的新技术主要包括:
- 抽象数据类型
- 封装和信息隐蔽
- 以继承和派生方式实现程序的重用
- 以运算符重载和虚函数来实现多态性
- 以模板来实现类型的参数化
第三节 面向对象程序设计OOP
1、C语言的缺点
- 结构化程序设计师面向过程,功能分解并逐步求精
- 数据和算法的一致性差,即两者相互分离
- 程序的可用性差,重复性工作无法避免,导致浪费资源
2、C++的主要特征
-
封装性
- 将数据和算法捆绑成一个整体,即对象
- 解决了数据和算法一致性差的问题
- 采用“类”来支持封装性和隐蔽性
-
继承性
- 是指一种事物保存了另一种事物的全部特征,同事还具有自身的独特性
- C++采用继承机制来支持重用,在已经有的功能上进行新功能的的扩展
-
多态性
- 是指当多种事物继承自一种事物时,同一种操作在他们之间便显出不同的行为
- C++语言中使用函数重载、模板、虚函数来支持多态性
第四节 C++语言的基本符号
- 符号——组成语言的最小元素
- 基本符号分成三类
- 字母——
A~Z
和a~z
- 数值——
0~9
- 特殊符号——
+
-
==
等30个
- 字母——
第五节 C++语言的词汇
- 词汇——符号按照一定规则组成的单词
- 合法词汇的五种类型
-
关键字
- 系统已定义好
-
标识符
-
用户自行定义,有相关要求:
- 标识符是一个以字母或者下划线开的,有字母、数字、下划线组成的字符串
注意数字不能用于开头 - 不能与关键字同名
- 严格区分大小写
- 标识符是一个以字母或者下划线开的,有字母、数字、下划线组成的字符串
-
-
字面常量
- 符号常量
Pi=3.1415926
的pi
- 字面常量
Pi=3.1415926
的3.1415926
- 符号常量
-
运算符
- 单字符组成的运算符
- 双字符组成的运算符
- 三个字符组成的运算符
- 关键字运算符
new
delete
size
-
标点符号——程序中起分割内容的界定作用的一类单词
- 空格
- 分号
- 单、双引号
- 井字号
- 双斜杠
- 斜杠和星号
- 花括号
-
第六节 C++程序的基本框架
- 一个最简单的C++程序
//ex_1.cpp #include<iostream> int main() //每个程序必须有且仅有一个主函数作为入口 //main可以带有参数,也可以不带参数 { std::cout<<"This is A simple C++ Progammer\n"; //cout是标准输出流对象,通常代表计算机的屏幕 return 0; }
第七节 C++程序的开发过程
开发一个C++程序的过程通常包括编辑、编译、链接、运行和调试等步骤。
-
编辑——“编写”程序
- 源程序文件
.cpp
- 头文件
.h
- 源程序文件
-
编译——“翻译”程序
- 编译成
.obj
文件 - 使用编译器来将源文件翻译为目标代码
- 编译成
-
链接
- 由链接器将目标文件与库文件链接起来,形成操作系统中可直接运行得可执行程序
-
调试
- 检查拼写错误、语法错误、链接错误
- 检查结果的正确性
- 可以上采用设置断点、单步调试、观察变量操作来调试程序
第八节 Visual C++6.0开发环境
VC6是在集成开发环境中利用项目的概念来组织和管理程序开发的工作的。
- 开发程序的一帮步骤
- 编辑、编译、链接、执行、调试
- 集成开发环境(IDE)的认识
- 项目工作区、源程序编辑窗口、输出窗口、迷你调试工具栏
- 项目(Project)工作区——开发程序所需要的所有文件的集合
- 工作区(WorkSpace)——进行项目组织的工作空间
- (你可以使用工作区文件
.dsw
和项目文件.dsp
来打开一个项目)
- 编写C++程序的步骤
- 创建项目——windows控制台程序(Win32 Console Application)
- 项目工作区的组成——类视图、文件视图
- 创建头文件、创建源程序文件、创建main函数
- 编译、链接、运行
code[class*="language-"],pre[class*="language-"] { color: #333; background: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; text-align: left; white-space: pre; word-spacing: normal; line-height: 1.4 }
pre[class*="language-"] { padding: .8em; overflow: auto; background: #f5f5f5 }
:not(pre)>code[class*="language-"] { padding: .1em; white-space: normal; background: #f5f5f5 }
.token.comment,.token.blockquote { color: #969896 }
.token.cdata { color: #183691 }
.token.doctype,.token.punctuation,.token.variable,.token.macro.property { color: #333 }
.token.operator,.token.important,.token.keyword,.token.rule,.token.builtin { color: #a71d5d }
.token.string,.token.url,.token.regex,.token.attr-value { color: #183691 }
.token.property,.token.number,.token.boolean,.token.entity,.token.atrule,.token.constant,.token.symbol,.token.command,.token.code { color: #0086b3 }
.token.tag,.token.selector,.token.prolog { color: #63a35c }
.token.function,.token.namespace,.token.pseudo-element,.token.class,.token.class-name,.token.pseudo-class,.token.id,.token.url-reference .token.variable,.token.attr-name { color: #795da3 }
.token.entity { cursor: help }
.token.title,.token.title .token.punctuation { font-weight: bold; color: #1d3e81 }
.token.list { color: #ed6a43 }
.token.inserted { background-color: #eaffea; color: #55a532 }
.token.deleted { background-color: #ffecec; color: #bd2c00 }
.token.bold { font-weight: bold }
.token.italic { font-style: italic }
.language-json .token.property { color: #183691 }
.language-markup .token.tag .token.punctuation { color: #333 }
code.language-css,.language-css .token.function { color: #0086b3 }
.language-yaml .token.atrule { color: #63a35c }
code.language-yaml { color: #183691 }
.language-ruby .token.function { color: #333 }
.language-markdown .token.url { color: #795da3 }
.language-makefile .token.symbol { color: #795da3 }
.language-makefile .token.variable { color: #183691 }
.language-makefile .token.builtin { color: #0086b3 }
.language-bash .token.keyword { color: #0086b3 }
html body { font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif; font-size: 16px; line-height: 1.6; color: #333; background-color: #fff; overflow: initial }
html body>:first-child { margin-top: 0 }
html body h1,html body h2,html body h3,html body h4,html body h5,html body h6 { line-height: 1.2; margin-top: 1em; margin-bottom: 16px; color: #000 }
html body h1 { font-size: 2.25em; font-weight: 300; padding-bottom: .3em }
html body h2 { font-size: 1.75em; font-weight: 400; padding-bottom: .3em }
html body h3 { font-size: 1.5em; font-weight: 500 }
html body h4 { font-size: 1.25em; font-weight: 600 }
html body h5 { font-size: 1.1em; font-weight: 600 }
html body h6 { font-size: 1em; font-weight: 600 }
html body h1,html body h2,html body h3,html body h4,html body h5 { font-weight: 600 }
html body h5 { font-size: 1em }
html body h6 { color: #5c5c5c }
html body strong { color: #000 }
html body del { color: #5c5c5c }
html body a:not([href]) { color: inherit; text-decoration: none }
html body a { color: #08c; text-decoration: none }
html body a:hover { color: #00a3f5; text-decoration: none }
html body img { max-width: 100% }
html body>p { margin-top: 0; margin-bottom: 16px }
html body>ul,html body>ol { margin-bottom: 16px }
html body ul,html body ol { padding-left: 2em }
html body ul.no-list,html body ol.no-list { padding: 0; list-style-type: none }
html body ul ul,html body ul ol,html body ol ol,html body ol ul { margin-top: 0; margin-bottom: 0 }
html body li { margin-bottom: 0 }
html body li.task-list-item { list-style: none }
html body li>p { margin-top: 0; margin-bottom: 0 }
html body .task-list-item-checkbox { margin: 0 .2em .25em -1.8em; vertical-align: middle }
html body .task-list-item-checkbox:hover { cursor: pointer }
html body blockquote { margin: 16px 0; font-size: inherit; padding: 0 15px; color: #5c5c5c; border-left: 4px solid #d6d6d6 }
html body blockquote>:first-child { margin-top: 0 }
html body blockquote>:last-child { margin-bottom: 0 }
html body hr { height: 4px; margin: 32px 0; background-color: #d6d6d6; border: 0 none }
html body table { margin: 10px 0 15px 0; border-collapse: collapse; border-spacing: 0; display: block; width: 100%; overflow: auto }
html body table th { font-weight: bold; color: #000 }
html body table td,html body table th { border: 1px solid #d6d6d6; padding: 6px 13px }
html body dl { padding: 0 }
html body dl dt { padding: 0; margin-top: 16px; font-size: 1em; font-style: italic; font-weight: bold }
html body dl dd { padding: 0 16px; margin-bottom: 16px }
html body code { font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: .85em !important; color: #000; background-color: #f0f0f0; padding: .2em 0 }
html body code::before,html body code::after { letter-spacing: -0.2em; content: " " }
html body pre>code { padding: 0; margin: 0; font-size: .85em !important; white-space: pre; background: transparent; border: 0 }
html body .highlight { margin-bottom: 16px }
html body .highlight pre,html body pre { padding: 1em; overflow: auto; font-size: .85em !important; line-height: 1.45; border: #d6d6d6 }
html body .highlight pre { margin-bottom: 0 }
html body pre code,html body pre tt { display: inline; max-width: initial; padding: 0; margin: 0; overflow: initial; line-height: inherit; background-color: transparent; border: 0 }
html body pre code::before,html body pre tt::before,html body pre code::after,html body pre tt::after { content: normal }
html body p,html body blockquote,html body ul,html body ol,html body dl,html body pre { margin-top: 0; margin-bottom: 16px }
html body kbd { color: #000; border: 1px solid #d6d6d6; border-bottom: 2px solid #c7c7c7; padding: 2px 4px; background-color: #f0f0f0 }
.markdown-preview { width: 100%; height: 100% }
.markdown-preview .pagebreak,.markdown-preview .newpage { page-break-before: always }
.markdown-preview pre.line-numbers { position: relative; padding-left: 3.8em; counter-reset: linenumber }
.markdown-preview pre.line-numbers>code { position: relative }
.markdown-preview pre.line-numbers .line-numbers-rows { position: absolute; top: 1em; font-size: 100%; left: 0; width: 3em; letter-spacing: -1px; border-right: 1px solid #999 }
.markdown-preview pre.line-numbers .line-numbers-rows>span { display: block; counter-increment: linenumber }
.markdown-preview pre.line-numbers .line-numbers-rows>span::before { content: counter(linenumber); color: #999; display: block; padding-right: .8em; text-align: right }
.markdown-preview .mathjax-exps .MathJax_Display { text-align: center !important }
.markdown-preview:not([for="preview"]) .code-chunk .btn-group { display: none }
.markdown-preview:not([for="preview"]) .code-chunk .status { display: none }
.markdown-preview:not([for="preview"]) .code-chunk .output-div { margin-bottom: 16px }
.scrollbar-style::-webkit-scrollbar { width: 8px }
.scrollbar-style::-webkit-scrollbar-track { background-color: transparent }
.scrollbar-style::-webkit-scrollbar-thumb { background-color: rgba(150,150,150,0.66); border: 4px solid rgba(150,150,150,0.66) }
html body[for="html-export"]:not([data-presentation-mode]) { position: relative; width: 100%; height: 100%; top: 0; left: 0; margin: 0; padding: 0; overflow: auto }
html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview { position: relative; top: 0 }
html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn { position: fixed; bottom: 8px; left: 8px; font-size: 28px; cursor: pointer; color: inherit; z-index: 99; width: 32px; text-align: center; opacity: .4 }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn { opacity: 1 }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc { position: fixed; top: 0; left: 0; width: 300px; height: 100%; padding: 32px 0 48px 0; font-size: 14px; overflow: auto; background-color: inherit }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar { width: 8px }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track { background-color: transparent }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb { background-color: rgba(150,150,150,0.66); border: 4px solid rgba(150,150,150,0.66) }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a { text-decoration: none }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul { padding: 0 1.6em; margin-top: .8em }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc li { margin-bottom: .8em }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul { list-style-type: none }
html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview { left: 300px; width: calc(100% - 300px); padding: 2em calc(50% - 457px - 150px); margin: 0 }
html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview { left: 50% }
html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc { display: none }
.markdown-preview.markdown-preview { margin: 0 auto; font-family: "Microsoft YaHei", arial, sans-serif; color: #444444; line-height: 1; padding: 30px }
.markdown-preview.markdown-preview h1,.markdown-preview.markdown-preview h2,.markdown-preview.markdown-preview h3,.markdown-preview.markdown-preview h4 { color: #111111; font-weight: 400; margin-top: 1em }
.markdown-preview.markdown-preview h1,.markdown-preview.markdown-preview h2,.markdown-preview.markdown-preview h3,.markdown-preview.markdown-preview h4,.markdown-preview.markdown-preview h5 { font-family: "Microsoft YaHei", Palatino, serif }
.markdown-preview.markdown-preview h1,.markdown-preview.markdown-preview h2,.markdown-preview.markdown-preview h3,.markdown-preview.markdown-preview h4,.markdown-preview.markdown-preview h5,.markdown-preview.markdown-preview p,.markdown-preview.markdown-preview dl { margin-bottom: 16px; padding: 0 }
.markdown-preview.markdown-preview h1 { font-size: 48px; line-height: 54px }
.markdown-preview.markdown-preview h2 { font-size: 36px; line-height: 42px }
.markdown-preview.markdown-preview h1,.markdown-preview.markdown-preview h2 { border-bottom: 1px solid #EFEAEA; padding-bottom: 10px }
.markdown-preview.markdown-preview h3 { font-size: 24px; line-height: 30px }
.markdown-preview.markdown-preview h4 { font-size: 21px; line-height: 26px }
.markdown-preview.markdown-preview h5 { font-size: 18px; list-style: 23px }
.markdown-preview.markdown-preview a { color: #0099ff; margin: 0; padding: 0; vertical-align: baseline }
.markdown-preview.markdown-preview a:hover { text-decoration: none; color: #ff6600 }
.markdown-preview.markdown-preview a:visited { }
.markdown-preview.markdown-preview ul,.markdown-preview.markdown-preview ol { padding: 0; padding-left: 24px; margin: 0 }
.markdown-preview.markdown-preview li { line-height: 24px }
.markdown-preview.markdown-preview p,.markdown-preview.markdown-preview ul,.markdown-preview.markdown-preview ol { font-size: 16px; line-height: 24px }
.markdown-preview.markdown-preview ol ol,.markdown-preview.markdown-preview ul ol { list-style-type: lower-roman }
.markdown-preview.markdown-preview code,.markdown-preview.markdown-preview pre { background-color: #f7f7f7; color: inherit }
.markdown-preview.markdown-preview code { font-family: Consolas, Monaco, Andale Mono, monospace; margin: 0 2px }
.markdown-preview.markdown-preview pre { line-height: 1.7em; overflow: auto; padding: 6px 10px; border-left: 5px solid #6CE26C }
.markdown-preview.markdown-preview pre>code { border: 0; display: inline; max-width: initial; padding: 0; margin: 0; overflow: initial; line-height: inherit; font-size: .85em; white-space: pre; background: 0 0 }
.markdown-preview.markdown-preview code { color: #666555 }
.markdown-preview.markdown-preview code .keyword { color: #8959a8 }
.markdown-preview.markdown-preview code .number { color: #f5871f }
.markdown-preview.markdown-preview code .comment { color: #998 }
.markdown-preview.markdown-preview aside { display: block; float: right; width: 390px }
.markdown-preview.markdown-preview blockquote { border-left: .5em solid #eee; padding: 0 0 0 2em; margin-left: 0 }
.markdown-preview.markdown-preview blockquote cite { font-size: 14px; line-height: 20px; color: #bfbfbf }
.markdown-preview.markdown-preview blockquote cite::before { content: "— " }
.markdown-preview.markdown-preview blockquote p { color: #666 }
.markdown-preview.markdown-preview hr { text-align: left; color: #999; height: 2px; padding: 0; margin: 16px 0; background-color: #e7e7e7; border: 0 none }
.markdown-preview.markdown-preview dl { padding: 0 }
.markdown-preview.markdown-preview dl dt { padding: 10px 0; margin-top: 16px; font-size: 1em; font-style: italic; font-weight: bold }
.markdown-preview.markdown-preview dl dd { padding: 0 16px; margin-bottom: 16px }
.markdown-preview.markdown-preview dd { margin-left: 0 }
.markdown-preview.markdown-preview button,.markdown-preview.markdown-preview input,.markdown-preview.markdown-preview select,.markdown-preview.markdown-preview textarea { font-size: 100%; margin: 0; vertical-align: baseline }
.markdown-preview.markdown-preview button,.markdown-preview.markdown-preview input { line-height: normal }
.markdown-preview.markdown-preview button::-moz-focus-inner,
.markdown-preview.markdown-preview input::-moz-focus-inner { border: 0; padding: 0 }
.markdown-preview.markdown-preview button,.markdown-preview.markdown-preview input[type="button"],.markdown-preview.markdown-preview input[type="reset"],.markdown-preview.markdown-preview input[type="submit"] { cursor: pointer }
.markdown-preview.markdown-preview input[type="checkbox"],.markdown-preview.markdown-preview input[type="radio"] { cursor: pointer }
.markdown-preview.markdown-preview input:not([type="image"]),.markdown-preview.markdown-preview textarea { }
.markdown-preview.markdown-preview input[type="search"] { }
.markdown-preview.markdown-preview input[type="search"]::-webkit-search-decoration { }
.markdown-preview.markdown-preview label,.markdown-preview.markdown-preview input,.markdown-preview.markdown-preview select,.markdown-preview.markdown-preview textarea { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: normal; margin-bottom: 18px }
.markdown-preview.markdown-preview input[type="checkbox"],.markdown-preview.markdown-preview input[type="radio"] { cursor: pointer; margin-bottom: 0 }
.markdown-preview.markdown-preview input[type="text"],.markdown-preview.markdown-preview input[type="password"],.markdown-preview.markdown-preview textarea,.markdown-preview.markdown-preview select { display: inline-block; width: 210px; padding: 4px; font-size: 13px; font-weight: normal; line-height: 18px; height: 18px; color: #808080; border: 1px solid #ccc }
.markdown-preview.markdown-preview select,.markdown-preview.markdown-preview input[type="file"] { height: 27px; line-height: 27px }
.markdown-preview.markdown-preview textarea { height: auto }
.markdown-preview.markdown-preview :-moz-placeholder { color: #bfbfbf }
.markdown-preview.markdown-preview ::-webkit-input-placeholder { color: #bfbfbf }
.markdown-preview.markdown-preview input[type="text"],.markdown-preview.markdown-preview input[type="password"],.markdown-preview.markdown-preview select,.markdown-preview.markdown-preview textarea { }
.markdown-preview.markdown-preview input[type="text"]:focus,.markdown-preview.markdown-preview input[type="password"]:focus,.markdown-preview.markdown-preview textarea:focus { outline: none; border-color: rgba(82, 168, 236, 0.8) }
.markdown-preview.markdown-preview button { display: inline-block; padding: 4px 14px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px; background-color: #0064cd; background-repeat: repeat-x; background-image: linear-gradient(top, #049cdb, #0064cd); color: #fff; border: 1px solid #004b9a; border-bottom-color: #003f81; border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25) }
.markdown-preview.markdown-preview button:hover { color: #fff; background-position: 0 -15px; text-decoration: none }
.markdown-preview.markdown-preview button:active { }
.markdown-preview.markdown-preview button::-moz-focus-inner { padding: 0; border: 0 }
.markdown-preview.markdown-preview table { border-spacing: 0; width: 100% }
.markdown-preview.markdown-preview table { border: solid #ccc 1px }
.markdown-preview.markdown-preview table tr:hover { background: #fbf8e9 }
.markdown-preview.markdown-preview table td,.markdown-preview.markdown-preview .table th { border-left: 1px solid #ccc; border-top: 1px solid #ccc; padding: 10px; text-align: left }
.markdown-preview.markdown-preview table th { background-color: #dce9f9; background-image: linear-gradient(top, #ebf3fc, #dce9f9); border-top: none; padding: 5px }
.markdown-preview.markdown-preview table td:first-child,.markdown-preview.markdown-preview table th:first-child { border-left: none }
.markdown-preview.markdown-preview table th:first-child { }
.markdown-preview.markdown-preview table th:last-child { }
.markdown-preview.markdown-preview table th:only-child { }
.markdown-preview.markdown-preview table tr:last-child td:first-child { }
.markdown-preview.markdown-preview table tr:last-child td:last-child { }