《C++ 语言程序设计》课程教学资源(应用阅读)C++ RC by Mississippi State U.(2009)

C++Reference Card Looping Pointers C++Data Types Data Type coutnd do-whil Loop Example do orchango th Operators biLe (expresston);hle (x1) oan:升s日 T0gnyeoeapossdpomes oI=(notequal-o】 for (;test;update) nd) statement 》 as5 signment0.*=,/=,=,+=,-= []: ett
C++ Reference Card C++ Data Types Data Type Description bool boolean (true or false) char character ('a', 'b', etc.) char[] character array (C-style string if null terminated) string C++ string (from the STL) int integer (1, 2, -1, 1000, etc.) long int long integer float single precision floating point double double precision floating point These are the most commonly used types; this is not a complete list. Operators The most commonly used operators in order of precedence: 1 ++ (post-increment), -- (post-decrement) 2 ! (not), ++ (pre-increment), -- (pre-decrement) 3 *, /, % (modulus) 4 +, - 5 , >= 6 == (equal-to), != (not-equal-to) 7 && (and) 8 || (or) 9 = (assignment), *=, /=, %=, +=, -= Console Input/Output cout > console in, reading from keyboard cerr > i; cout > inputVariable; // you can also use get (char) or // getline (entire line) in addition to >> ... inputFile.close(); Example (output): ofstream outFile; outfile.open("output.txt"); outFile element=val; hPtr->patties = 1; hPtr->cheese = false; Structures can be used just like the built-in data types in arrays

Classes Inheritance Exceptions nce allows dass it is bas getArea() public: type otdtgen,strineidn: Pbtmembesaieacst Eatch (int) rom anywhere the class is 1。 um can not be negative! essible fom the same clas class Gradstudent:public Student atch(cha exceptionstring) r(): string prevDegree add more catch blocks as needed Function Templates Base stotements; if (ab)a idtha Operator Overloading oid square:(o) t elseit(-1) ag65.e37,时 floatSquare::getArea() (const Square Class Templates fheotiecthatreei es the function call is not an ins 2oeamcaa 8 ce(PointT>p)i r(): priva Example d function Pi( he class template coutgetArea() 2.50 Suggested Websites C+Reference: http:// http://www.informit.com/guides/guide.aspx?gecplusplus C++Tutorialt: http://.cplusplus.com/doc/tutorial ttp://.sparknotes.com/cs/ C++Exan ple nttp://ww.fredosaurus.com/notes-cpp/
Developed for Mississippi State University's CSE1284 and CSE1384 courses February 17, 2009 Download the latest version from http://cse.msstate.edu/~crumpton/reference Classes Declaration Example class classname class Square { { public: public: classname(params); Square(); ~classname(); Square(float w); type member1; void setWidth(float w); type member2; float getArea(); protected: private: type member3; float width; private: }; type member4; }; public members are accessible from anywhere the class is visible. private members are only accessible from the same class or a friend (function or class). protected members are accessible from the same class, derived classes, or a friend (function or class). constructors may be overloaded just like any other function. You can define two or more constructors as long as each constructor has a different parameter list. Definition of Member Functions return_type classname::functionName(params) { statements; } Examples Square::Square() { width = 0; } void Square::setWidth(float w) { if (w >= 0) width = w; else exit(-1); } float Square::getArea() { return width*width; } Definition of Instances Example classname varName; Square s1(); Square s2(3.5); classname* ptrName; Square* sPtr; sPtr=new Square(1.8); Accessing Members Example varName.member=val; s1.setWidth(1.5); varName.member(); cout member=val; coutgetArea(); ptrName->member(); Inheritance Inheritance allows a new class to be based on an existing class. The new class inherits all the member variables and functions (except the constructors and destructor) of the class it is based on. Example class Student { public: Student(string n, string id); void print(); protected: string name; string netID; }; class GradStudent : public Student { public: GradStudent(string n, string id, string prev); void print(); protected: string prevDegree; }; Visibility of Members after Inheritance Inheritance Access Specifier in Base Class Specification private protected public private - private private protected - protected protected public - protected public Operator Overloading C++ allows you to define how standard operators (+, -, *, etc.) work with classes that you write. For example, to use the operator + with your class, you would write a function named operator+ for your class. Example Prototype for a function that overloads + for the Square class: Square operator+ (const Square &); If the object that receives the function call is not an instance of a class that you wrote, write the function as a friend of your class. This is standard practice for overloading >. Example Prototype for a function that overloads , ==, etc.) should be bool, the return type of T getMax(T a, T b) { if (a>b) return a; else return b; } // example calls to the function template int a=9, b=2, c; c = getMax(a, b); float f=5.3, g=9.7, h; h = getMax(f, g); Class Templates Example template class Point { public: Point(T x, T y); void print(); double distance(Point p); private: T x; T y; }; // examples using the class template Point p1(3, 2); Point p2(3.5, 2.5); p1.print(); p2.print(); Suggested Websites C++ Reference: http://www.cppreference.com/ http://www.informit.com/guides/guide.aspx?g=cplusplus C++ Tutorial: http://www.cplusplus.com/doc/tutorial/ http://www.sparknotes.com/cs/ C++ Examples: http://www.fredosaurus.com/notes-cpp/ Gaddis Textbook: Video Notes http://media.pearsoncmg.com/aw/aw_gaddis_sowcso_6/videos Source Code ftp://ftp.aw.com/cseng/authors/gaddis/CCSO5 (5th edition)
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《C++ 语言程序设计》课程教学资源(应用阅读)C++ Reference Card(C++ RC by Greg Book,2002).pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十六讲 标准模板库(Standard Template Library,STL).pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十五讲 文件流与输出输入重载.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十四讲 多态.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十三讲 继承与派生.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十二讲 运算符重载与自动类型转换.pdf
- 《C++ 语言程序设计》课程教学资源(应用阅读)C++ vector使用方法.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十一讲 类与对象(III)面向对象提高.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第十讲 类与对象(II)面向对象进阶.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第九讲 类与对象(I)面向对象基础.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第八讲 排序算法.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第七讲 输入输出与(C 语言)文件操作.pdf
- 《C++ 语言程序设计》课程教学资源(应用阅读)Pointers and Memory.pdf
- 《C++ 语言程序设计》课程教学资源(应用阅读)内存分配——栈和堆.pdf
- 《C++ 语言程序设计》课程教学资源(应用阅读)Fast and stable matrix multiplication.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(应用阅读)Gauss消去法求解线性方程组.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(应用阅读)矩阵乘积快速算法——Strassen 算法.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第六讲 指针.pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第五讲 数组(二)字符数组(字符串).pdf
- 华东师范大学:《C++ 语言程序设计》课程教学资源(课件讲稿)第五讲 数组(一)数值数组.pdf
- 《C++ 语言程序设计》课程教学资源(应用阅读)ASCII码(256完整版)The ASCII Character Set.pdf
- 《C++ 语言程序设计》课程教学资源(应用阅读)ASCII 码——常用ASCII码.pdf
- 西安电子科技大学:《操作系统》课程教学资源(PPT课件)Introduction(主讲:苏锐丹).pptx
- 西安电子科技大学:《操作系统》课程教学资源(PPT课件)Operating-System Structure.pptx
- 西安电子科技大学:《操作系统》课程教学资源(PPT课件)Processes.pptx
- 《移动互联网技术》课程教学资源(培训教材)Cisco Press - Building the Mobile Internet(Mark Grayson, Kevin Shatzkamer, Klaas Wierenga).pdf
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)01 课程介绍(主讲:苏锐丹).ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)02 移动互联网概述.ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)03 移动互联网技术(Android安全).ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)03 Android应用安全 Android application security.pptx
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)03 传输层移动性.ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)03 应用层移动性.ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)03 相关支撑技术.ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)04 数据链路层移动性技术.ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)05 网络层Mobility.ppt
- 西安电子科技大学:《移动互联网技术》课程教学资源(PPT课件)06 移动互联网IPv6.ppt
- 兰州交通大学:《单片机原理与接口技术》课程教学资源(教案讲义,打印版)实验教学大纲.pdf
- 兰州交通大学:《单片机原理与接口技术》课程教学资源(教案讲义,打印版)理论教学大纲.pdf
- 兰州交通大学:《单片机原理与接口技术》课程教学资源(课后作业)第1章(作业,打印版).pdf
- 兰州交通大学:《单片机原理与接口技术》课程教学资源(课后作业)第2章(作业,打印版).pdf