C++ Review

C++ Review
C++ Review

Outline ■C++ basic features Programming paradigm and statement syntax ■C| ass definitions Data members methods constructor destructor Pointers, arrays, and strings Parameter passing in functions Templates Friend Operator overloading O streams An example on file copy Makefile
2 Outline ◼ C++ basic features ◼ Programming paradigm and statement syntax ◼ Class definitions ◼ Data members, methods, constructor, destructor ◼ Pointers, arrays, and strings ◼ Parameter passing in functions ◼ Templates ◼ Friend ◼ Operator overloading ◼ I/O streams ◼ An example on file copy ◼ Makefile

Functions memory Every function needs a place to store its local variables Memory Collectively this storage is called location the stack This storage(memory aka "RAM) d2 Is a series of storage spaces and their numerical addresses Instead of using raw addresses we use variables to attach a name to an address all of the data/variables for a particular function call are located void aFunc(int x, int y) in a stack frame double d1, d2; int 1
3 Functions & Memory ◼ Every function needs a place to store its local variables. Collectively, this storage is called the stack ◼ This storage (memory aka “RAM”), is a series of storage spaces and their numerical addresses ◼ Instead of using raw addresses, we use variables to attach a name to an address ◼ All of the data/variables for a particular function call are located in a stack frame Memory location void aFunc(int x, int y) { double d1, d2; int i; } x y d2 d1 i

Functions memory(cont) When a function is called a new stack frame is set aside Parameters and return values are passed by copy(ie, they' re copied into and out of the stack frame) When a function finishes its stack frame is reclaimed void afunc (int x, int y) double dl=x+ int main(int argc, const char argv[])[ int x =7 a Func(1, 2) Y aFunc a Func(2,3)i return 0; 7 main
4 Functions & Memory (cont) ◼ When a function is called, a new stack frame is set aside ◼ Parameters and return values are passed by copy (ie, they’re copied into and out of the stack frame) ◼ When a function finishes, its stack frame is reclaimed void aFunc(int x, int y) { double d1 = x + y; } int main(int argc, const char * argv[]) { int x = 7; aFunc(1, 2); aFunc(2, 3); return 0; } x y d1 x 7 aFunc main

Programming Paradigm: Modular Concept program maln program dat module 1 module data +date data +da 2 DLCCCauLc procedure procedure The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters
5 Programming Paradigm: Modular Concept ◼ The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters

Modular Concept- Problems Decoupled Data and operations The resulting module structure is oriented on the operations rather than the actual data a The defined operations specify the data to be used
6 Modular Concept - Problems ◼ Decoupled Data and Operations ◼ The resulting module structure is oriented on the operations rather than the actual data ◼ The defined operations specify the data to be used

Object-Oriented Concept(C++) pro object data object data data object data Objects of the program interact by sending messages to each other
7 Object-Oriented Concept (C++) ◼ Objects of the program interact by sending messages to each other

Basic ctt Inherit all c syntax Primitive data types Supported data types: int, long, short, float double, char, bool and enum The size of data types is platform-dependent Basic expression syntax Defining the usual arithmetic and logical operations such as +r &,!,and| Defining bit-wise operations, such as & I, and Basic statement syntax If-else, for, while, and do-while
8 Basic C++ ◼ Inherit all C syntax ◼ Primitive data types ◼ Supported data types: int, long, short, float, double, char, bool, and enum ◼ The size of data types is platform-dependent ◼ Basic expression syntax ◼ Defining the usual arithmetic and logical operations such as +, -, /, %, *, &&, !, and || ◼ Defining bit-wise operations, such as &, |, and ~ ◼ Basic statement syntax ◼ If-else, for, while, and do-while

Basic C++(cont) ■ Add a new comment mark ∥/For1 line comment /.*/for a group of line comment New data type Reference data type & Much likes pointer nt ix/*ix is real variable * int&rx=ⅸ;/rxis"aias"forⅸ* ⅸ=1;/ also rx==1* rx=2:/alsoⅸ==2* const support for constant declaration, just likes C
9 Basic C++ (cont) ◼ Add a new comment mark ◼ // For 1 line comment ◼ /*… */ for a group of line comment ◼ New data type ◼ Reference data type “&”. Much likes pointer int ix; /* ix is "real" variable */ int & rx = ix; /* rx is "alias" for ix */ ix = 1; /* also rx == 1 */ rx = 2; /* also ix == 2 */ ◼ const support for constant declaration, just likes C

Class Definitions AC++ class consists of data members and methods(member functions) class Intcell Initializer list used to initialize the data Avoid implicit type conversion members directly public explicit Intcell( int initialvalye=0) storedvalue( initialvalue y[] Member functions int read( )const return storedValue iNdicates that the member's invocation does void write( int x) not change any of the data members storedvalue private int storedvalue Data member(s)
10 Class Definitions ◼ A C++ class consists of data members and methods (member functions). class IntCell { public: explicit IntCell( int initialValue = 0 ) : storedValue( initialValue ) {} int read( ) const { return storedValue;} void write( int x ) { storedValue = x; } private: int storedValue; } Member functions Data member(s) Indicates that the member’s invocation does not change any of the data members. Avoid implicit type conversion Initializer list: used to initialize the data members directly
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《计算机网络与通讯》课程教学资源(PPT课件讲稿,英文版)Chapter 07 Network Security.ppt
- Incorporating Structured World Knowledge into Unstructured Documents via——Heterogeneous Information Networks.pptx
- FairCloud:Sharing the Network in Cloud Computing.pptx
- 香港科技大学:《计算机网络 Computer Networks》课程教学资源(PPT课件)Chapter 1 Introduction of computer networking.ppsx
- Fluent:《GAMBIT建模教程》教学资源(PPT讲稿)Geometry Operations in GAMBIT.ppt
- 有限元分析 ANSYS:Modeling Turbulent Flows(PPT讲稿)Introductory FLUENT Training.ppt
- 隐马尔科夫模型和词性标注(PPT课件讲稿).ppt
- 哈尔滨工业大学:《中文信息处理》课程教学资源(PPT课件讲稿)句法分析(张宇).ppt
- 新乡学院:《计算机网络》课程教学大纲(适用专业:信息与计算科学).pdf
- 新乡学院:《数据库原理》课程电子教案(PPT课件)第3章 关系数据库.ppt
- 《数据库系统概论 An Introduction to Database System》课程教学资源(PPT课件讲稿)第8讲 数据库恢复技术.ppt
- 河南中医药大学:《网络技术实训》课程教学资源(PPT课件讲稿)第4讲 网络管理实训内容(上).pptx
- 河南中医药大学(河南中医学院):《计算机网络》课程教学资源(PPT课件讲稿)第六章 应用层.ppt
- 《计算机辅助设计——Photoshop制图》课程标准.pdf
- 《操作系统 Operating System》课程电子教案(PPT课件讲稿)第一章 简介.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)文件管理 File Management.ppt
- 《Advanced Artificial Intelligence》课程PPT教学课件(高级人工智能)Lecture 6 Convolutional Neural Network.pptx
- 《Advanced Artificial Intelligence》课程PPT教学课件(高级人工智能)Lecture 3 Decision Tree.pptx
- 《Advanced Artificial Intelligence》课程PPT教学课件(高级人工智能)Lecture 5 Neural Networks.pptx
- 北京林业大学:《深度学习》课程PPT教学课件(Deep Learning)第二章 神经网络与优化方法(主讲:孙钰).pptx
- 《计算机网络与通讯》课程教学资源(PPT课件讲稿,英文版)Chapter 3 Transport Layer.ppt
- 《Java编程导论》课程教学资源(PPT课件讲稿)Chapter 8 Strings and Text I/O.ppt
- 印第安纳大学:《Informatics》课程PPT教学课件(信息学)08 网络爬虫 Web Crawling.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 1 and 2 Computer System and Operating System Overview.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 6 Concurrency Deadlock and Starvation.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 8 Virtual Memory.ppt
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 10 Pose estimation by the iterative method.pptx
- Introduction to Internet and TCPIP(PPT讲稿)IP转发 IP FORWARDING.pptx
- GD-Aggregate:A WAN Virtual Topology Building Tool for Hard Real-Time and Embedded Applications.ppt
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 05 Hough transform.pptx
- 香港中文大学:Image processing and computer vision(PPT课件讲稿)Edge detection and image filtering.pptx
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 07 Mean-shift and Cam-shift.pptx
- Essential Cluster OS Commands.ppt
- 香港浸会大学:Kickstart Tutorial/Seminar on using the 64-nodes P4-Xeon Cluster in Science Faculty.ppt
- 香港浸会大学:并行输入输出(PPT讲稿)Parallel I/O.ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 7 Memory Management.ppt
- 四川大学:《数据库技术》课程教学资源(PPT课件讲稿)第4章 数据库查询.ppt
- 《计算机系统结构》课程教学资源(PPT课件讲稿)第五章 存储层次.ppt
- 软件配置管理和项目管理工具(PPT讲稿)Software Configuration Management and Project Management Tool.ppt
- 《数据库基础》课程PPT教学课件(SQL Server)第4章 T-SQL与可编程对象.ppt